/*	Heavily modified from Lightbox JS by Lokesh Dhakar: http://huddletogether.com/projects/lightbox/ */
// 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;
}
// 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; }
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime) return;
	}
}
// Preloads images. Pleaces new image in lightbox then centers and displays.
function showEFbox() {
	// prep objects
	var objEFoverlay = document.getElementById('efOverlay');
	var objEFbox = document.getElementById('efbox');
	var objEFboxContent = document.getElementById('efboxContent');
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	// set height of Overlay to take up whole page and show
	if(objEFoverlay) {
		objEFoverlay.style.height = (arrayPageSize[1] + 'px');
		objEFoverlay.style.display = 'block';
	}
	var strHtml = '<h1>' + objEFdata.title + '</h1>';
	strHtml += objEFdata.content;

	if(objEFboxContent) objEFboxContent.innerHTML = strHtml;

	if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); }

	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "hidden"; }
	// display EFbox
	if(objEFbox) objEFbox.style.display = 'block';

	arrayPageSize = getPageSize();
	if(objEFoverlay) objEFoverlay.style.height = (arrayPageSize[1] + 'px');
	return void(0);
}
// hideEFbox()
function hideEFbox() {
	// get objects
	objEFoverlay = document.getElementById('efOverlay');
	objEFbox = document.getElementById('efbox');
	// hide lightbox and overlay
	objEFoverlay.style.display = 'none';
	objEFbox.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 = '';
}
// The function inserts html markup at the top of the page which will be used as a
// container for the overlay pattern and the dialog.
function initEFbox() {
	if (!document.getElementsByTagName){ return; }
	var objBody = document.getElementsByTagName("body").item(0);
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objEFoverlay = document.createElement("div");
	objEFoverlay.setAttribute('id','efOverlay');
	objEFoverlay.onclick = function () {hideEFbox(); return false;}
	objEFoverlay.style.display = 'none';
	objEFoverlay.style.position = 'absolute';
	objEFoverlay.style.top = '0';
	objEFoverlay.style.left = '0';
	objEFoverlay.style.zIndex = '1001';
 	objEFoverlay.style.width = '100%';
	objBody.insertBefore(objEFoverlay, objBody.firstChild);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	// create lightbox div, same note about styles as above
	var objEFbox = document.createElement("div");
	objEFbox.setAttribute('id','efbox');
	objEFbox.style.display = 'none';
	objEFbox.style.position = 'absolute';
	objEFbox.style.zIndex = '1600';
	objBody.insertBefore(objEFbox, objEFoverlay.nextSibling);
	// create top div
	var objEFboxTop = document.createElement("div");
	objEFboxTop.setAttribute('class','top');
	objEFbox.appendChild(objEFboxTop);
	// create caption
	var objEFboxContent = document.createElement("div");
	objEFboxContent.setAttribute('id','efboxContent');
	objEFbox.appendChild(objEFboxContent);
	// create bottom div
	var objEFboxBottom = document.createElement("div");
	objEFboxBottom.setAttribute('class','bttm');
	objEFbox.appendChild(objEFboxBottom);
}
