/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
/*--------------------------------------------------------------------------*/

//note: modified & stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}

Object.extend = function(destination, source) {
	for (property in source) destination[property] = source[property];
	return destination;
}

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}

Function.prototype.bindAsEventListener = function(object) {
var __method = this;
	return function(event) {
		__method.call(object, event || window.event);
	}
}

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;

	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
}

if (!window.Element) var Element = new Object();

Object.extend(Element, {
	remove: function(element) {
		element = $(element);
		element.parentNode.removeChild(element);
	},

	hasClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var hasClass = false;
		element.className.split(' ').each(function(cn){
			if (cn == className) hasClass = true;
		});
		return hasClass;
	},

	addClassName: function(element, className) {
		element = $(element);
		Element.removeClassName(element, className);
		element.className += ' ' + className;
	},
  
	removeClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var newClassName = '';
		element.className.split(' ').each(function(cn, i){
			if (cn != className){
				if (i > 0) newClassName += ' ';
				newClassName += cn;
			}
		});
		element.className = newClassName;
	},

	cleanWhitespace: function(element) {
		element = $(element);
		$c(element.childNodes).each(function(node){
			if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element.remove(node);
		});
	},

	find: function(element, what) {
		element = $(element)[what];
		while (element.nodeType != 1) element = element[what];
		return element;
	}
});

var Position = {
	cumulativeOffset: function(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.offsetTop  || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL, valueT];
	}
};

document.getElementsByClassName = function(className) {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = [];
	$c(children).each(function(child){
		if (Element.hasClassName(child, className)) elements.push(child);
	});  
	return elements;
}



function $c(array){
	var nArray = [];
	for (var i=0;i<array.length;i++) nArray.push(array[i]);
	return nArray;
}

/*
moo.fx, simple effects library built with prototype.js (http://prototype.conio.net).
by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE.
for more info (http://moofx.mad4milk.net).
Sunday, March 05, 2006
v 1.2.3
*/

var fx = new Object();
//base
fx.Base = function(){};
fx.Base.prototype = {
	setOptions: function(options) {
	this.options = {
		duration: 500,
		onComplete: '',
		transition: fx.sinoidal
	}
	Object.extend(this.options, options || {});
	},

	step: function() {
		var time  = (new Date).getTime();
		if (time >= this.options.duration+this.startTime) {
			this.now = this.to;
			clearInterval (this.timer);
			this.timer = null;
			if (this.options.onComplete) setTimeout(this.options.onComplete.bind(this), 10);
		}
		else {
			var Tpos = (time - this.startTime) / (this.options.duration);
			this.now = this.options.transition(Tpos) * (this.to-this.from) + this.from;
		}
		this.increase();
	},

	custom: function(from, to) {
		if (this.timer != null) return;
		this.from = from;
		this.to = to;
		this.startTime = (new Date).getTime();
		this.timer = setInterval (this.step.bind(this), 13);
	},

	hide: function() {
		this.now = 0;
		this.increase();
	},

	clearTimer: function() {
		clearInterval(this.timer);
		this.timer = null;
	}
}

//stretchers
fx.Layout = Class.create();
fx.Layout.prototype = Object.extend(new fx.Base(), {
	initialize: function(el, options) {
		this.el = $(el);
		this.el.style.overflow = "hidden";
		this.iniWidth = this.el.offsetWidth;
		this.iniHeight = this.el.offsetHeight;
		this.setOptions(options);
	}
});

fx.Height = Class.create();
Object.extend(Object.extend(fx.Height.prototype, fx.Layout.prototype), {	
	increase: function() {
		this.el.style.height = this.now + "px";
	},

	toggle: function() {
		if (this.el.offsetHeight > 0) this.custom(this.el.offsetHeight, 0);
		else this.custom(0, this.el.scrollHeight);
	}
});

fx.Width = Class.create();
Object.extend(Object.extend(fx.Width.prototype, fx.Layout.prototype), {	
	increase: function() {
		this.el.style.width = this.now + "px";
	},

	toggle: function(){
		if (this.el.offsetWidth > 0) this.custom(this.el.offsetWidth, 0);
		else this.custom(0, this.iniWidth);
	}
});

//fader
fx.Opacity = Class.create();
fx.Opacity.prototype = Object.extend(new fx.Base(), {
	initialize: function(el, options) {
		this.el = $(el);
		this.now = 1;
		this.increase();
		this.setOptions(options);
	},

	increase: function() {
		if (this.now == 1 && (/Firefox/.test(navigator.userAgent))) this.now = 0.9999;
		this.setOpacity(this.now);
	},
	
	setOpacity: function(opacity) {
		if (opacity == 0 && this.el.style.visibility != "hidden") this.el.style.visibility = "hidden";
		else if (this.el.style.visibility != "visible") this.el.style.visibility = "visible";
		if (window.ActiveXObject) this.el.style.filter = "alpha(opacity=" + opacity*100 + ")";
		this.el.style.opacity = opacity;
	},

	toggle: function() {
		if (this.now > 0) this.custom(1, 0);
		else this.custom(0, 1);
	}
});

//transitions
fx.sinoidal = function(pos){
	return ((-Math.cos(pos*Math.PI)/2) + 0.5);
	//this transition is from script.aculo.us
}
fx.linear = function(pos){
	return pos;
}
fx.cubic = function(pos){
	return Math.pow(pos, 3);
}
fx.circ = function(pos){
	return Math.sqrt(pos);
}


//	Source edited from Lightbox v2.02
//	by Lokesh Dhakar - http://www.huddletogether.com

var fileLoadingImage = "./system/loading.gif";		
var fileBottomNavCloseImage = "./system/closelabel.gif";
var resizeSpeed = 6;	// controls the speed of the image resizing (1=slowest and 10=fastest)
var borderSize = 10;	//if you adjust the padding in the CSS, you will need to update this variable

var imageArray = new Array;
var activeImage;

if(resizeSpeed > 10){ resizeSpeed = 10;}
if(resizeSpeed < 1){ resizeSpeed = 1;}
resizeDuration = (11 - resizeSpeed) * 100;

Object.extend(Element, {
	hide: function() {
		for (var i = 0; i < arguments.length; i++) {
			var element = $(arguments[i]);
			element.style.display = 'none';
		}
	},
	show: function() {
		for (var i = 0; i < arguments.length; i++) {
			var element = $(arguments[i]);
			try{
				element.style.display = '';
			}catch(e){
				//alert('SHOW ERROR');
				//alert(objToString(element));
				//alert(e);
			}
		}
	},
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
		element.style.width = w +"px";
	},
	getHeight: function(element) {
		element = $(element);
		return element.offsetHeight;
	},
	setHeight: function(element,h) {
   		element = $(element);
		element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
		element.style.top = t +"px";
	},
	setSrc: function(element,src) {
		element = $(element);
		element.src = src; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});




var Lightbox = Class.create();
					
Lightbox.prototype = {

	initialize: function() {
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		this.LBID = (typeof(LBID) != 'undefined')? LBID: 0;

		// YOU ALWAYS GRAB THE SURFACE VIEW OF THE LANDING PAGE...
		// YOU CAN'T GRAB THE SURFACE VIEW OTHERWISE YOU LOSE THE ORIENTATION WITH THE 
		// YOU ONLY REINJECT NEW PAGE NODES IF WE GO DEEP INTO THE WINDOW STRUCTURES...

		// THIS IS TOTALLY WRONG...

		
		if(typeof(JSN) == 'object'){
			this.loadJSN = true;
		}else{
			// loop through all anchor tags
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				var relAttribute = String(anchor.getAttribute('rel')).toLowerCase();
				// use the string.match() method to catch 'lightbox' references in the rel attribute
				if (anchor.getAttribute('rev')){
					if(relAttribute.match('lightbox')){
						anchor.onclick = function () {myLightbox.start(this,'src'); return false;}
					}else if(relAttribute.match('jumpbox')){
						//anchor.onclick = function () {myLightbox.start(this,'href'); return false;}
					}
				}
			}
		}

		var objBody = document.getElementsByTagName("body").item(0);

		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.onclick = function() { myLightbox.end(); return false; }
		objBody.appendChild(objOverlay);

		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objBody.appendChild(objLightbox);

		var objLightboxFloater = document.createElement("div");
		objLightboxFloater.setAttribute('id','lightboxFloater');
		objLightbox.appendChild(objLightboxFloater);

		var objOuterImageContainer = document.createElement("div");
		objOuterImageContainer.setAttribute('id','outerImageContainer');
		objLightboxFloater.appendChild(objOuterImageContainer);

		var objImageContainer = document.createElement("div");
		objImageContainer.setAttribute('id','imageContainer');
		objOuterImageContainer.appendChild(objImageContainer);

		var descRightContainer = document.createElement("div");
		descRightContainer.setAttribute('id','descRightContainer');
		objImageContainer.appendChild(descRightContainer);

		var objPageContainer = document.createElement("div");
		objPageContainer.setAttribute('id','pageContainer');
		objOuterImageContainer.appendChild(objPageContainer);		

		var objPageContainerSlug = document.createElement("div");
		objPageContainerSlug.setAttribute('id','pageContainerSlug');
		objPageContainer.appendChild(objPageContainerSlug);			

		var objLightboxImage = document.createElement("img");
		objLightboxImage.setAttribute('id','lightboxImage');
		objImageContainer.appendChild(objLightboxImage);
	
		var objHoverNav = document.createElement("div");
		objHoverNav.setAttribute('id','hoverNav');
		objImageContainer.appendChild(objHoverNav);
	
		var objPrevLink = document.createElement("a");
		objPrevLink.setAttribute('id','prevLink');
		objPrevLink.setAttribute('href','#');
		objHoverNav.appendChild(objPrevLink);
		
		var objNextLink = document.createElement("a");
		objNextLink.setAttribute('id','nextLink');
		objNextLink.setAttribute('href','#');
		objHoverNav.appendChild(objNextLink);
	
		var objLoading = document.createElement("div");
		objLoading.setAttribute('id','loading');
		objOuterImageContainer.appendChild(objLoading);
	
		var objLoadingLink = document.createElement("a");
		objLoadingLink.setAttribute('id','loadingLink');
		objLoadingLink.setAttribute('href','#');
		objLoadingLink.onclick = function() { myLightbox.end(); return false; }
		objLoading.appendChild(objLoadingLink);
	
		var objLoadingImage = document.createElement("img");
		objLoadingImage.setAttribute('src', fileLoadingImage);
		objLoadingLink.appendChild(objLoadingImage);

		var objImageDataContainer = document.createElement("div");
		objImageDataContainer.setAttribute('id','imageDataContainer');
		objImageDataContainer.className = 'clearfix';
		objLightboxFloater.appendChild(objImageDataContainer);

		var objImageData = document.createElement("div");
		objImageData.setAttribute('id','imageData');
		objImageDataContainer.appendChild(objImageData);
	
		var objImageDetails = document.createElement("div");
		objImageDetails.setAttribute('id','imageDetails');
		objImageData.appendChild(objImageDetails);
	
		this.objImageDetails = objImageDetails;
	
		var objCaption = document.createElement("span");
		objCaption.setAttribute('id','caption');
		objImageDetails.appendChild(objCaption);

		this.objCaption = objCaption;
	
		var objNumberDisplay = document.createElement("span");
		objNumberDisplay.setAttribute('id','numberDisplay');
		objImageDetails.appendChild(objNumberDisplay);
		
		var objBottomNav = document.createElement("div");
		objBottomNav.setAttribute('id','bottomNav');
		objImageData.appendChild(objBottomNav);
	
		var objBottomNavCloseLink = document.createElement("a");
		objBottomNavCloseLink.setAttribute('id','bottomNavClose');
		objBottomNavCloseLink.setAttribute('href','#');
		objBottomNavCloseLink.onclick = function() { myLightbox.end(); return false; }
		objBottomNav.appendChild(objBottomNavCloseLink);
		
		overlayEffect = new fx.Opacity(objOverlay, { duration: 300 });
		overlayEffect.hide();
		
		overlayEffectPage	= new fx.Opacity(objPageContainer, { duration: 900 });
		overlayEffectPage.hide();

		imageDescEffect = new fx.Opacity(descRightContainer, { duration: 350, onComplete: function() {}});
		imageDescEffect.hide();
		
		imageEffect = new fx.Opacity(objLightboxImage, { duration: 350, onComplete: function() { imageDetailsEffect.custom(0,1); }});
		imageEffect.hide();
		
		imageDetailsEffect = new fx.Opacity('imageDataContainer', { duration: 400, onComplete: function() { navEffect.custom(0,1); }}); 
		imageDetailsEffect.hide();
		
		navEffect = new fx.Opacity('hoverNav', { duration: 100 });
		navEffect.hide();
	},

	// this entire function has to be reworked to acomodate normal div elements...
	// where are we getting our dimensions from???
	// essentially... everything passed into this box will mix the lightbox initialization phase...
	// so...
	// we need special hooks... either that or we need to reinitialize the lightbox on each load and we cn do that through the requestController...
	// we will know our next previous due to the initialization process... so there will be no problems there...


	start: function(imageLink,version,c,p) {	

		if(myLightbox.is_open){
			getPane(imageLink,1,c,p);
			return;
		}

		hideSelectBoxes();
		var arrayPageSize = getPageSize();
		Element.setHeight('overlay', arrayPageSize[1]);
		overlayEffectPage.custom(0,0);
		overlayEffectPage.transition = 0;
		overlayEffect.custom(0,0.8);
		imageArray = [];
		imageNum = 0;		

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');
		if(this.loadJSN){
			Element.hide('imageContainer');
			// find the node... we need the variables passed through onclick to reference the categories...
			imageArray.push(new Array(imageLink.getAttribute('rev'), imageLink.getAttribute('title') , 'href' , c , p));		
		}else if((imageLink.getAttribute('rel') == 'lightbox')){
			imageArray.push(new Array(imageLink.getAttribute('rev'), imageLink.getAttribute('title')));			
		}else{
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				if (anchor.getAttribute('rev') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
					imageArray.push(new Array(anchor.getAttribute('rev'), anchor.getAttribute('title'), version));
				}
			}
			for(i = 1; i < imageArray.length; i++){
				if(imageArray[i][0] == imageArray[i-1][0]){
					imageArray.splice(i,1);
				}
			}
			while(imageArray[imageNum][0] != imageLink.getAttribute('rev')) { imageNum++;}
		}

		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

		//Element.setTop('lightbox', lightboxTop); // -------------------------------------------------------------------------------- SET TOP !!!!!!!!!!!!!!
		Element.show('lightbox');

		// maybe you've gone too deep... I mean... why are you cahnging the image if it's already loaded...
		this.changeImage(imageNum);
	},


	hideElements: function(){
		overlayEffectPage.custom(1,0);
		overlayEffectPage.transition = 1;
	},


	changeImage: function(imageNum) {
		activeImage = imageNum;	// update global var
		Element.hide('lightboxImage');
		imageDescEffect.hide();
		
		Element.show('loading');
		imageDetailsEffect.hide();
		imageEffect.hide();
		navEffect.hide();
		Element.hide('prevLink');
		Element.hide('nextLink');
		Element.hide('numberDisplay');

		mode = imageArray[activeImage][2];

		if(mode == 'href'){
			if(PANES.i != 'home'){ // this is set to the PAGE=HOME variable...
				hidePane(PANES.i);				
			}
			myLightbox.resizeImageContainer(600,400,imageArray[activeImage][2]);
			getPane(imageArray[activeImage][0],1,imageArray[activeImage][3],imageArray[activeImage][4]);
		}else{
			imgPreloader = new Image();
			imgPreloader.onload=function(){
				Element.setSrc('lightboxImage', imageArray[activeImage][0]);
				resizeMode = 0;
				if(typeof(LBPR) != 'undefined'){
					resizeMode = LBPR;
				}
				
				// IMAGE RESIZING MODES...
				var spaceCaptionBottom = (this.LBID == 1 || this.LBID == 2)? 350: 150;
				var maxHeightWin = Window.getHeight() - spaceCaptionBottom;
				var maxHeightImg = imgPreloader.height;
				
				if(maxHeightImg > maxHeightWin){
					framedHeight = maxHeightWin;
					var ratio = framedHeight / maxHeightImg;
					framedWidth = (ratio < 1)? parseInt(imgPreloader.width * ratio): imgPreloader.width;
					if(!resizeMode){						
						Element.setHeight('lightboxImage', framedHeight);
						Element.setWidth('lightboxImage', framedWidth);
					}
				}else{
					framedHeight = maxHeightImg;
					framedWidth = imgPreloader.width;
					if(!resizeMode){
						Element.setHeight('lightboxImage', framedHeight);
						Element.setWidth('lightboxImage', framedWidth);
					}
				}

				myLightbox.resizeImageContainer(framedWidth, framedHeight);
			}
			imgPreloader.src = imageArray[activeImage][0];
		}
	},

	resizeImageContainer: function( imgWidth, imgHeight, page) {

		this.resizeImageContainerFLAG = 1;
		this.wCur = Element.getWidth('outerImageContainer');
		this.hCur = Element.getHeight('outerImageContainer');
		var spaceCaptionRight = (this.LBID == 3 || this.LBID == 4)? 250: 0;

		wDiff = (this.wCur - borderSize * 2) - imgWidth;
		hDiff = (this.hCur - borderSize * 2) - imgHeight;
		reHeight = new fx.Height('outerImageContainer', { duration: resizeDuration });
		reHeight.custom(Element.getHeight('outerImageContainer'),imgHeight+(borderSize*2)); 
		reWidth = new fx.Width('outerImageContainer', { duration: resizeDuration, onComplete: function() { imageEffect.custom(0,1);imageDescEffect.custom(0,1);myLightbox.resizeImageContainerFLAG =0; }});
		reWidth.custom(Element.getWidth('outerImageContainer'),imgWidth+(borderSize*2)+spaceCaptionRight);

		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf("MSIE")!=-1){ dopause(250); } else { dopause(100);} 
		}

		if(typeof(page) !== 'undefined' && page == 'href'){
			Element.setHeight('pageContainer', imgHeight);
		}

		Element.setHeight('prevLink', imgHeight);
		Element.setHeight('nextLink', imgHeight);		
		Element.setWidth( 'imageDataContainer', imgWidth + (borderSize * 2) + spaceCaptionRight);
		Element.setWidth( 'hoverNav', imgWidth + (borderSize * 2));

		if(typeof(page) !== 'undefined'){
			//this.showPage();
		}else{
			this.showImage();
		}
	},

	// sometimes we are firing the lightbox before it has a chance to finsih it's transition.... we need safty locks to block repetitive calls...

	showPage: function(){
		myLightbox.is_open = true;
		
		if(!myLightbox.resizeImageContainerFLAG){
			if(PANES.hook == 1 && overlayEffectPage.transition == 1){
				//alert('transition is active...');
				overlayEffectPage.transition = 0;
				setTimeout("myLightbox.showPage();",1000);
				return;
			}
			Element.hide('loading');
			Element.show('lightboxImage');
			Element.show('caption');
			overlayEffectPage.custom(0,1);
			PANES[PANES.i].style.display = 'block';
			PANES[PANES.i].style.overflow = 'hidden';
			PANES['containers'][1].scrollTop = '0';
		}else{
			setTimeout("myLightbox.showPage();",1000);
			return;
		}
		var clone = PANES[PANES.i].cloneNode(true);
		PANES['containers'][PANES.hook].replaceChild(clone,PANES['containers'][PANES.hook].firstChild);
		PANES[PANES.i].style.display = 'none';
		if(this.loadJSN){
			var c = PANES.c;
			this.objCaption.innerHTML = '';
			if(typeof(JSN[PANES.c]) !== 'undefined'){
				var l = JSN[PANES.c].length;			
				for(x in JSN[c]){	
					var anchor = document.createElement("A");
					anchor.setAttribute('href',JST[x][1]);
					var sect = ('page_id='+x).toString();		
					anchor.setAttribute('rev',sect);
					anchor.setAttribute('rel','jumpbox[catalogue]');				
					anchor.onclick = function(){getPane(this.rev,1,c,x);return false;}				
					anchor.innerHTML = JST[x][0];
					this.objCaption.appendChild(anchor);
				}
			}else{ // happens with a single page node...
				//alert('defined');
			}
		}
	},

	updatePageDetails: function(){

	},
	
	showImage: function(){
		Element.hide('loading');
		Element.show('lightboxImage');
		myLightbox.updateDetails(); 
		this.preloadNeighborImages();
	},

	updateDetails: function() {

		Element.show('caption');
		var str = '';
		if(!this.LBID){
			str += imageArray[activeImage][1];
			Element.setInnerHTML( 'caption', str);
			Element.hide('descRightContainer');	
		}else if(this.LBID == 1 || this.LBID == 2){
			str += imageArray[activeImage][1];
			try{str += '<br>' + LBD[imageArray[activeImage][0]].replace(/&quot;/g, '"');}catch(e){}
			Element.setInnerHTML( 'caption', str);
			Element.hide('descRightContainer');	
		}else if(this.LBID == 3 || this.LBID == 4){
			Element.setInnerHTML( 'caption', str);
			str += imageArray[activeImage][1];
			try{str += '<br><br>' + LBD[imageArray[activeImage][0]].replace(/&quot;/g, '"');}catch(e){}		
			Element.setWidth('descRightContainer',225);
			Element.setInnerHTML( 'descRightContainer', str);
			Element.show('descRightContainer');	
		}
		
		if(imageArray.length > 1){
			Element.show('numberDisplay');
			Element.setInnerHTML( 'numberDisplay', "Image " + eval(activeImage + 1) + " of " + imageArray.length);
		}

		myLightbox.updateNav();
	},

	updateNav: function() {

		if(activeImage != 0){
			Element.show('prevLink');
			document.getElementById('prevLink').onclick = function() {
				myLightbox.changeImage(activeImage - 1); return false;
			}
		}

		if(activeImage != (imageArray.length - 1)){
			Element.show('nextLink');
			document.getElementById('nextLink').onclick = function() {
				myLightbox.changeImage(activeImage + 1); return false;
			}
		}
		
		//this.enableKeyboardNav();
	},

	EnableKeyboardNav: function() {
		document.onkeydown = this.keyboardAction; 
	},

	disableKeyboardNav: function() {
		document.onkeydown = '';
	},

	keyboardAction: function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}

		key = String.fromCharCode(keycode).toLowerCase();
		
		if((key == 'x') || (key == 'o') || (key == 'c')){	// close lightbox
			myLightbox.end();
		} else if(key == 'p'){	// display previous image
			if(activeImage != 0){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage - 1);
			}
		} else if(key == 'n'){	// display next image
			if(activeImage != (imageArray.length - 1)){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage + 1);
			}
		}
	},

	preloadNeighborImages: function(){

		if((imageArray.length - 1) > activeImage){
			preloadNextImage = new Image();
			preloadNextImage.src = imageArray[activeImage + 1][0];
		}
		if(activeImage > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = imageArray[activeImage - 1][0];
		}
	
	},

	end: function() {
		myLightbox.is_open = false;
		this.disableKeyboardNav();
		Element.hide('lightbox');
		Element.hide('caption');
		imageDescEffect.toggle();
		imageEffect.toggle();
		overlayEffect.custom(0.8,0);
		overlayEffectPage.custom(1,0);
		showSelectBoxes();
	}
}

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;
}

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;
		yScroll = document.body.clientHeight;

	}
	
	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;
	}	
	//alert('yScroll'+yScroll);
	//alert('windowHeight'+windowHeight);
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}


	//alert('pageHeight'+pageHeight);

	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

function listenKey () {	document.onkeypress = getKey; }

// LOOKS LIKE IE WILL NOT SET THE SELECTED OPTION IF THE SELECT BOX IS NOT ON SCREEN>>>> A CARRY OVER FROM TH LAME MISTAKE BACK IN IE 6... ( STILL NOT FIXED EITHER )

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	var l = selects.length;
	for(i = 0; i != selects.length; i++){
		try{selects[i].style.visibility = "visible";}catch(e){break;}
	}
}

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}


function dopause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}


function initLightbox() { myLightbox = new Lightbox(); }