// JavaScript Document

var popupWidthGallery, popupHeightGallery, originalDocumentWidthGallery;

function showPopupGallery(url)
{
	var elSource = document.getElementById('popupSourceGallery');
	var el = document.getElementById('popupMaskGallery');
	var elContent = document.getElementById('popupContentGallery');
	var width = 882;
	var height = 530;

	// Store input dimensions
	popupWidthGallery = width;
	popupHeightGallery = height;
	originalDocumentWidthGallery = document.documentElement.scrollWidth;
	
	// Copy source html into elContent
	elContent.innerHTML = elSource.innerHTML;
	
	// Set dimensions
	setPopupDimensionsGallery(el, elContent, width, height);
	
	document.getElementById('GalleryIFrame').src = url;
	
	// Set visibility
	el.style.display = 'block';
	elContent.style.display = 'block';
	
	// Detect resizes
	window.onresize = setPopupDimensionsGallery;
	window.onscroll = setPopupDimensionsGallery;
}

function setPopupDimensionsGallery(el, elContent, width, height)
{	
	var elSource = document.getElementById('popupSourceGallery');
	var el = document.getElementById('popupMaskGallery');
	var elContent = document.getElementById('popupContentGallery');

	// Get stored dimensions
	width = popupWidthGallery;
	height = popupHeightGallery;
	
	// Get scroll position
	var scrollY = document.documentElement.scrollTop;
	var scrollX = document.documentElement.scrollLeft;

	// Get document dimensions
	var documentHeight = document.body.clientHeight > document.documentElement.clientHeight ? document.body.clientHeight : document.documentElement.clientHeight;
	var documentWidth = originalDocumentWidthGallery < document.documentElement.scrollWidth ? originalDocumentWidthGallery : document.documentElement.scrollWidth;
	
	// Get browser dimensions
	if(self.innerHeight)
		var innerHeight = self.innerHeight;
	else
		var innerHeight = document.documentElement.clientHeight;
	var innerWidth = document.documentElement.clientWidth < document.body.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
	
	if(documentWidth < innerWidth)
		documentWidth = innerWidth;
	
	// Set dimensions of background mask
	el.style.width = documentWidth + 'px';
	el.style.height = documentHeight + 'px';
	el.style.top = 0;
	el.style.left = 0;
	
	// Set dimensions of content
	elContent.style.width = width + 'px';
	elContent.style.height = height + 'px';
	elContent.style.top = (scrollY + innerHeight / 2 - height / 2 - 48 / 2) + 'px';
	elContent.style.top = '35px';
	//elContent.style.top = (scrollY + innerHeight / 2 - height / 2 - 48 / 2) + 'px';
	elContent.style.left = (scrollX + innerWidth / 2 - width / 2) + 'px';
}

function cancelPopupGallery()
{
	// Hide view
	document.getElementById('popupMaskGallery').style.display = 'none';
	document.getElementById('popupContentGallery').style.display = 'none';
	/*document.getElementById('swfFlvPlayer').innerHTML = '';*/
	
	// Don't handle resizes
	window.onresize = null;
	window.onscroll = null;
	
	//document.getElementById('objGallery').innerHTML = document.getElementById('GalleryContent').innerHTML;
}

function fncShowLargeImage(objRef)
{	
	var objRef;
	var objImg = objRef.childNodes[0];
	var strImgThumbPath = objImg.src;
	var strImgFileName = strImgThumbPath.slice(strImgThumbPath.lastIndexOf('/')+1,strImgThumbPath.length)
	strImgFileName = strImgFileName.toLowerCase().replace("_jpg.jpg", ".jpg");
	var strImgPathThumb = strImgThumbPath.slice(0,strImgThumbPath.lastIndexOf('/')+1)
	var strImgPathLarge = strImgThumbPath.slice(0,strImgThumbPath.lastIndexOf('/')-6)
	
	var imgLargeImage = new Image();
	imgLargeImage.src = strImgPathLarge + strImgFileName;
	document.getElementById('GalleryLargeImg').width = "594";
	document.getElementById('GalleryLargeImg').src = imgLargeImage.src;
}

function fncInitFirstLargeImage()
{
	var colGalleriImg = document.getElementById('GalleryThumbnails').getElementsByTagName("img");
	var strFirstImagePath = colGalleriImg[0].src;
	strFirstImagePath = strFirstImagePath.toLowerCase().replace("/thumbs","");
	strFirstImagePath = strFirstImagePath.replace("_jpg.jpg", ".jpg");
	
	var imgLargeImage = new Image();
	imgLargeImage.src = strFirstImagePath;
	document.getElementById('GalleryLargeImg').width = "594";
	document.getElementById('GalleryLargeImg').src = imgLargeImage.src;
}

function PlaceFrontpageNewsBox()
{
	var ObjectToPlace = document.getElementById('FrontpageNewsParent');
	var DocumentWidth = document.body.clientWidth;
	var SiteWidth = document.getElementById('Container').clientWidth;
	var PlaceHolderHeight = document.getElementById('dwtopimage').offsetHeight;
	var PlaceHolderTop = document.getElementById('dwtopimage').offsetTop;
	
//	alert(ObjectToPlace.clientHeight);
	
	ObjectToPlace.style.left = (((DocumentWidth-SiteWidth)/2)+(SiteWidth-323))+"px";
	ObjectToPlace.style.display = "block";
	ObjectToPlace.style.top = (PlaceHolderHeight-ObjectToPlace.clientHeight)+"px";
	
}
	window.onresize = function(){if(document.getElementById('FrontpageNewsParent'))PlaceFrontpageNewsBox()};