﻿// JScript File

//function getPageScroll(){

//	var yScroll;

//	if (self.pageYOffset) {
//		yScroll = self.pageYOffset;
//	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
//		yScroll = document.documentElement.scrollTop;
//	} else if (document.body) {// all other Explorers
//		yScroll = document.body.scrollTop;
//	}

//	arrayPageScroll = new Array('',yScroll) 
//	return arrayPageScroll;
//}

//function getPageSize(){
//	
//	var xScroll, yScroll;
//	
//	if (window.innerHeight && window.scrollMaxY) {	
//		xScroll = document.body.scrollWidth;
//		yScroll = window.innerHeight + window.scrollMaxY;
//	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
//		xScroll = document.body.scrollWidth;
//		yScroll = document.body.scrollHeight;
//	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
//		xScroll = document.body.offsetWidth;
//		yScroll = document.body.offsetHeight;
//	}
//	
//	var windowWidth, windowHeight;
//	if (self.innerHeight) {	// all except Explorer
//		windowWidth = self.innerWidth;
//		windowHeight = self.innerHeight;
//	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
//		windowWidth = document.documentElement.clientWidth;
//		windowHeight = document.documentElement.clientHeight;
//	} else if (document.body) { // other Explorers
//		windowWidth = document.body.clientWidth;
//		windowHeight = document.body.clientHeight;
//	}	
//	
//	// for small pages with total height less then height of the viewport
//	if(yScroll < windowHeight){
//		pageHeight = windowHeight;
//	} else { 
//		pageHeight = yScroll;
//	}

//	// for small pages with total width less then width of the viewport
//	if(xScroll < windowWidth){	
//		pageWidth = windowWidth;
//	} else {
//		pageWidth = xScroll;
//	}


//	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
//	return arrayPageSize;
//}

//function pause(numberMillis) {
//	var now = new Date();
//	var exitTime = now.getTime() + numberMillis;
//	while (true) {
//		now = new Date();
//		if (now.getTime() > exitTime)
//			return;
//	}
//}

//function getKey(e){
//	if (e == null) { // ie
//		keycode = event.keyCode;
//	} else { // mozilla
//		keycode = e.which;
//	}
//	key = String.fromCharCode(keycode).toLowerCase();
//	
//	if(key == 'x'){ hideLightbox(); }
//}

//function listenKey () {	document.onkeypress = getKey; }

function hideLightbox2()
{
	// get objects
	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox2');

	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	
	// disable keypress listener
	document.onkeypress = '';
}

function showLightbox2(p_strPre, p_intId)
{
	
	//var objLink = 
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox2');
	var objPreloading = document.getElementById('loadingImage');
	var objSource = document.getElementById(p_strPre + p_intId);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

    var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 500) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 420) / 2);
	
	objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
	objLightbox.innerHTML = objSource.innerHTML;
	objPreloading.style.display='none';
    if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	}
	objOverlay.style.height = (arrayPageSize[1] + 'px');
    objOverlay.style.display = 'block';
	objLightbox.style.display= 'block';
//	// center loadingImage if it exists
//	if (objLoadingImage) {
//		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 300) / 2) + 'px');
//		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - 200) / 2) + 'px');
//		objLoadingImage.style.display = 'block';
//	}

//	// set height of Overlay to take up whole page and show
//	objOverlay.style.height = (arrayPageSize[1] + 'px');
//	objOverlay.style.display = 'block';

	// preload image
//	imgPreload = new Image();

//	imgPreload.onload=function(){
//		objImage.src = objLink.href;

//		// center lightbox and make sure that the top and left values are not negative
//		// and the image placed outside the viewport
//		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 300) / 2);
//		var lightboxLeft = ((arrayPageSize[0] - 20 - 200) / 2);
//		
//		objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
//		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";


//		objLightboxDetails.style.width = imgPreload.width + 'px';
//		
//		if(objLink.getAttribute('title')){
//			objCaption.style.display = 'block';
//			//objCaption.style.width = imgPreload.width + 'px';
//			objCaption.innerHTML = objLink.getAttribute('title');
//		} else {
//			objCaption.style.display = 'none';
//		}
		
		// A small pause between the image loading and displaying is required with IE,
		// this prevents the previous image displaying for a short burst causing flicker.
		 

//		if (objLoadingImage) {	objLoadingImage.style.display = 'none'; }
//		objLightbox.style.display = 'block';

		// After image is loaded, update the overlay height as the new image might have
//		// increased the overall page height.
//		arrayPageSize = getPageSize();
//		objOverlay.style.height = (arrayPageSize[1] + 'px');
//		
//		// Check for 'x' keypress
//		listenKey();

//		return false;
//	}

	//imgPreload.src = objLink.href;
	
}

function initLightbox2()
{
	objOverlay = document.getElementById('overlay');
	var objBody = document.getElementsByTagName("body").item(0);
	//alert("test");

	// create lightbox div, same note about styles as above
	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox2');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '300';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
	// create link
	var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.setAttribute('title','Click to close');
	objLink.onclick = function () {hideLightbox2(); return false;}
	objLightbox.appendChild(objLink);
    
//    var objPrev = document.createElement("div");
//    objPrev.setAttribute('id', 'PrevImg');
    //objPrev.innerHTML = ArrayRels[0];
    //objLightbox.appendChild(objPrev);
	// preload and create close button image
	//g_strNextImg
	
//	var imgNextImg = new Image();
//	imgNextImg.src = g_strNextImg;
//	imgNextImg.setAttribute('id','NextImg');
//	var objNextLink = document.createElement("a");
//	objNextLink.setAttribute('href','#');
//	objNextLink.setAttribute('id','NextImgLink');
//	//objNextLink.setAttribute('rel','lightbox');
//	//objNextLink.setAttribute('Func','Next');
//	objNextLink.appendChild(imgNextImg);
//	
//	var imgPrevImg = new Image();
//	imgPrevImg.src = g_strPrevImg;
//	imgPrevImg.setAttribute('id','PrevImg');
//	var objPrevLink = document.createElement("a");
//	objPrevLink.setAttribute('href','#');
//	objPrevLink.setAttribute('id','PrevImgLink');
//	//objPrevLink.setAttribute('rel','lightbox');
//	//objPrevLink.setAttribute('Func','Previous');
//	objPrevLink.appendChild(imgPrevImg);
//	
//	objLightbox.appendChild(objPrevLink);
//	objLightbox.appendChild(objNextLink);
	
	var imgPreloadCloseButton = new Image();

	// if close button image found, 
	imgPreloadCloseButton.onload=function(){

		var objCloseButton = document.createElement("img");
		objCloseButton.src = closeButton;
		objCloseButton.setAttribute('id','closeButton2');
		objCloseButton.style.position = 'absolute';
		objCloseButton.style.styleFloat = 'right';
		objCloseButton.style.right = '10px';
		objCloseButton.style.top = '10px';
		objCloseButton.style.zIndex = '200';
		objLink.appendChild(objCloseButton);

		return false;
	}

	imgPreloadCloseButton.src = closeButton;

	// create image
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage2');
	objLink.appendChild(objImage);
	
	// create details div, a container for the caption and keyboard message
//	var objLightboxDetails = document.createElement("div");
//	objLightboxDetails.setAttribute('id','lightboxDetails');
//	objLightbox.appendChild(objLightboxDetails);

	// create caption
//	var objCaption = document.createElement("div");
//	objCaption.setAttribute('id','lightboxCaption');
//	objCaption.style.display = 'none';
//	objLightboxDetails.appendChild(objCaption);


//    if (!document.getElementsByTagName){ return; }
//	    var anchors = document.getElementsByTagName("a");
//        var ArrayRels=new Array()
//        var Counter = 0;
//	    // loop through all anchor tags
//	    for (var i=0; i<anchors.length; i++)
//	    {
//		    var anchor = anchors[i];
//            //var test = '';
//		    if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox"))
//		    {
//		        if(!anchor.getAttribute("Func")) {  
//		            anchor.id = 'Photo_'+Counter;
//		            Counter++;
//		            anchor.onclick = function () {showLightbox(this); return false;}
//		            }
//			    
//		    }
//	    }
}




//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
//
function addLoadEvent2(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}



addLoadEvent2(initLightbox2);	// run initLightbox onLoad