﻿// JScript File

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 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';	
}

function initLightbox2()
{
	objOverlay = document.getElementById('overlay');
	var objBody = document.getElementsByTagName("body").item(0);

	// 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 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
}
//
// 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