// 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 = 926;
	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)
{	
	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 = '15px';
	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 = "550";
	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 = "550";
	document.getElementById('GalleryLargeImg').src = imgLargeImage.src;
}*/

function fncGetCloseTxt()
{
	var strOutputTxt;
	switch(numAreaID)
	{
		case 1: // Dansk
			strOutputTxt = "Luk vindue";
			return strOutputTxt;
			break;
		case 2: // Engelsk
			strOutputTxt = "Close window";
			return strOutputTxt;
			break;
		case 3: // USA
			strOutputTxt = "Close window";
			return strOutputTxt;
			break;
		case 5: // Svensk
			strOutputTxt = "Close window";
			return strOutputTxt;
			break;
		case 6: // Tysk
			strOutputTxt = "Close window";
			return strOutputTxt;
			break;
		case 7: // Italiensk
			strOutputTxt = "Close window";
			return strOutputTxt;
			break;
		case 8: // Fransk
			strOutputTxt = "Close window";
			return strOutputTxt;
			break;
	}
}

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 = "477";
	document.getElementById('GalleryLargeImg').src = imgLargeImage.src;
	//isImageOk(document.getElementById('GalleryLargeImg'));
	numTimerID=setTimeout("fncSetIFrameHeight()",1000);
}

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 = "477";
	document.getElementById('GalleryLargeImg').src = imgLargeImage.src;
	//isImageOk(document.getElementById('GalleryLargeImg'));
	numTimerID=setTimeout("fncSetIFrameHeight()",1000);
}

// Set Gallery iFrame Height
var numTimerID;
function fncSetIFrameHeight()
{
	var documentGalleryHeight = document.body.clientHeight > document.documentElement.clientHeight ? document.body.clientHeight : document.documentElement.clientHeight;
	
	if(document.getElementById('GalleryLargeImg').height<510)
	{
		parent.document.getElementById('GalleryIFrame').height = 510;	
	}
	else
	{
		parent.document.getElementById('GalleryIFrame').height = documentGalleryHeight;
	}
	clearTimeout(numTimerID);
}

function isImageOk(img) {
    // During the onload event, IE correctly identifies any images
    // that weren't downloaded as not complete. Others should too.
    // Gecko-based browsers act like NS4 in that they report this
    // incorrectly: they always return true.
    if (!img.complete) {
				document.getElementById('testOutput').innerHTML = "Not ready!!!";
        return false;
    }

    // However, they do have two very useful properties: naturalWidth
    // and naturalHeight. These give the true size of the image. If
    // it failed to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        document.getElementById('testOutput').innerHTML = "Not ready!!!";
				return false;
    }

    // No other way of checking: assume it's ok.
    document.getElementById('testOutput').innerHTML = "Ready!!!";
		return true;
}
