




/*
     FILE ARCHIVED ON 18:26:28 sep 20, 2007 AND RETRIEVED FROM THE
     INTERNET ARCHIVE ON 15:04:21 nov 10, 2011.
     JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.

     ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
     SECTION 108(a)(3)).
*/
/*
	eZ showOverlay script, based on:
	
	Lightbox JS: Fullsize Image Overlays 
	by Lokesh Dhakar - http://web.archive.org/web/20070920182628/http://www.huddletogether.com

	For more information on this script, visit:
	http://web.archive.org/web/20070920182628/http://huddletogether.com/projects/lightbox/

	Licensed under the Creative Commons Attribution 2.5 License - http://web.archive.org/web/20070920182628/http://creativecommons.org/licenses/by/2.5/
	(basically, do anything you want, just leave my name and link)

*/


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
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;
}


//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
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;
	}
	//  Minus scrollbar with
	windowWidth -= 19;

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){ hideOverlay(); }
}

function listenKey () {	document.onkeypress = getKey; }
	

//
// showOverlay()
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showOverlay(id)
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var popup = document.getElementById(id);
	
	if (popup) {
/*		popup.style.width='542px';*/
/*		alert(popup.style.width);*/
/*		popup.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - popup.style.height) / 2) + 'px');*/
/*		popup.style.left = (((arrayPageSize[0] - 20 - popup.style.width) / 2) + 'px');*/
		popup.style.display = 'block';
	}
	
	// hide select boxes (IE bugfix)
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
	
	// set height and width of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.width = (arrayPageSize[2] + 'px');
	objOverlay.style.display = 'block';
}


//
// hideOverlay()
//
function hideOverlay(id)
{
	// get objects
	objOverlay = document.getElementById('overlay');
/*	objLightbox = document.getElementById('lightbox');*/

	// hide lightbox and overlay
	objOverlay.style.display = 'none';
/*	objLightbox.style.display = 'none';*/

	// make select boxes visible
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}

	// disable keypress listener
	document.onkeypress = '';
	
	// close popup div
	document.getElementById(id).style.display='none';
}

var initlayer = '';
function initLightbox()
{
	var objBody = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
/*	objOverlay.onclick = function () {hideOverlay(); return false;}*/
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '200';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	if ( initlayer != '')
	{
	    showOverlay(initlayer);
	    initlayer ='';
    }
}


//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://web.archive.org/web/20070920182628/http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}


addLoadEvent(initLightbox);	// run initLightbox onLoad
