//	runthere v1.0
//	2005 (c) RunThere.com 
//	you may borrow, but please don't steal :-)
// 	THIS SOFTWARE IS PROVIDED WITHOUT WARRANTY.

// Set up globals
var Browser = {
	IE: (document.all ? true : false),
	getVersion: function(){
		return parseFloat(navigator.appVersion.split('MSIE')[1]);
	},
	Safari:((navigator.userAgent.indexOf('Safari')!= -1)? true : false),
	Firefox:((!document.all&&window.XMLHttpRequest)? true : false),
	Opera:((typeof window.opera != 'undefined')? true : false),
	scrollbarWidth: function(){
		if(typeof this.scrollbarWidthStored != 'undefined'){
			return this.scrollbarWidthStored;
		}
		var wNoScroll = 0;
	    var wScroll = 0;

	    // Outer scrolling div, Start with no scrollbar
	    var a = $$.create('div');
		$$.setStyle(a, 'position', 'absolute', 'top', '-1000px', 'left', '-1000px','width', '100px', 'height', '50px', 'overflow', 'hidden');
	    
	    // Inner content div
	    var b = $$.create('div');
		$$.setStyle(b, 'width', '100%', 'height', '200px');

	    // Put the inner div in the scrolling div
	    $$.addChild(a, b);
	    // Append the scrolling div to the doc
	    $$.addChild(document.body, a);

	    // Width of the inner div sans scrollbar
	    wNoScroll = b.offsetWidth;
	    // Add the scrollbar
	    a.style.overflow = 'auto';
	    // Width of the inner div width scrollbar
	    wScroll = b.offsetWidth;

	    // Remove the scrolling div from the doc
	    document.body.removeChild(a);

	    // Pixel width of the scroller
		this.scrollbarWidthStored = wNoScroll - wScroll;
	    return this.scrollbarWidthStored;
	},
	windowSize: function(){
		//Firefox, mozilla, safari, opera, netscape
		var w = window.innerWidth;
		var h = window.innerHeight;

		if(typeof w == 'undefined'){
			try{
				w = document.documentElement.clientWidth;
				h = document.documentElement.clientHeight;
			}catch(e){
				w = document.body.clientWidth;
				h = document.body.clientHeight;
			}
		}
		return {x: w, y: h};
	},
	pngfix: function (img,w,h){
		if(Browser.IE && (Browser.getVersion() >= 5.5) && (Browser.getVersion() < 7) && (document.body.filters)){
			//only IE less than version 7
			var src = $$.getA(img, 'src');
			img.onload = null;
			if(w && h){
				$$.style(img, 'width', w + 'px', 'height', h + 'px');
			}
			var fimg = img.cloneNode(true);
			$$.setA(fimg, 'src', 'images/blank.gif');
			$$.style(fimg, 'filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')");
			img.parentNode.replaceChild(fimg, img);
		}
	}
};


// AJAX functions
function XMLHttp(){if(typeof XMLHttpRequest != 'undefined'){return new XMLHttpRequest();}else {try{return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{return new ActiveXObject("Microsoft.XMLHTTP");}catch(E){return null;}}}}
//params = new Array ( errordisplay,contentdisplay,formtofill,routetoimport,routenumload)
function doAJAX(typ,addr,data,action,inaction,params){
	var r = new XMLHttp();
	if(!r){alert('Your browser is not compatible with our site. Please update to Firefox.');return false;}
	r.open(typ, addr + '&blah=' + new Date().getTime(), true);
	if(typ == 'POST'){r.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}
	r.onreadystatechange = function(){
		if (r.readyState==4){
			if(r.responseXML){action(r.responseXML.documentElement,r.responseText,params);}
			else if(r.responseText){action(null,r.responseText,params);}
			else{inaction(params);}
		}
	};
	r.send(data);
	return true;
}

// DOM object reference
function $(id){return (typeof id == 'string')? document.getElementById(id) : id;}
function $tag(x, tag){return x.getElementsByTagName(tag);}

//DOM global object
var $$ = {
	create: function(t){
		var a = document.createElement(t);
		for(var i=1; i<arguments.length; i+=2){
			switch(arguments[i]){
				case 'class': $$.setClass(a,arguments[i+1]);break;
				case 'valign': a.vAlign=arguments[i+1];break;
				case 'align': a.align=arguments[i+1];break;
				case 'colspan': a.colSpan=arguments[i+1];break;
				case 'rowspan': a.rowSpan=arguments[i+1];break;
				case 'cellpadding': a.cellPadding=arguments[i+1];break;
				case 'cellspacing': a.cellSpacing=arguments[i+1];break;
				case 'valign': a.vAlign=arguments[i+1];break;
				case 'innerText': $$.text(a,arguments[i+1]);break;
				default: $$.setA(a, arguments[i], arguments[i+1]);break;
			}
		}
		return a;
	},
	show: function(){
		var s = '';
		var n = null;
		for(var i=0; i < arguments.length; i++){
			n = $(arguments[i]);
			switch(n.tagName){
				case 'DIV': case 'UL': s = 'block';break;
				case 'TABLE': s = 'table';break;
				case 'TR': s = 'table-row';break;
				case 'TD': s = 'table-cell';break;
				case 'TABLE': s = 'table';break;
				case 'TBODY': case 'THEAD': s = 'table-row-group';break;
				default:
					s = 'inline';
			}
			try{n.style.display = s;}catch(e){n.style.display = 'block';}
		}
	},
	hide: function(){
		for(var i = 0; i < arguments.length; i++){
			$(arguments[i]).style.display = 'none';
		}
	},
	chop: function(){
		var n = '';
		for(var i = 0; i < arguments.length; i++){
			n = $(arguments[i]);
			n.parentNode.removeChild(n);
		}
	},
	toggle: function(n, os, oh){
		//node, onShow, onHide
		n = $(n);
		if(n.style.display == 'none'){
			$$.show(n);
			if(os){os();}
		}else{
			$$.hide(n);
			if(oh){oh();}
		}
	},
	toggleForce: function(n, tf){
		if(tf){
			$$.show(n);
		}else{
			$$.hide(n);
		}
	},
	opacity: function(n, o){
		n = $(n);
		n.style.opacity = o;
		if(Browser.IE){
			n.style.filter = 'alpha(opacity='+(o*100)+')';
			n.style.zoom = "1";//to force hasLayout
		}else{
			n.style.MozOpacity = o;
			n.style['-moz-opacity'] = o;
		}
	},
	setClass: function(n, c){
		$$.setA(n, 'class', c);
		$$.setA(n, 'className', c);
	},
	addClass: function(n, c){
		n = $(n);
		var cs = n.className.split(' ');
		var nc = '';
		for(var i in cs){
			//check if this class is already added
			if(c == cs[i]){
				return;
			}
			nc += cs[i] + ' ';
		}
		$$.setClass(n, nc + ' ' + c);
	},
	removeClass: function(n, c){
		n = $(n);
		var cs = n.className.split(' ');
		var cn = '';
		for(var i in cs){
			if(c !== cs[i]){//check if this class is NOT being removed
				cn += cs[i] + ' ';
			}
		}
		$$.setClass(n, cn);
	},
	setStyle: function(n){
		n = $(n);
		for(var i = 1; i < arguments.length; i += 2){
			n.style[arguments[i]] = arguments[i+1];
		}
	},
	style: function(n){
		n = $(n);
		var l = arguments.length;
		for(var i=1; i < l; i += 2){
			n.style[arguments[i]] = arguments[i + 1];
		}
	},
	addChild: function(n){
		n = $(n);
		for(var i=1; i<arguments.length; i++){
			n.appendChild(arguments[i]);
		}
	},
	text: function(n, t){
		n = $(n);
		while(n.childNodes.length){
			n.removeChild(n.firstChild);
		}
		if(typeof(t) == 'string'){
			n.appendChild(document.createTextNode(t));
		}else{
			n.appendChild(t);
		}
	},
	size: function(n){
		n = $(n);
		return {x: n.offsetWidth, y: n.offsetHeight};
	},
	position: function(n){
		n = $(n);
		var dx = n.offsetLeft;
		var dy = n.offsetTop;
		if(n.offsetParent){
			while( n = n.offsetParent){
				dx += n.offsetLeft;
				dy += n.offsetTop;
			}
		}
		return{x: dx, y: dy};
	},
	//get attribute
	getA: function(n, a){
		return $(n).getAttribute(a);
	},
	//set attribute
	setA: function(n, a, v){
		$(n).setAttribute(a, v);
	},
	//get value
	getV: function(n){
		n = $(n);
		if(n.placeholder && n.value == n.placeholder){
			return '';
		}
		return n.value;
	},
	//set value
	setV: function(n, v){
		n = $(n);
		n.value = v;
		if(n.placeholder){
			Placeholder.blur(n);
		}
	}
};

// XML parsing
function X$Obj(x,node){return x.getElementsByTagName(node);}
function X$(x,node){return X$Obj(x,node)[0].childNodes[0].nodeValue;}

function X$a_set(x,a,n){return x.setAttribute(a,n);}
function X$_(x,node){var t = X$(x,node);return t.substring(0,t.length-1);}
function X$$(x){return x.childNodes[0].nodeValue;}
function X$$_(x){var t = X$$(x);return t.substring(0,t.length-1);}

function checkNum(num){v = '0123456789';for (var i=0; i < num.length ; i++){if (v.indexOf(num.charAt(i)) == -1){return false;}}return true;}
function setColors(elem,bg,fg){if(elem){elem.style.backgroundColor = bg; elem.style.color = fg;}}
function trim(str){return str.replace(/^\s*|\s*$/g,'');}
function addslashes(str,dbl){return (dbl)? str.replace('"','\\"'): str.replace('\'','\\\'');}
function deg2rad(deg){this.pd=Math.PI/180; return deg*this.pd;}
function encode(str){var result = '';for (i = 0; i < str.length; i++) {if (str.charAt(i) == ' '){result += '+';}else{ result += str.charAt(i);}}return escape(result);}
function escapeDblQuote(str){return str.replace(/"/g,'&quot;')}

//String functions
var $String = {
	addBreaks: function(s, maxWdLen){
		if(!s){return '';}
		var out = '';
		var wdLen = '';
		var nPcs = '';
		
		//split by spaces
		var wds = s.split(' ');
		for(var i = 0; i < wds.length; i++){
			wdLen = wds[i].length;
			if(wdLen < maxWdLen){
				//word is shorter than cutoff
				out += wds[i];
			}else{
				nPcs = Math.ceil(wdLen / maxWdLen) ;
				for(var j = 0; j < nPcs; j++){
					out += wds[i].substr(j * maxWdLen, maxWdLen) + '<wbr />';
				}
			}
			out += ' ';
		}
		return out;		
	},
	escape: function(s){
		var a = $$.create('div');
		$$.text(a, s);
		return a.innerHTML;
	},
	trim: function(s){
		return s.replace(/^\s*|\s*$/g,'');
	}
};

// Placeholder Text
var Placeholder = {
	init: function(){
		var is;
		if(arguments.length){
			//setup only the passed in nodes
			is = arguments;
			for(var i = 0; i < is.length; i++){
				Placeholder.addHandlers($(is[i]));
			}
		}else{
			//setup all nodes on page
			is = $tag(document, 'INPUT');
			var t = '';
			for(var i = 0; i < is.length; i++){
				t = is[i];
				if(t.type.toLowerCase() != 'text'){
					continue;		
				}else{
					Placeholder.addHandlers(t);
				}
			}
			is = $tag(document, 'TEXTAREA');
			for(var i=0; i < is.length; i++){
				t = is[i];
				Placeholder.addHandlers(t);
			}
		}
	},
	addHandlers: function(n){
		try{
			var ph = $$.getA(n, 'ph');
			if(ph && ph !== ''){
				//store placeholder on node
				n.placeholder = ph;
				if(!n.value){
					//show placeholder if input has empty value
					Placeholder.blur(n);
				}
				//set up event handlers
				var of = n.onfocus;
				n.onfocus = function(){
					Placeholder.focus(n);
					//if(of){of();}
				};
				//var ob = n.onblur;
				n.onblur = function(){
					Placeholder.blur(n);
					//if(ob){ob();}
				};
			}
		}catch(e){}
	},
	focus: function(a){
		if(a.showingPH){
			a.value = '';
			a.style.color = 'black';			
		}
	},
	blur: function(a){
		//if(!trim(a.value)){
		if(!trim(a.value)){
			//input is empty or just whitepsace
			a.style.color = '#999';
			a.value = a.placeholder;
			a.showingPH = true;
		}else{
			a.style.color = 'black';
			a.showingPH = false;
		}
	}
};

function unhide(id){$(id).style.display='block';}
function unhideA(ids){for(var i=0;i<ids.length;i++){try{unhide(ids[i]);}catch(e){}}}
function chop(obj){obj.parentNode.removeChild(obj);}
function loginPlz(reason){window.open('login.php?mini=1&r='+reason,'_blank','width=455,height=350,toolbar=no,location=yes,directories=no,status=yes,menubar=yes,scrollbars=no,copyhistory=no,resizable=yes');}

//Button/Onclick Functionality
var Btn = {
	init: function(){//pass in button(s) as arguments
		//each button to setup is an array
		//	[0] => ID of button or image
		//	[1] => onclick function FUNCTION
		//	[2] => use hover opacity T|F
		//	[3] => title STRING
		//	[4] => is selected T|F
		//	[5] => custom disabled opacity NUMBER		
		
		var a = null;
		var b = null;
		for(var i = 0; i < arguments.length; i++){
			a = arguments[i];
			b = $(a[0]);//try to grab this node
			//console.debug(a + ': ' + b);
			//alert(b);
			if(null === b){continue;}//else, continue to the next one
			b.onclick = a[1];
			if(a[5]){
				b.disabledOpacity = a[5];
			}
			if(a[2]){
				//add hover handlers, if set
				b.onmouseover = function(){Btn.enable(this);};
				b.onmouseout = function(){if(!this.isReallySelected){Btn.disable(this);}};
				Btn.disable(b);
			}
			if(a[3]){
				//add title if set
				b.title = a[3];
			}
			if(a[4]){
				//enable button if selected
				Btn.select(b);
			}
			if(b.nodeName == 'A'){
				//add this to prevent page from jumping around
				b.href = 'javas' + 'cript:void(0)';
			}
			
		}
	},
	disable: function(){//pass in button(s) as arguments
		var b = null;
		var o = 0.4;
		for(var i = 0; i < arguments.length; i++){
			b = $(arguments[i]);
			//alert('before isDisabled set');
			b.isReallyDisabled = true;//for internal usage
			//alert('after isDisabled set');
			o = (typeof b.disabledOpacity == 'number')? b.disabledOpacity : 0.4;
			switch(b.nodeName){
				case 'BUTTON':
				case 'INPUT':
				case 'TEXTAREA':
					b.disabled = true;
					o = 1;
					break;
				default:
					$$.opacity(b, o);//ie doesn't make pretty buttons with opacity
			}
			$$.removeClass(b, 'click');
		}
	},
	enable: function(){//pass in button(s) as arguments
		var b = null;
		for(var i = 0; i < arguments.length; i++){
			b = $(arguments[i]);
			b.isReallyDisabled = false;//for internal usage.. IE6 sucks!
			switch(b.nodeName){
				case 'BUTTON':
				case 'INPUT':
				case 'TEXTAREA':
					b.disabled = false;
					break;
				default:
					$$.opacity(b, 1);//ie makes ugly buttons with opacity
			}
			$$.addClass(b, 'click');
		}
	},
	select: function(){//pass in button(s) as arguments
		var b = null;
		for(var i = 0; i < arguments.length; i++){
			b = $(arguments[i]);
			b.isReallySelected = true;
			Btn.enable(b);
		}

	},
	unselect: function(){//pass in button(s) as arguments
		var b = null;
		for(var i = 0; i < arguments.length; i++){
			b = $(arguments[i]);
			b.isReallySelected = false;
			Btn.disable(b);
		}
	}
};

var Form = {
	ajaxed : function(form){
		if(typeof(form) == 'object'){
			//first we check the form
			if(Form.check(form)){
				var ins = form.elements;
				var out ='';
				for(var i=0;i<ins.length;i++){			
					try{
						out += '&' + Form.ajaxInput(ins[i]);
					}catch(e){
					}
				}
				Form.ajaxClear();
				return out;
			}
		}
		return false;
	},
	ajaxInput : function(input){
		//alert(input.type);
		switch (input.type){
			case 'checkbox':
				return Form.ajaxCbox(input);
			case 'radio':
				return Form.ajaxRadio(input);
			case 'select-one':
			case 'select':
				return $$.getA(input,'name')+'='+(input.options[input.selectedIndex]).value;
			case 'text':
			case 'textarea':
				return $$.getA(input,'name')+'='+encode(trim(input.value));
		}
		return '';
	},
	ajaxClear:function(){
		Form.doneCbox = [];
		Form.doneRadio = [];
	},
	doneCbox:[],
	ajaxCbox:function(inp){
		var n = $$.getA(inp,'name');
		if(!Form.doneCbox[n]){
			//do this entire checkbox name group
			var cs = document.getElementsByName(n);
			var out = n+'=';
			for(var i=0;i<cs.length;i++){
				out += cs[i].value + ':' + ((cs[i].checked)?'1':'0') + ';';
			}
			//flag it as done
			Form.doneCbox[n] = true;
			//return values
			return out.substr(0,out.length-1);
		}
		return '';

	},
	doneRadio:[],
	ajaxRadio:function(inp){
		
		var n = $$.getA(inp,'name');
		if(!Form.doneRadio[n]){
			//do this entire checkbox name group
			var rs = document.getElementsByName(n);
			var out = n+'=';
			for(var i=0;i<rs.length;i++){
				if(rs[i].checked){
					out += rs[i].value;
				}
			}
			//flag it as done
			Form.doneRadio[n] = true;
			//return values
			return out;
		}
		return '';
	},
	check:function(form){
		if(typeof(form) == 'object'){
			var ins = form.elements;
			var isOk = 1;
			for(var i=0;i<ins.length;i++){
				if(!Form.checkInput(ins[i])){
					isOk = 0;
				}
			}
			return isOk;
		}
		return 1;
	},
	checkInput:function(input){
		return true;
	},
	buildInput:function(inx){
		//returns an array
		//[label,input(s)]
		var l = $$.getA(inx,'label');
		var n = $$.getA(inx,'name');
		switch($$.getA(inx,'type')){
			case 't':
				//text input
				return [l,'<input type="text" name="'+n+'" class="" value="'+escapeDblQuote(X$$_(inx))+'" />'];
			case 'ta':
				//textarea
				return [l,'<textarea type="text" name="'+n+'" class="">'+X$$_(inx)+'</textarea>'];
			case 'r':
				//radio
				var a = (X$$(inx)).split(';');
				var b = '';
				for(var i=0;i<a.length;i++){
					var c = (a[i]).split(':');
					var d = parseInt(c[2]);
					b += '<div><input type="radio" name="'+n+'" id="'+n+'_'+c[0]+'" value="'+c[0]+'" '+((d)? 'checked="checked"':'')+' /> <label for="'+n+'_'+c[0]+'">'+c[1]+'</label></div>';
				}
				return [l,b];
			case 's':
				//select
				var a = (X$$(inx)).split(';');
				var b = '';
				for(var i=0;i<a.length;i++){
					var c = (a[i]).split(':');
					var d = parseInt(c[2]);
					b += '<option type="radio" value="'+c[0]+'" '+((d)? 'selected="selected"':'')+'>'+c[1]+'</option>';
				}
				return [l,'<select name="'+n+'" class="">'+b+'</select>'];
			case 'c':
				//checkbox
				var a = (X$$(inx)).split(';');
				var b = '';
				for(var i=0;i<a.length;i++){
					var c = (a[i]).split(':');
					var d = parseInt(c[2]);
					b += '<div><input type="checkbox" name="'+n+'" value="'+c[0]+'" id="'+n+'_'+c[0]+'" '+((d)? 'checked="checked"':'')+' /> <label for="'+n+'_'+c[0]+'">'+c[1]+'</label></div>';
				}
				return [l,b];
		}
	}
};


/*
	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/lightbox/loading.gif';		
var closeButton = 'images/lightbox/close.gif';		





//
// 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 = $('overlay');
	var objLightbox = $('lightbox');
	var objCaption = $('lightboxCaption');
	var objImage = $('lightboxImage');
	var objLoadingImage = $('loadingImage');
	var objLightboxDetails = $('lightboxDetails');

	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	if($('flythroughVideo')){
		$('flythroughVideo').style.visibility = 'hidden';
	}
	
	// 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 = $('overlay');
	objLightbox = $('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";
	}
	if($('flythroughVideo')){
		$('flythroughVideo').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