/****************************************************************************************************************/
//SET UP ALL GLOBAL VARIABLES AND ARRAYS 	<!-- Last Updated Date: 6-1-2010   Time: 2PM   Version: 1.2 -->	
/****************************************************************************************************************/
//sets up all top nav id's
var depositSub = "#deposit_sub";
var consumersSub = "#consumers_sub";
var bankSub = "#bank_sub";
var regulationsSub = "#regulations_sub";
var buyingSub = "#buying_sub";
var newsSub = "#news_sub";
var aboutSub = "#about_sub";

var siloClicked;

//sets up all hover id's
var navClickID;
var nullTopNavID;
var subNavClickID;
var navHoverID;
var navHoverSubID;

//array that sets all directory paths to sub nav array id's up above
var dictionary = new Array();

//depositSubArr id's
dictionary[ "idasp/main_bankfind.asp" ] = "#deposit_sub1"; //WWW2 page
dictionary[ "deposit/deposits" ] = "#deposit_sub2";
dictionary[ "deposit/investments" ] = "#deposit_sub3";
dictionary[ "deposit/insurance" ] = "#deposit_sub4";
dictionary[ "deposit/deposits/international" ] = "#deposit_sub5";

//consumersSubArr id's
dictionary[ "consumers/consumer" ] = "#consumers_sub1";
dictionary[ "consumers/loans" ] = "#consumers_sub2";
dictionary[ "consumers/banking" ] = "#consumers_sub3";
dictionary[ "consumers/education" ] = "#consumers_sub4";
dictionary[ "consumers/community" ] = "#consumers_sub5";
dictionary[ "consumers/theft" ] = "#consumers_sub6";
dictionary[ "consumers/privacy" ] = "#consumers_sub7";

//bankSubArr id's
dictionary[ "bank/statistical" ] = "#bank_sub1";
dictionary[ "bank/analytical" ] = "#bank_sub2";
dictionary[ "bank/individual/failed" ] = "#bank_sub3";

//regulationsSubArr id's
dictionary[ "regulations/examinations" ] = "#regulations_sub1";
dictionary[ "regulations/laws" ] = "#regulations_sub2";
dictionary[ "regulations/resources" ] = "#regulations_sub3";
dictionary[ "" ] = "#regulations_sub4"; //links to https://www2.fdicconnect.gov/
dictionary[ "regulations/required" ] = "#regulations_sub5";
dictionary[ "regulations/examiner" ] = "#regulations_sub6";

//buyingSubArr id's
dictionary[ "buying/loan" ] = "#buying_sub1";
dictionary[ "buying/owned" ] = "#buying_sub2";
dictionary[ "buying/financial" ] = "#buying_sub3";
dictionary[ "buying/servicing" ] = "#buying_sub4";
dictionary[ "buying/otherasset" ] = "#buying_sub5";
dictionary[ "buying/historical" ] = "#buying_sub6";

//newsSubArr id's
dictionary[ "news/news/press/2012" ] = "#news_sub1";
dictionary[ "" ] = "#news_sub2"; //Survey
dictionary[ "news/conferences" ] = "#news_sub3"; 
dictionary[ "news/news/financial/2012" ] = "#news_sub4";
dictionary[ "news/news/SpecialAlert/2011" ] = "#news_sub5";
dictionary[ "news/letters" ] = "#news_sub6";
dictionary[ "news/news/speeches/chairman" ] = "#news_sub7";

//*************************************************************************************************************//
//Browser Detection Code variable - JavaScript Date: 4-22-10
//*************************************************************************************************************//
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
//sets users browser to a variable
var browser = BrowserDetect.browser + ' ' + BrowserDetect.version;
/****************************************************************************************************************/
//end of global variables
/****************************************************************************************************************/

//runs when document is ready
$(document).ready(function(){
	setNavClass();
	BrowserDetect.init();
	
	/*Setting top-nav Clicked Item */
	$("#top-nav span").click(function (event) { 
		navClickID = "#" + $(this).attr("id");
		subNavClickID = navClickID + "_sub";
		//clearing
		$("#top-nav .active").removeClass("active");
		//single action
		$(navClickID).addClass("active");
		$(subNavClickID).css('visibility', 'visible');	
	});
	
	$("#about_sub1").click(function (event) { 
		$("#about_sub .active").removeClass("active");
		$("#about_sub1").addClass("active");
	});
	$("#about_sub2").click(function (event) { 
		$("#about_sub .active").removeClass("active");
		$("#about_sub2").addClass("active");
	});
	$("#about_sub3").click(function (event) { 
		$("#about_sub .active").removeClass("active");
		$("#about_sub3").addClass("active");
	});
	$("#about_sub4").click(function (event) { 
		$("#about_sub .active").removeClass("active");
		$("#about_sub4").addClass("active");
	});
	$("#about_sub5").click(function (event) { 
		$("#about_sub .active").removeClass("active");
		$("#about_sub5").addClass("active");
	});
	$("#about_sub6").click(function (event) { 
		$("#about_sub .active").removeClass("active");
		$("#about_sub6").addClass("active");
	});
	$("#about_sub7").click(function (event) { 
		$("#about_sub .active").removeClass("active");
		$("#about_sub7").addClass("active");
	});
	
	/*Setting 'top-nav' to Home when FDIC Logo is Clicked */
	$("#header-nav-left").click(function () { 
		//clearing
		$("#top-nav .active").removeClass("active");		
		//single action
		$("#home").addClass("active");
	});
/*	*****************TEST CODE*******************************************************************
//////////////another option for the hover to fix ie 7 slowness when hover//////////////////
	$("#top-nav span").each( function()
	{ 
        var row = $(this);
        row.hover(
            function() {
                setTimeout( function() { row.addClass('hover'); }, 0 );
				navHoverID = "#" + $(this).attr("id");
				navHoverSubID = "#" + $(this).attr("id") + "_sub";
				mopen();
            },
            function() {
				setTimeout( function() { row.addClass('hover'); }, 0 );
				mclose();
			}
        );
}); 
*/	
	$("#header-nav-left div").hover(function () {
		$(this).removeClass("homeOff");
		$(this).addClass("homeOver");
	}, function () {
		$(this).removeClass("homeOver");
		$(this).addClass("homeOff");
	});
	
	$("#top-nav span").hover(function () {
		navHoverID = "#" + $(this).attr("id");
		navHoverSubID = "#" + $(this).attr("id") + "_sub";
	
		$("#top-nav .hover").removeClass("hover");
		$(navHoverID).addClass("hover");

		mopen();	
	}, function () {
		//Detects the Users Browser
		if(browser == 'Explorer 6')
		{
			ie6_mclose();
		}
		if(browser != 'Explorer 6')
		{
			mclose();
		}
	});

});	
	
/****************************************************************************************************************/
//ALL CLASS FUNCTIONS
/****************************************************************************************************************/
//sets the current page url to the active state
function setNavClass()
{	
	//private variables
	var strUrl = window.location.href; //grabs full URL
	var strJnk = strUrl.substring(strUrl.indexOf('://') + 3, strUrl.length); //takes out everything before and up to :// in URL
	var strDirs = strJnk.substring(strJnk.indexOf('/') + 1, strUrl.length); //takes anything prior to the 1st directory off the string
	var arrDirs = strDirs.split('/'); //seperates all spilts with commas (ex) news/news/press = news,news,press
	var i = 0;
	var arrLen = arrDirs.length; //tells how long the array is (ex) news,news,press = 3
	var filePos = arrLen - 1; //last element of the array which should be the file in the URL.
	var strFile = arrDirs[filePos]; //tells how deep the directory goes from the root folder
	var arrRemoveLastElement = arrDirs.pop(); //deletes last object in the string array
	var newArrLen = arrDirs.length; //gives new array length after the last object was pop() off the end of the string
	var newArrDirs = arrDirs.join("/"); //replaces commas in string array with '/', (ex) news,news,press = news/news/press

	//If you find a file, remove it and reset the length of the array.	
	// Loop through the array setting the class name for each item in it. If you don't find it, default home to current.

	for (i=0;i<=arrLen;i++) 
	{
		if (document.getElementById(arrDirs[i]) != null) 
		{
			var arrTopNavID = arrDirs[i];
			var arrSubNavID = "#" + arrTopNavID + "_sub";

			if (newArrLen >= 2)
			{
				//private variables
				var onLoadClickID;
				var onLoadClickIDSplit;
				var onLoadClickIDPop;
				
				//alert("newArrLen is greater or equal to 2 directories");
				onLoadClickID = dictionary[newArrDirs];
				if(onLoadClickID == null)
				{
					nullTopNavID = "#" + arrTopNavID + "_sub";
					document.getElementById(arrDirs[i]).className = "active"		
					$(arrSubNavID).css('visibility', 'visible');
					subNavClickID = nullTopNavID;
				}
				if(onLoadClickID != null)
				{
					onLoadClickIDSplit = onLoadClickID.split("");
					onLoadClickIDPop = onLoadClickIDSplit.pop();
					$(dictionary[newArrDirs]).addClass("active");
					onLoadClickIDJoin = onLoadClickIDSplit.join("");
					$(onLoadClickIDJoin).css('min-width', '915px');
					subNavClickID = onLoadClickIDJoin;
				}
			}
			
			if(arrSubNavID == "#about_sub")
			{
				var anchor = arrRemoveLastElement;
				
				if(anchor == "index.html#1")
				{
					$("#about_sub1").addClass("active");
				}
				if(anchor == "index.html#2")
				{
					$("#about_sub2").addClass("active");
				}
				if(anchor == "index.html#3")
				{
					$("#about_sub3").addClass("active");
				}
				if(anchor == "index.html#4")
				{
					$("#about_sub4").addClass("active");
				}
				if(anchor == "index.html#5")
				{
					$("#about_sub5").addClass("active");
				}
				if(anchor == "index.html#6")
				{
					$("#about_sub6").addClass("active");
				}
				if(anchor == "index.html#7")
				{
					$("#about_sub7").addClass("active");
				}
			}
			
			//alert("newArrLent is less than 2 directories deep");
			document.getElementById(arrDirs[i]).className = "active"		
			$(arrSubNavID).css('visibility', 'visible');
			subNavClickID = arrSubNavID;
			return;
		}
			document.getElementById("home").className = "active"
			return;	
	}
	
	if (strFile.indexOf(".") || strFile.indexOf(" ")) 
	{
		arrDirs.splice(filePos, 1);
		arrLen = arrDirs.length - 1;
		//alert("loads strFile.indexOf");
	}			
}

//set all sub-nav id's to hidden
function hideAllSubs()
{
	$(depositSub).css('visibility', 'hidden');
	$(consumersSub).css('visibility', 'hidden');
	$(bankSub).css('visibility', 'hidden');
	$(regulationsSub).css('visibility', 'hidden');
	$(buyingSub).css('visibility', 'hidden');
	$(newsSub).css('visibility', 'hidden');
	$(aboutSub).css('visibility', 'hidden');
}

//open hidden layer
function mopen()
{	
	hideAllSubs();
	$(navHoverSubID).css('width', '990px');
	$(subNavClickID).css('visibility', 'hidden');	
	$(navHoverSubID).css('visibility', 'visible');	
}

//close showed layer
function mclose()
{
	$("#header-nav").mouseover(function (){
		mclosetime();
	});
	$(navHoverSubID).mouseover(function (){
		$(navHoverID).addClass("hover");
		$(subNavClickID).css('visibility', 'hidden');
		$(nullTopNavID).css('visibility', 'hidden');
		$(navHoverSubID).css('visibility', 'visible');
	});
	$(subNavClickID).mouseover(function (){
		mclosetime();
	});
	$("#header-container").mouseout(function (){
		mclosetime();
	});
}

//close showed layer for ie 6 users
function ie6_mclose()
{
	$("#top-nav").mouseover(function (){
		mopen();
	});
	$("#home").mouseout(function (){
		mclosetime();
	});
	/*$("#about").mouseout(function (){
		mclosetime();
	});*/
	$("#header-nav").mouseover(function (){
		mclosetime();
	});
	$("table, td, th, tr, h1, h2, h3, h4, h5, h6, p, img").mouseover(function (){
		mclosetime();
	});
}

//after close set nav back to previous settings
function mclosetime()
{
	$("#top-nav .hover").removeClass("hover");
	$(navHoverSubID).css('visibility', 'hidden');
	$(subNavClickID).css('visibility', 'visible');
}

/****************************************************************************************************************/
// Lightbox JavaScript Code - JavaScript Date: 4-20-10
/****************************************************************************************************************/
/*
	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)
	
	Table of Contents
	-----------------
	Configuration
	
	Functions
	- getPageScroll()
	- getPageSize()
	- pause()
	- getKey()
	- listenKey()
	- showLightbox()
	- hideLightbox()
	- initLightbox()
	- addLoadEvent()
	
	Function Calls
	- addLoadEvent(initLightbox)

*/

//
// Configuration
//

// If you would like to use a custom loading image or close button reference them in the next two lines.
var loadingImage = '/header/images/Lightbox/loading.gif';		
var closeButton = '/header/images/Lightbox/fancy_close.png';		
//
// 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;
}
//
// pause(numberMillis)
// 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;
	}
}
//
// 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'){ hideLightbox(); }
}
//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }	
//
// showLightbox()
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showLightbox(objLink)
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
	var objCaption = document.getElementById('lightboxCaption');
	var objImage = document.getElementById('lightboxImage');
	var objLoadingImage = document.getElementById('loadingImage');
	var objLightboxDetails = document.getElementById('lightboxDetails');

	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// center loadingImage if it exists
	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	// preload image
	imgPreload = new Image();

	imgPreload.onload=function(){
		objImage.src = objLink.href;

		// center lightbox and make sure that the top and left values are not negative
		// and the image placed outside the viewport
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - imgPreload.width) / 2);
		
		objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";


		objLightboxDetails.style.width = imgPreload.width + 'px';
		
		if(objLink.getAttribute('title')){
			objCaption.style.display = 'block';
			//objCaption.style.width = imgPreload.width + 'px';
			objCaption.innerHTML = objLink.getAttribute('title');
		} else {
			objCaption.style.display = 'none';
		}
		
		// A small pause between the image loading and displaying is required with IE,
		// this prevents the previous image displaying for a short burst causing flicker.
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			pause(250);
		} 

		if (objLoadingImage) {	objLoadingImage.style.display = 'none'; }

		// 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";
        }

	
		objLightbox.style.display = 'block';

		// After image is loaded, update the overlay height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		
		// Check for 'x' keypress
		listenKey();

		return false;
	}

	imgPreload.src = objLink.href;
	
}
//
// hideLightbox()
//
function hideLightbox()
{
	// 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 = '';
}
//
// 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()
{
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
			anchor.onclick = function () {showLightbox(this); return false;}
		}
	}

	// 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.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';
		objLoadingImageLink.appendChild(objLoadingImage);

		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs

		return false;
	}

	imgPreloader.src = loadingImage;

	// create lightbox div, same note about styles as above
	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '100';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
	// create link
	var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.setAttribute('title','Click to close');
	objLink.onclick = function () {hideLightbox(); return false;}
	objLightbox.appendChild(objLink);

	// preload and create close button image
	var imgPreloadCloseButton = new Image();

	// if close button image found, 
	imgPreloadCloseButton.onload=function(){

		var objCloseButton = document.createElement("img");
		objCloseButton.src = closeButton;
		objCloseButton.setAttribute('id','closeButton');
		objCloseButton.style.position = 'absolute';
		objCloseButton.style.zIndex = '200';
		objLink.appendChild(objCloseButton);

		return false;
	}

	imgPreloadCloseButton.src = closeButton;

	// create image
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink.appendChild(objImage);
	
	// create details div, a container for the caption and keyboard message
	var objLightboxDetails = document.createElement("div");
	objLightboxDetails.setAttribute('id','lightboxDetails');
	objLightbox.appendChild(objLightboxDetails);

	// create caption
	var objCaption = document.createElement("div");
	objCaption.setAttribute('id','lightboxCaption');
	objCaption.style.display = 'none';
	objLightboxDetails.appendChild(objCaption);

	// create keyboard message
	var objKeyboardMsg = document.createElement("div");
	objKeyboardMsg.setAttribute('id','keyboardMsg');
	objKeyboardMsg.innerHTML = 'press <a href="#" onclick="hideLightbox(); return false;"><kbd>x</kbd></a> to close';
	objLightboxDetails.appendChild(objKeyboardMsg);


}
//
// 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)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

addLoadEvent(initLightbox);	// run initLightbox onLoad

/****************************************************************************************************************/
// End of Lightbox JavaScript Code                                                                              	
/****************************************************************************************************************/
