var loadingImage = 'images/processing.gif';
var loadingCaption = 'images/waiting.bmp';

//
// 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;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function Anthem_PreCallBack()
{
	document.body.style.cursor = 'wait';            
	//var loading = document.getElementById("divProgressPage");
	//loading.Visible = true;
	//loading.style.visibility = "visible";
	showLightbox();
	
}	
	//
// showLightbox()
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showLightbox(objLink)
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLoadingImage = document.getElementById('loadingImage');
	var objLoadingCaption = document.getElementById('loadingCaption');
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// center loadingImage if it exists
	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 138) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - 214) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}
	
	// center loadingImage if it exists
	//if (objLoadingCaption) {
	//	objLoadingCaption.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingCaption.height) / 2) + 25 + 'px');
	//	objLoadingCaption.style.left = (((arrayPageSize[0] - 20 - objLoadingCaption.width) / 2) + 'px');
	//	objLoadingCaption.style.display = 'block';
	//}

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	// Hide select boxes as they will 'peek' through the image in IE
	//selects = document.getElementsByTagName("select");
    //for (i = 0; i != selects.length; i++) {
    //        selects[i].style.visibility = "hidden";
    //}

	
}

function Anthem_PostCallBack()
{

	hideLightbox();
	//loading.Visible = false;
	//loading.style.visibility='hidden';
	document.body.style.cursor = '';
}   
      	
//
// hideLightbox()
//
function hideLightbox()
{
	// get objects
	objOverlay = document.getElementById('overlay');
	objLoadingImage = document.getElementById('loadingImage');
	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLoadingImage.style.display = 'none';
	// make select boxes visible
	//selects = document.getElementsByTagName("select");
    //for (i = 0; i != selects.length; i++) {
	//	selects[i].style.visibility = "visible";
	//}

}


//
// initLightbox()
// Function runs on window load, going through link tags looking for rel="lightbox".
// These links receive onclick events that enable the lightbox display for their targets.
// The function also inserts html markup at the top of the page which will be used as a
// container for the overlay pattern and the inline image.
//
function initLightbox(blnBack)
{
	
	if (!document.getElementsByTagName){ return; }


	// the rest of this code inserts html at the top of the page that looks like this:
	//
	// <div id="overlay">
	//		<a href="#" onclick="hideLightbox(); return false;"><img id="loadingImage" /></a>
	//	</div>
	// <div id="lightbox">
	//		<a href="#" onclick="hideLightbox(); return false;" title="Click anywhere to close image">
	//			<img id="closeButton" />		
	//			<img id="lightboxImage" />
	//		</a>
	//		<div id="lightboxDetails">
	//			<div id="lightboxCaption"></div>
	//			<div id="keyboardMsg"></div>
	//		</div>
	// </div>
	
	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 () {hideLightbox(); return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	//// preload and create loader image
	var imgPreloader = new Image();
	
	// if loader image found, create link to hide lightbox and create loadingimage
	imgPreloader.onload=function(){

		var objLoadingImageLink = document.createElement("a");
		objLoadingImageLink.setAttribute('href','#');
		//objLoadingImageLink.innerHTML='blah';
		//objLoadingImageLink.onclick = function () {hideLightbox(); return false;}
		objOverlay.appendChild(objLoadingImageLink);
		
		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = loadingImage;
		objLoadingImage.setAttribute('id','loadingImage');
		objLoadingImage.style.position = 'absolute';
		objLoadingImage.style.zIndex = '150';
		//objLoadingImage.style.height = '80';
		//objLoadingImage.style.width = '80';
		objLoadingImageLink.appendChild(objLoadingImage);
		
		
		//var objLoadingCaption = document.createElement("img");
		//objLoadingCaption.src = loadingCaption;
		//objLoadingCaption.setAttribute('id','loadingCaption');
		//objLoadingCaption.style.position = 'absolute';
		//objLoadingCaption.style.zIndex = '150';
		//objLoadingImageLink.appendChild(objLoadingCaption);
	
		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs
		if (blnBack){
		backButtonOverride();
		}
		return false;
	}
	
	imgPreloader.src = loadingImage;
	
}




//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func,blnBack)
{	
	
    window.onload = function(){
	func(blnBack);
	}
}

//addLoadEvent(initLightbox);	// run initLightbox onLoad

function backButtonOverride()
			{
			// Work around a Safari bug
			// that sometimes produces a blank page
			setTimeout("backButtonOverrideBody()", 1);
			}

			function backButtonOverrideBody()
			{
			// Works if we backed up to get here
			try {
				history.forward();
			} catch (e) {
				// OK to ignore
			}
			// Every quarter-second, try again. The only
			// guaranteed method for Opera, Firefox,
			// and Safari, which don't always call
			// onLoad but *do* resume any timers when
			// returning to a page
			setTimeout("backButtonOverrideBody()", 500);
			}