//Global Variables
/* common javsacript file */
// JavaScript Browser Sniffer
// Eric Krok, Andy King, Michel Plungjan Jan. 31, 2002
// see http://www.webreference.com/ for more information
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

    var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();
    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);

	var is_opera = (agt.indexOf("opera") != -1);

	var is_mac = (agt.indexOf("mac")!=-1);
    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       if(is_mac) {
           var iePos = agt.indexOf('msie');
           is_minor = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));
       }
       else is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
       is_major = parseInt(is_minor);
    }

    var is_konq = false;
    var kqPos   = agt.indexOf('konqueror');
    if (kqPos !=-1) {                 
       is_konq  = true;
       is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
       is_major = parseInt(is_minor);
    }                                 

    var is_getElementById   = (document.getElementById) ? "true" : "false";
    var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
    var is_documentElement = (document.documentElement) ? "true" : "false";

    var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
    var is_khtml  = (is_safari || is_konq);

    var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
	var is_ie4   = (is_ie && is_major == 4);
    var is_ie5   = (is_ie && is_major == 5);
	var is_ie5up = (is_ie && is_minor >= 5);
	var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
	var is_ie6   = (is_ie && is_major == 6);


/* PC-IE4 and Mac IE 5+ redirect */
	if (is_ie4 || (is_ie5up == true && is_mac == true) || (is_ie5 == true && is_ie5_5 == false)) {
		window.location="../fail/fail-browser.html";
	}

/* function to have multiple events within the onload event */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function clearText(thefield) {
	if (thefield.defaultValue==thefield.value) {
		thefield.value = "";
	}
}

var xmlhttp;
function ajaxcheck(redirect) {
	if(window.XMLHttpRequest) {
    	try {
			xmlhttp = new XMLHttpRequest();
        } catch(e) {
			xmlhttp = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		xmlhttp = false;
        	}
		}
    }
    //NO XMLREQUEST SUPPORT
    if(!xmlhttp) {
		alert('Your browser does not support AJAX, you will now be redirected');
		document.location.href=redirect
   }

}
function exec_request(url,id,anchorname) {
	if(window.XMLHttpRequest) {
    	try {
			xmlhttp = new XMLHttpRequest();
        } catch(e) {
			xmlhttp = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		xmlhttp = false;
        	}
		}
    }
 
	if(xmlhttp) {
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
	
	if (xmlhttp.readyState==4) {
		var response=xmlhttp.responseText;
	//	alert(url);
		if (response > ''); {
		updatecontent(id,response); //write the layer		
		hide(id);
		show(id);
		scrolltoanchor(anchorname);
		}
	//	}
	}	
	}
	
	xmlhttp.setRequestHeader('Accept','message/x-formresult')
	xmlhttp.send(null)
	return false
	}
}
function scrolltoanchor(anchorname) {
try {
document.getElementById(anchorname).focus();
document.getElementById(anchorname).scrollIntoView();
} catch(e){}

//window.location.href=window.location.href+"#"+anchorname;
}
//PRODUCT WIZARD FUNCTIONS
function WizardAnswer_Change(id,divid,ctl,type,nexttype,section,answer,categoryid) {
var radio=document.getElementById(id);
var WizardAnswerID = radio.checked;
var WizardAnswerIDAry = id.split("wizard_");
var AnswerID = WizardAnswerIDAry[1];
if (answer == 0) {
//DO NOTHING
}
else {
AnswerID = answer;
}

var showsubmit=2;
if (layerexists('SubmitBtn') == true){
showsubmit=0
hide('SubmitBtn');
show('SubmitBtn');
}
if (WizardAnswerID == true) {
//TYPE = RADIOBUTTONLIST SO UNCHECK EVERYTHING ELSE
if (type==4) {
uncheckall(id,ctl);
}
exec_request("../includes/getnextquestion2.aspx?nqid="+radio.value+"&type="+nexttype+"&answerid="+AnswerID+"&show="+showsubmit+"&catid="+categoryid,divid,"bottoma");
}

if (showsubmit==0){
hide('SubmitBtn');
show('SubmitBtn');
}

if (WizardAnswerID == false) {
	hide(divid);
	exec_request("../includes/removeanswercookie.aspx?answerid="+AnswerID+"&catid="+categoryid,divid);
}
}

//PRODUCT WIZARD FUNCTIONS
function WizardAnswer_Change2(id,divid,ctl,type,nexttype,section,answer) {
var radio=document.getElementById(id);
var WizardAnswerID = radio.checked;
var WizardAnswerIDAry = id.split("wizard_");
var AnswerID = WizardAnswerIDAry[1];
var showsubmit=2;
if (layerexists('SubmitBtn') == true){
showsubmit=0
hide('SubmitBtn');
show('SubmitBtn');
}

if (answer == 0) {
//DO NOTHING
}
else {
AnswerID = answer;
}

if (WizardAnswerID == true) {
//TYPE = RADIOBUTTONLIST SO UNCHECK EVERYTHING ELSE
if (type==4) {
uncheckall(id,ctl);
}
exec_request("../includes/getnextquestioncutdown.aspx?nqid="+radio.value+"&type="+nexttype+"&answerid="+AnswerID+"&show="+showsubmit,divid, "bottoma");
}

if (WizardAnswerID == false) {
	hide(divid);
	exec_request("../includes/removeanswercookie.aspx?answerid="+AnswerID,divid);
}
}

function WizardAnswer_CreateCookie(id,ctl,type) {
var radio=document.getElementById(id);
var WizardAnswerID = radio.checked;
var WizardAnswerIDAry = id.split("wizard_");
var AnswerID = WizardAnswerIDAry[1];
if (WizardAnswerID == true) {
//TYPE = RADIOBUTTONLIST SO UNCHECK EVERYTHING ELSE
if (type==4) {
uncheckall(id,ctl);
}
exec_request("../includes/createcookie.aspx?answerid="+AnswerID);
}

if (WizardAnswerID == false) {
	hide(divid);
	exec_request("../includes/removeanswercookie.aspx?answerid="+AnswerID,divid);
}

}


function uncheckall(theid,allid) {

    tmp = document.getElementsByTagName('input');
    //alert(tmp.length);
    var rad;
    var type;
    var radary;
    for (var i = 0; i < tmp.length; i++){		
		if (tmp[i].id.indexOf(allid)>(-1)) {
			rad = tmp[i]
			//alert(rad.id+allid);
			// alert('found allid');
			if (rad.id.indexOf(theid)>(-1)) {
				rad.checked = true;
			}
			else {
			
					rad.checked = false;	
			}
		//	alert('newvalue:'+rad.value);
		}
     
    }

}

//END PRODUCT WIZARD FUNCTIONS


//CONTACT WIZARD FUNCTIONS
function ContactWizardID_Change(id,divid) {
var dropdown=document.getElementById(id);
var ContactWizardID = dropdown.options[dropdown.selectedIndex].value;
if (dropdown.options[dropdown.selectedIndex].value>0) {
exec_request("../includes/getcontactquestions.aspx?cwid="+ContactWizardID,divid,"stepthree");
}
}
function ContactWizardIDP_Change(id,divid) {
var dropdown=document.getElementById(id);
var ContactWizardID = dropdown.options[dropdown.selectedIndex].value;
if (dropdown.options[dropdown.selectedIndex].value>0) {

exec_request("../includes/getchildcontactwizards.aspx?cwid="+ContactWizardID,divid,"steptwo");
hide('wizstep2');
show('wizstep2');
//writeintolayer('selectwizard', 'Select your Wizard:');
writeintolayer('wizardquestions', '');
}
}


function show(idname){
    try {
		      document.getElementById(idname).style.display = (document.getElementById(idname).style.display == 'none') ? 'block' : 'none';
				document.getElementById(idname).style.visibility = 'visible';
        	} catch(e) {
          		
        	}
   
}
function layerexists(objid) {
  try  {
		  if (typeof objid != 'object') {
			objid = document.getElementById(objid);
		}
		if (objid){
			return true;
		}
		else {
			return false;
		}
		} catch (e) {
			return false;
		} 
}

function writeintolayer(objid,content) {
  if (typeof objid != 'object') {

    objid = document.getElementById(objid);
  }
  if (objid){
    objid.innerHTML = content;
  }
}

function hide(idname){

			try {
		          document.getElementById(idname).style.display =  'none';
        	} catch(e) {
          		
        	}
}

function updatecontent(idname, content) {

  if (typeof idname != 'object') {
    idname = document.getElementById(idname);
  }
  if (idname){
		try {
		       idname.innerHTML = content;
        	} catch(e) {
          		
        	}

    }
  }




function getParameter ( queryString, parameterName ) {
var parameterName = parameterName + "=";
if ( queryString.length > 0 ) {
begin = queryString.indexOf ( parameterName );
if ( begin != -1 ) {
begin += parameterName.length;
end = queryString.indexOf ( "&" , begin );
if ( end == -1 ) {
end = queryString.length
}
return unescape ( queryString.substring ( begin, end ) );
}
return "null";
}
} 


function download(fileUrl) {
  var downloadUrl='../includes/download.aspx?file='+fileUrl;
  self.location.href=downloadUrl;
}

function showPopUp(url)
{	

	popUp = window.open(url,'PopUp','scrollBars=1,resizable=1,toolbar=no,status=no,width=756,height=600'); 
        popUp.focus();

}

//ENTER PRESS FUNCTION
function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 


}

//MORE PRODUCT WIZARD FUNCTIONS

function changeAnswer(allid) {
		    if (layerexists('SubmitBtn') == true){
							hide('SubmitBtn');
							show('SubmitBtn');
							} 
    tmp = document.getElementsByTagName('input');
    var rad;
    var type;
    var wizcheck;
    for (var i = 0; i < tmp.length; i++) {		
		if (tmp[i].id.indexOf(allid)>(-1)) {
			rad = tmp[i]
			wizcheck = rad.checked;
			if (wizcheck==true) {
				clickRadio(rad.id);	
			}
			
		}
    }
}

function clickRadio(id) { 
      var bt = document.getElementById(id); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                        bt.click(); 
                        return false;  
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                        bt.click();  
                        return false; 
            } 
      } 
}




//HOVER JAVASCRIPT

// JavaScript Document
<!--//--><![CDATA[//><!--

startList = function() {
    try {
		      
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav_right");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
        	} catch(e) {
          		
        	}

}

window.onload=startList;

//--><!]]>

///NAV ROLLOVER JS
// JavaScript Document<script language="JavaScript">
function MM_findObj(n, d) { //v3.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
<!--
var type = "IE";	//Variable used to hold the browser name

BrowserSniffer();

//detects the capabilities of the browser
function BrowserSniffer() {
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";		//Opera
	else if (document.all) type="IE";														//Internet Explorer e.g. IE4 upwards
	else if (document.layers) type="NN";													//Netscape Communicator 4
	else if (!document.all && document.getElementById) type="MO";							//Mozila e.g. Netscape 6 upwards
	else type = "IE";		//I assume it will not get here
}

//Displays the generic browser type
function whatBrows() {
	window.alert("Browser is : " + type);
}

//Puts the contents of str into the layer id
//id is the name of the layer
//str is the required content
//Works with all browsers except Opera
function ChangeContent(id, str) {
	if (type=="IE") {
		document.all[id].innerHTML = str;
	}
	if (type=="NN") { 
		document.layers[id].document.open();
		document.layers[id].document.write(str);
		document.layers[id].document.close();
	}
	if (type=="MO" || type=="OP") {
		document.getElementById(id).innerHTML = str;
	}
}

//Change the color of the layer background
//id is the name of the layer
//color is the required color
//Works with all browsers except NN4
function ChangeLayerBgColor(id, color){
	if (type=="IE") document.all[id].style.backgroundColor=color;
	if (type=="NN") document.layer['id'].bgColor=color;
	if (type=="MO" || type=="OP") document.getElementById(id).style.backgroundColor=color;
}

//Show and hide a layer
//id is the name of the layer
//action is either hidden or visible
//Seems to work with all versions NN4 plus other browsers
function ShowLayer(id, action){
	if (type=="IE") eval("document.all." + id + ".style.visibility='" + action + "'");
	if (type=="NN") eval("document." + id + ".visibility='" + action + "'");
	if (type=="MO" || type=="OP") eval("document.getElementById('" + id + "').style.visibility='" + action + "'");
}


//-->
<!--
window.onload=montre;
function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}
//-->
//--> Added
		var navID = null;
		var lastID = null;
		
		var hideNav = null;
		var hideImg = null;
		var hideID = null;
	
	function navIDNull(){
		navID = null;
	}

	function navOver(id, imgID, empty, imgURL){
		navID = id
	
		if (lastID == null) {
			lastID = id;
			ShowLayer(navID,'visible');
			MM_swapImage(imgID, '', imgURL);
		}
		
		if (navID == lastID) {
			clearTimeout(hideNav);
			clearTimeout(hideImg);
			clearTimeout(hideID);
			ShowLayer(navID,'visible');
			MM_swapImage(imgID, '', imgURL);
		} else {
			ShowLayer(lastID,'hidden');
			MM_swapImgRestore();
			lastID = navID;
			ShowLayer(navID,'visible');
			MM_swapImage(imgID, '', imgURL);
			clearTimeout(hideNav);
			clearTimeout(hideImg);
			clearTimeout(hideID);
		}		
	}
	
	function navOut(id){
		hideNav = setTimeout("ShowLayer('"+[navID]+"','hidden')", 1000);
		hideImg = setTimeout("MM_swapImgRestore()", 1000);
		hideID = setTimeout("navIDNull()", 1000);
	}
//--> End added


//ENTER PRESS FUNCTION
function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 


}






/*
	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()
	- 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 = '../i/popup.jpg';		
var closeButton = '../i/popup.jpg';		





//
// 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;
	}
}





//
// 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 arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// center loadingImage if it exists


	// 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";


		
		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);
		} 

		objLoadingImage.style.display = 'none';
		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');

		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';
}


//
// 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="lightboxCaption"></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.style.display = 'inline';	// added to fix a {display:none;} in style sheet
		objLoadingImageLink.onclick = function () {hideLightbox(); return false;}
		objOverlay.appendChild(objLoadingImageLink);
		
		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = loadingImage;
		objLoadingImage.setAttribute('id','loadingImage');
		objLoadingImage.setAttribute('usemap','mapname');
		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';
		objCloseButton.style.top = '5px';		
		objCloseButton.style.right = '5px';		
		objLink.appendChild(objCloseButton);

		return false;
	}

	imgPreloadCloseButton.src = closeButton;

	// create image
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink.appendChild(objImage);
	
	// create caption
	var objCaption = document.createElement("div");
	objCaption.setAttribute('id','lightboxCaption');
	objCaption.style.display = 'none';
	objLightbox.appendChild(objCaption);

}




//
// 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
