// JavaScript Document

<!--
function MM_swapImgRestore() { //v1.2
if (document.MM_swapImgData != null)
for (var i=0; i<(document.MM_swapImgData .length-1); i+=2)
document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}
function MM_preloadImages() { //v1.2
if (document.images) {
var imgFiles = MM_preloadImages.arguments;
var preloadArray = new Array();
for (var i=0; i<imgFiles.length; i++) {
preloadArray[i] = new Image;
preloadArray[i].src = imgFiles[i];
}
}
}

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v1.2
var i,j=0,objStr,obj,swapArray=new
Array,oldArray=document.MM_swapImgData;
for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
if ((objStr.indexOf('document.layers[') == 0 && document.layers == null) ||
(objStr.indexOf('document.all[') == 0 && document.all == null))
objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
obj = eval(objStr);
if (obj != null) {
swapArray[j++] = obj;
swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
obj.src = MM_swapImage.arguments[i+2];
} }
document.MM_swapImgData = swapArray; //used for restore
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function preventDefault(e) {
	if (document.addEventListener) e.preventDefault();
	else e.returnValue=false;
	return false;
}
function keypress(e) {
	if(typeof _jaWidgetFocus != 'undefined' && _jaWidgetFocus) return true;
	if(!e) var e = window.event;
	if(e.keyCode) keyCode = e.keyCode; 
	else if(e.which) keyCode = e.which;
	switch(keyCode) {
		case 8: window.location="../"; return false; break;
		case 63235: case 39: window.location="tropical2.html"; return preventDefault(e); break;
		
		case 63273: case 36: window.location="tropical.html"; return preventDefault(e); break;
		case 63275: case 35: window.location="tropical2.html"; return preventDefault(e); break;
		case 32: show_down(); setTimeout('show_out()', 200); return preventDefault(e); break;
		case 13: window.location="slides/Tim drawing.html?show_param=3"; return preventDefault(e); break;
	}
	return true;
}
function setuplisteners() {
	if (document.addEventListener) document.addEventListener('keypress',keypress,false);
	else if (document.attachEvent) document.attachEvent('onkeydown',keypress);
}
up0 = new Image(31,31); up0.src = "res/up.gif";
up1 = new Image(31,31); up1.src = "res/up1.gif";
next0 = new Image(31,31); next0.src = "res/next.gif";
next1 = new Image(31,31); next1.src = "res/next1.gif";
prev0 = new Image(31,31); prev0.src = "res/prev.gif";
prev1 = new Image(31,31); prev1.src = "res/prev1.gif";

show0 = new Image(31,31);show0.src = "res/show.gif";
show1 = new Image(31,31);show1.src = "res/show1.gif";
stop0 = new Image(31,31);stop0.src = "res/stop.gif";
stop1 = new Image(31,31);stop1.src = "res/stop1.gif";


var delay = 3;
function show_over() { 
	document.getElementById("show").src = show1.src;;
}
function show_out() { 
	document.getElementById("show").src = show0.src;
}
function show_down() { 
	window.location="slides/Tim drawing.html?show_param="+delay+ "";
}
function change_delay() { 
	delay = prompt('delay', 3);
}
function redirect() {
}
function calctotalpages() {
	if ( (TotalImages / vtpicp) - (Math.round(TotalImages / vtpicp)) > 0 ) 
  	{
  		return Math.round(TotalImages / vtpicp) + 1;
  	}
	else   {
  		return Math.round(TotalImages / vtpicp);
	}
}

function PopulateGalleryHeaderTable(MyGalleryTitle) {	
	MyGalleryDiv='<table style="height:54px;" align="center" cellspacing="0" cellpadding="0" border="0">';
	MyGalleryDiv=MyGalleryDiv+'<tr><td>';	
	MyGalleryDiv=MyGalleryDiv+'<table width="460px" cellspacing="0" cellpadding="0" border="0">';
	MyGalleryDiv=MyGalleryDiv+'<tr>';
	MyGalleryDiv=MyGalleryDiv+'<td style="width:31px;">';
		if (vpage == 1) {
			MyGalleryDiv=MyGalleryDiv+'<img src="/images/gallery_support/prev_disabled.gif" border="0" width="31" height="31" alt="Prev" title=" At First Page " />';
		} else {
			MyGalleryDiv=MyGalleryDiv+'<img src="/images/buttons/prev.gif" border="0" width="31" height="31" title="  Previous  " alt="Next" name="GalleryPrevButton" onmouseover="MM_swapImage('+myapos+'document.GalleryPrevButton'+myapos+','+myapos+'document.GalleryPrevButton'+myapos+','+myapos+'/images/buttons/prev1.gif'+myapos+')" onmouseout="MM_swapImgRestore()" onclick="galleryprevpage()" />';
		};
	MyGalleryDiv=MyGalleryDiv+'</td>';
	MyGalleryDiv=MyGalleryDiv+'<td style="width:20px;"><img style="border:0;" src="../images/gallery_support/hdr_left.gif" alt="" /></td>';
	MyGalleryDiv=MyGalleryDiv+'<td class="GalleryTitle">';	
	MyGalleryDiv=MyGalleryDiv+MyGalleryTitle;
	MyGalleryDiv=MyGalleryDiv+'</td>';
	MyGalleryDiv=MyGalleryDiv+'<td style="width:20px;"><img style="border:0;" src="../images/gallery_support/hdr_right.gif" alt="" /></td>';
	MyGalleryDiv=MyGalleryDiv+'<td style="width:10px;">';
	if ( vpage < vtpages ) {
			MyGalleryDiv=MyGalleryDiv+'<img src="/images/buttons/next.gif" border="0" width="31" height="31" title="  Next  " alt="Next" name="GalleryNextButton" onmouseover="MM_swapImage('+myapos+'document.GalleryNextButton'+myapos+','+myapos+'document.GalleryNextButton'+myapos+','+myapos+'/images/buttons/next1.gif'+myapos+')" onmouseout="MM_swapImgRestore()" onclick="gallerynextpage()" />';
		} else {
			MyGalleryDiv=MyGalleryDiv+'<img src="/images/gallery_support/next_disabled.gif" border="0" width="31" height="31" alt="Prev" title=" At Last Page " />';
		};
	MyGalleryDiv=MyGalleryDiv+'</td>';
	MyGalleryDiv=MyGalleryDiv+'</tr> </table>';
	MyGalleryDiv=MyGalleryDiv+'</td></tr></table>';	
}

function PopulateGalleryFooterTable(MyGalleryTitle) {
	MyGalleryDiv=MyGalleryDiv+'<table style="height:54px;" align="center" cellspacing="0" cellpadding="0" border="0">';
	MyGalleryDiv=MyGalleryDiv+'<tr><td>';	
	MyGalleryDiv=MyGalleryDiv+'<table width="460px" cellspacing="0" cellpadding="0" border="0">';
	MyGalleryDiv=MyGalleryDiv+'<tr>';
	MyGalleryDiv=MyGalleryDiv+'<td style="width:31px;">';
		if (vpage == 1) {
			MyGalleryDiv=MyGalleryDiv+'<img src="/images/gallery_support/prev_disabled.gif" border="0" width="31" height="31" alt="Prev" title=" At First Page " />';
		} else {
			MyGalleryDiv=MyGalleryDiv+'<img src="/images/buttons/prev.gif" border="0" width="31" height="31" title="  Previous  " alt="Next" name="GalleryPrevButton2" onmouseover="MM_swapImage('+myapos+'document.GalleryPrevButton2'+myapos+','+myapos+'document.GalleryPrevButton2'+myapos+','+myapos+'/images/buttons/prev1.gif'+myapos+')" onmouseout="MM_swapImgRestore()" onclick="galleryprevpage()" />';
		};
	MyGalleryDiv=MyGalleryDiv+'</td>';
	MyGalleryDiv=MyGalleryDiv+'<td style="width:20px;"><img style="border:0;" src="../images/gallery_support/hdr_left.gif" alt="" /></td>';
	MyGalleryDiv=MyGalleryDiv+'<td class="GalleryTitle">';	
	MyGalleryDiv=MyGalleryDiv+MyGalleryTitle;
	MyGalleryDiv=MyGalleryDiv+'</td>';
	MyGalleryDiv=MyGalleryDiv+'<td style="width:20px;"><img style="border:0;" src="../images/gallery_support/hdr_right.gif" alt="" /></td>';
	MyGalleryDiv=MyGalleryDiv+'<td style="width:10px;">';
	if ( vpage < vtpages ) {
			MyGalleryDiv=MyGalleryDiv+'<img src="/images/buttons/next.gif" border="0" width="31" height="31" title="  Next  " alt="Next" name="GalleryNextButton2" onmouseover="MM_swapImage('+myapos+'document.GalleryNextButton2'+myapos+','+myapos+'document.GalleryNextButton2'+myapos+','+myapos+'/images/buttons/next1.gif'+myapos+')" onmouseout="MM_swapImgRestore()" onclick="gallerynextpage()" />';
		} else {
			MyGalleryDiv=MyGalleryDiv+'<img src="/images/gallery_support/next_disabled.gif" border="0" width="31" height="31" alt="Prev" title=" At Last Page " />';
		};
	MyGalleryDiv=MyGalleryDiv+'</td>';
	MyGalleryDiv=MyGalleryDiv+'</tr> </table>';
	MyGalleryDiv=MyGalleryDiv+'</td></tr></table>';	
}
function buildimageblock() {
if (vcount <= vtpicp * vpage  && vcount < TotalImages )
	{
		MyGalleryDiv=MyGalleryDiv+'<td style="width:140px; height:140px; background:url(../images/gallery_support/dia.gif); background-repeat:no-repeat; margin-left:auto; margin-right:auto; text-align:center;">';
		MyGalleryDiv=MyGalleryDiv+'<a href="'+ImageList[vcount].replace(Episode.toLowerCase(),Episode.toLowerCase() + "/slides")+'" rel="lightbox" title=""><img class="image" id='+vcount+' src="'+ImageList[vcount]+'" width="120px" height="86" border="0" align="top")/></a></td>';
		vcount = vcount + 1;
		<!--<a href="images/image-1.jpg" rel="lightbox" title="my caption">image #1</a> -->
	}
}
function buildimagerow() {
	MyGalleryDiv=MyGalleryDiv+'<tr>';
}
function closeimagerow() {
	MyGalleryDiv=MyGalleryDiv+'</tr>';
}
function buildimagetable() {
	MyGalleryDiv=MyGalleryDiv+'<table align="center" width="460px" cellspacing="6" cellpadding="0" border="0">';
}
function closeimagetable() {
	MyGalleryDiv=MyGalleryDiv+'</table>';	
}
function PopulateGallery(TheGallryTitle){		
	PopulateGalleryHeaderTable(TheGallryTitle); 
	buildimagetable(); 
		buildimagerow();	
			buildimageblock();
			buildimageblock();
			buildimageblock();
		closeimagerow();	
		buildimagerow();	
			buildimageblock();
			buildimageblock();
			buildimageblock();
		closeimagerow();	
		buildimagerow();	
			buildimageblock();
			buildimageblock();
			buildimageblock();
		closeimagerow();	
		buildimagerow();	
			buildimageblock();
			buildimageblock();
			buildimageblock();
		closeimagerow();	
	closeimagetable();	
	PopulateGalleryFooterTable(TheGallryTitle); 
}
function GetGalleryVariables() {
	vtpicp = 12;
	vtpages = calctotalpages();
	vcount = ((vpage - 1) * vtpicp);
}
function gallerynextpage() {
	if (vpage < vtpages)
	{
		vpage = vpage + 1;
		vcount = ((vpage - 1) * vtpicp);	
		RefreshGallery();
	};
}
function galleryprevpage() {
	if (vpage > 1)
	{
		vpage = vpage - 1;
		vcount = ((vpage - 1) * vtpicp);
		RefreshGallery();
	};
}

function FastTrackEmailForm() { 
	var daReferrer = document.referrer; 
	var email = "abacus@abacusgardens.com"; 
	var subject = "Abacus Gardens | Fast-track your enquiry"; 
	var mailto_link = 'mailto:'+email+'?subject='+subject; 
	var win = window.open(mailto_link,'emailWindow'); 
	if (win && win.open &&!win.closed) {win.close(); }
} 
function RefreshGallery() {	
		PopulateGallery(MyGalleryTitle);
		document.getElementById('Gallery').innerHTML=MyGalleryDiv; 
		initLightbox();
	}
 
function InsertHeader() {
	document.write('<p><a href="../Home.html"><img src="../images/l1.gif" alt="" border="0" style="margin-left:39px; margin-top:10px " width="11" height="11"></a><img src="../images/sep.gif" alt="" style="margin-left:9px; margin-right:9px " width="1" height="11"><a href="../Sitemap.html"><img src="../images/l2.gif" alt="" border="0" width="11" height="11" ></a><img src="../images/sep.gif" alt="" style="margin-left:9px; margin-right:9px " width="1" height="11"><a href="../Contact Us.html"><img src="../images/l3.gif" alt="" border="0" width="11" height="11" ></a></p>');
}

function InsertMenu2() {
	document.write('<div class="menuclass2">');
	document.write('<p></p>');
	document.write('<p><img src="/images/buttons/Fast_Track.gif" name="FastTrackButton" onmouseover="MM_swapImage('+myapos+'document.FastTrackButton'+myapos+','+myapos+'document.FastTrackButton'+myapos+','+myapos+'/images/buttons/Fast_Track_Up.gif'+myapos+')" onmouseout="MM_swapImgRestore()" onclick="FastTrackEmailForm()" ></p>');
	document.write('<p><a href="/Home.html"><img src="/images/buttons/Home_Button.gif" name="m2HomeButton" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('+myapos+'document.m2HomeButton'+myapos+','+myapos+'document.m2HomeButton'+myapos+','+myapos+'/images/buttons/Home_Button_Up.gif'+myapos+')" border="0"></a></p>');
	document.write('<p><a href="/About%20Us%20Home.html"><img src="/images/buttons/AboutUs_Button.gif" name="AboutUs_Button" onmouseout="MM_swapImgRestore()" onmouseover=	"MM_swapImage('+myapos+'document.AboutUs_Button'+myapos+','+myapos+'document.AboutUs_Button'+myapos+','+myapos+'/images/buttons/AboutUs_Button_Up.gif'+myapos+')" border="0"></a></p>');
	document.write('<p><a href="/services.html"><img src="/images/buttons/Services_Button.gif" name="Services_Button" onmouseout="MM_swapImgRestore()" onmouseover=	"MM_swapImage('+myapos+'document.Services_Button'+myapos+','+myapos+'document.Services_Button'+myapos+','+myapos+'/images/buttons/Services_Button_Up.gif'+myapos+')" border="0"></a></p>');
	document.write('<p><a href="/Garden%20Styles.html"><img src="/images/buttons/GardenStyles_Button.gif" name="GardenStyles_Button" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('+myapos+'document.GardenStyles_Button'+myapos+','+myapos+'document.GardenStyles_Button'+myapos+','+myapos+'/images/buttons/GardenStyles_Button_Up.gif'+myapos+')" border="0"></a></p>');
	document.write('<p><a href="/PhotoGallery%201.html"><img src="/images/buttons/PhotoGallery_Button.gif" name="PhotoGallery_Button" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('+myapos+'document.PhotoGallery_Button'+myapos+','+myapos+'document.PhotoGallery_Button'+myapos+','+myapos+'/images/buttons/PhotoGallery_Button_Up.gif'+myapos+')" border="0" ></a></p>');
	document.write('<p><a href="/Contact%20Us.html"><img src="/images/buttons/ContactUs_Button.gif" name="ContactUs_Button" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('+myapos+'document.ContactUs_Button'+myapos+','+myapos+'document.ContactUs_Button'+myapos+','+myapos+'/images/buttons/ContactUs_Button_Up.gif'+myapos+')" border="0" ></a></p>');
	document.write('<p><a href="/Special%20Offers%20Menu.html"><img src="/images/buttons/SpecialOffers_Button.gif" name="SpecialOffers_Button" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('+myapos+'document.SpecialOffers_Button'+myapos+','+myapos+'document.SpecialOffers_Button'+myapos+','+myapos+'/images/buttons/SpecialOffers_Button_Up.gif'+myapos+')" border="0"></a></p>');
	document.write('<!-- menuclass 2--></div>');
}

function InsertFooter() {
	document.write('<div id="footer">');	
	document.write('<p>Copyright 2009 &copy; The HWH Share Trust. All rights reserved.</p>');
	document.write('<p>Tel: +27 (0) 11 795 2000 * Fax: +27 (0) 11 795 2021 * E-mail: abacus@abacusgardens.com</p>');
	document.write('<p><a href="Privacy.html" class="pol2">Privacy Policy</a>  | <a href="Terms-of-use.html" class="pol2">Terms Of Use</a></p>');
	document.write('<!-- end #footer --></div>');
}
function hidediv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('ImageDiv').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.hideShow.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.hideShow.style.visibility = 'hidden'; 
} 
} 
} 
function showdiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('ImageDiv').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.hideShow.visibility = 'visible'; 
} 
else { // IE 4 
document.all.hideShow.style.visibility = 'visible'; 
} 
} 
} 
/*
	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 = '/images/gallery_support/loading.gif';		
// var closeButton = '/images/gallery_support/close.gif';		
var closeButton = '';

//
// 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] - 10 - objLoadingImage.height) /3 ) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 240 - 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, LAMTEST
		// 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;}
		}
	}

	
	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.height= '100px';
		objLoadingImage.style.width= '300px';
		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

window.onload = function() {
	setuplisteners();		
};


-->

