/*
   ADAPTED FROM:
   Lightbox JS: Fullsize Image Overlays 
	by Lokesh Dhakar - http://www.huddletogether.com

	For more information on this script, visit:
	http://huddletogether.com/projects/lightbox/

	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
	(basically, do anything you want, just leave my name and link)
	
   NOTE: Altered by CB to create and display dark overlay only, with extraneous
   functions removed and relevant functions revised and renamed.
  
	Table of Contents
	-----------------
	Configuration
	
	Functions
	- getPageHeight() -- (formerly getPageSize())
  	- showOverlay() -- (formerly showLightbox())
  	- hideOverlay() -- (formerly hideLightbox())
  	- initOverlay() -- (formerly initLightbox())

*/



//
// Configuration
//

// CB Note: requires #overlay section of lightbox.css added to our css
// And image called overlay.png
// Must be initialized by adding initOverlay() call to body onload.



//
// get PageHeight -- (formerly getPageSize)
// Original function returned array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
// CB altered (and renamed) to return page height only
// and also added some Windows IE corrections
//
function getPageHeight(){
	
	var yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
	}
	
	var windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}	
	
  // CB added because IE 6.0 on Windows with XHTML 1.0 Transitional doctype is not working
  var newHeight = 0;
  if (document.documentElement && document.documentElement.scrollHeight)
    newHeight = document.documentElement.scrollHeight;
  if (newHeight > yScroll)
    yScroll = newHeight;
  
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	return pageHeight;
}


//
// showOverlay -- (formerly showLightbox)
// Displays overlay.
//
function showOverlay()
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLoading = document.getElementById('ajaxload');

  // get page height
  var pageHeight = getPageHeight();

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (pageHeight + 'px');
	objOverlay.style.display = 'block';
  
  // display loading image
  objLoading.style.visibility = 'visible';
//  new Effect.Appear('overlay', {duration : 0.5});
}


//
// hideOverlay -- (formerly hideLightbox)
// Hides overlay.
//
function hideOverlay()
{
	// get object
	objOverlay = document.getElementById('overlay');

	// hide overlay
	objOverlay.style.display = 'none';
}


//
// initOverlay -- (formerly initLightbox)
// Function should run on window load.
// It inserts html markup at the top of the page which will be used as a
// container for the overlay pattern.
//
function initOverlay()
{
	if (!document.getElementsByTagName){ return; }
	// the rest of this code inserts html creating the overlay div as the first element after <body>
	//
	// <div id="overlay" style="display:none; position:absolute; top:0; left:0; z-index:2; width:100%"></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.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '2';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
}
