// -----------------------------------------------------------------------------------

//
//	Configuration
//
var fileLoadingImage        = "/images/ajax-loader-50.gif";		
var overlayOpacity = 0.8;	// controls transparency of shadow overlay
var animate = true;			// toggles resizing animations
var resizeSpeed = 7;		// controls the speed of the image resizing animations (1=slowest and 10=fastest)
var borderSize = 0;		//if you adjust the padding in the CSS, you will need to update this variable
var percent_limit = 0.9;
var overlay_visible = 0;
var bodyObject='';
var z_index=500;
var opened_windows=0;

// -----------------------------------------------------------------------------------

//
//	Global Variables
//
var imageArray = new Array;
var activeImage;

if(animate == true){
	overlayDuration = 0.5;	// shadow fade in/out duration
	if(resizeSpeed > 6){ resizeSpeed = 6;}
	if(resizeSpeed < 1){ resizeSpeed = 1;}
	resizeDuration = (7 - resizeSpeed) * 0.15;
} else { 
	overlayDuration = 0;
	resizeDuration = 0;
}

// -----------------------------------------------------------------------------------

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	getTop: function(element) {
	   	element = $(element);
	   	return element.style.top; 
	},
	getLeft: function(element) {
	   	element = $(element);
	   	return element.style.left; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setLeft: function(element,l) {
	   	element = $(element);
    	element.style.left = l +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// -----------------------------------------------------------------------------------

//
//	Extending built-in Array object
//	- array.removeDuplicates()
//	- array.empty()
//
Array.prototype.removeDuplicates = function () {
    for(i = 0; i < this.length; i++){
        for(j = this.length-1; j>i; j--){        
            if(this[i][0] == this[j][0]){
                this.splice(j,1);
            }
        }
    }
}

// -----------------------------------------------------------------------------------

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

// -----------------------------------------------------------------------------------

//
//	Lightbox Class Declaration
//	- initialize()
//	- start()
//	- changeImage()
//	- resizeImageContainer()
//	- showImage()
//	- updateDetails()
//	- updateNav()
//	- enableKeyboardNav()
//	- disableKeyboardNav()
//	- keyboardNavAction()
//	- end()
//
//	Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
//
var Lightbox = Class.create();

Lightbox.prototype = {
	
	// initialize()
	// Constructor runs on completion of the DOM loading. Calls updateImageList and then
	// the function inserts html at the bottom of the page which is used to display the shadow 
	// overlay and the image container.
	//
	initialize: function() {	
		
		this.updateImageList();

		// Code inserts html at the bottom of the page that looks similar to this:
		//
		//	<div id="overlay"></div>
		//	<div id="lightbox">
		//		<div id="imageDataContainer">
		//			<div id="imageData">
		//				<div id="imageDetails">
		//					<span id="description"></span>
		//				</div>
		//				<div id="bottomNav">
		//					<a href="#" id="bottomNavClose">X</a>
		//				</div>
		//			</div>
		//		</div>
		//		<div id="outerImageContainer">
		//			<div id="imageContainer">
		//				<img id="lightboxImage">
		//				<div id="loading">
		//					<a href="#" id="loadingLink">
		//						<img src="images/loading.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//	</div>


		bodyObject = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { myLightbox.end(); }
		bodyObject.appendChild(objOverlay);
		
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
			if (!e) var e = window.event;
			var clickObj = Event.element(e).id;
			if ( clickObj == 'lightbox') {
//				myLightbox.end();
			}
		};
		bodyObject.appendChild(objLightbox);
				

		var objImageDataContainer = document.createElement("div");
		objImageDataContainer.setAttribute('id','imageDataContainer');
		if (navigator.appVersion.indexOf("MSIE")!=-1)
		{
			//IE
			objImageDataContainer.style.setAttribute('cssText','border:2px #00456f solid;background-color:#00456f;height:25px');
		}
		else 
		{
			//AUTRES
			objImageDataContainer.setAttribute('style','border:2px #00456f solid;background-color:#00456f;height:25px');
		}
		objLightbox.appendChild(objImageDataContainer);


		var objOuterImageContainer = document.createElement("div");
		objOuterImageContainer.setAttribute('id','outerImageContainer');
		objLightbox.appendChild(objOuterImageContainer);

		// When Lightbox starts it will resize itself from 250 by 250 to the current image dimension.
		// If animations are turned off, it will be hidden as to prevent a flicker of a
		// white 250 by 250 box.
		if(animate){
			Element.setWidth('outerImageContainer', 250);
			Element.setHeight('outerImageContainer', 250);			
		} else {
			Element.setWidth('outerImageContainer', 1);
			Element.setHeight('outerImageContainer', 1);			
		}

		var objImageContainer = document.createElement("div");
		objImageContainer.setAttribute('id','imageContainer');
		objOuterImageContainer.appendChild(objImageContainer);
	
		var objLightboxImage = document.createElement("img");
		objLightboxImage.setAttribute('id','lightboxImage');
		objImageContainer.appendChild(objLightboxImage);
			
		var objLoading = document.createElement("div");
		objLoading.setAttribute('id','loading');
		objOverlay.appendChild(objLoading);
	
		var objLoadingImage = document.createElement("img");
		objLoadingImage.setAttribute('src', fileLoadingImage);
		objLoading.appendChild(objLoadingImage);

		var objImageData = document.createElement("div");
		objImageData.setAttribute('id','imageData');	
		if (navigator.appVersion.indexOf("MSIE")!=-1)
		{
			//IE
			objImageData.style.setAttribute('cssText','text-align:right;');
		}
		else 
		{
			//AUTRES
			objImageData.setAttribute('style','text-align:right;');
		}
		objImageDataContainer.appendChild(objImageData);

		var objImageDetails = document.createElement("div");
		objImageDetails.setAttribute('id','imageDetails');
		objImageData.appendChild(objImageDetails);


		var objBottomNav = document.createElement("div");
		objBottomNav.setAttribute('id','bottomNav');
		if (navigator.appVersion.indexOf("MSIE")!=-1)
		{
			//IE
			objBottomNav.style.setAttribute('cssText','float:right;');
		}
		else 
		{
			//AUTRES
			objBottomNav.setAttribute('style','float:right;');
		}
		objImageData.appendChild(objBottomNav);
	
		var objBottomNavCloseLink = document.createElement("a");
		objBottomNavCloseLink.setAttribute('id','bottomNavClose');
		objBottomNavCloseLink.setAttribute('href','#');
		objBottomNavCloseLink.setAttribute('class','fermer');
		objBottomNavCloseLink.setAttribute('className','fermer');

		objBottomNavCloseLink.onclick = function() { myLightbox.end(); return false; }
		objBottomNav.appendChild(objBottomNavCloseLink);

		var objBottomNavCloseImage = document.createTextNode("X");	
		objBottomNavCloseLink.appendChild(objBottomNavCloseImage);

	
		var objDescription = document.createElement("span");
		objDescription.setAttribute('id','description');
		objDescription.setAttribute('class','mini_blanc');
		objDescription.setAttribute('className','mini_blanc');
		objImageDetails.appendChild(objDescription);	
	},


	//
	// updateImageList()
	// Loops through anchor tags looking for 'lightbox' references and applies onclick
	// events to appropriate links. You can rerun after dynamically adding images w/ajax.
	//
	updateImageList: function() {	
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');
		var areas = document.getElementsByTagName('area');

		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var relAttribute = String(anchor.getAttribute('rel'));
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
				anchor.onclick = function () {myLightbox.start(this); return false;}
			}
		}

		// loop through all area tags
		// todo: combine anchor & area tag loops
		for (var i=0; i< areas.length; i++){
			var area = areas[i];
			
			var relAttribute = String(area.getAttribute('rel'));
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (area.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
				area.onclick = function () {myLightbox.start(this); return false;}
			}
		}
	},
	


	  showMask: function() {
		if(overlay_visible==0)
		{
			overlay_visible = 1;
			var arrayPageSize = getPageSize();
			Element.setWidth('overlay', arrayPageSize[0]);
			Element.setHeight('overlay', arrayPageSize[1]);
			Element.show('loading');
		
			new Effect.Appear('overlay', { duration: .3, from: 0.0, to: overlayOpacity, queue: 'front'});
		}
	  },



	 hideMask: function() {
 		if(overlay_visible==1)
		{
			overlay_visible = 0;
			new Effect.Fade('overlay', { duration: .3,queue: 'end'});
		}
	 },
 
 
	openWindow: function (name,type,width,height)
	{
		z_index+=5;
		if (!document.getElementById){ return; }
		if(!document.getElementById(name))
		{
			opened_windows++;
			//La BOX GENERALE A LA FENETRE
			var objbox = document.createElement("div");
			objbox.setAttribute('id',name+'box');
			objbox.setAttribute('class','winbox');
			objbox.setAttribute('className','winbox');
			if (navigator.appVersion.indexOf("MSIE")!=-1)
			{
				//IE
				objbox.style.setAttribute("cssText",'position:absolute;display:none;z-index:'+z_index);
			}
			else 
			{
				//AUTRES
				objbox.setAttribute("style",'position:absolute;display:none;z-index:'+z_index);
			}

			bodyObject.appendChild(objbox);


			//LE OUTER DE LA FENETRE
			var objOuter = document.createElement("div");
			objOuter.setAttribute('id','outer'+name);
			if (navigator.appVersion.indexOf("MSIE")!=-1)
			{
				//IE
				objOuter.style.setAttribute("cssText",'position:absolute;width:'+width+';height:'+height+';z-index:'+z_index);
			}
			else 
			{
				//AUTRES
				objOuter.setAttribute("style",'position:absolute;width:'+width+';height:'+height+';z-index:'+z_index);
			}

			objbox.appendChild(objOuter);


			//LE HEADER DE LA FENETRE
			var objHeader = document.createElement("div");
			objHeader.setAttribute('id','header'+name);

			if (navigator.appVersion.indexOf("MSIE")!=-1)
			{
				//IE
				objHeader.style.setAttribute("cssText",'z-index:'+z_index);
			}
			else 
			{
				//AUTRES
				objHeader.setAttribute("style",'z-index:'+z_index);
			}
			objbox.appendChild(objHeader);


			//LE TITRE DE LA FENETRE
			var objTitle = document.createElement("div");
			objTitle.setAttribute('id','title'+name);
			objTitle.setAttribute('class',"wintitle");
			objTitle.setAttribute('className',"wintitle");
			var w=width-25+1;
			
			if (navigator.appVersion.indexOf("MSIE")!=-1)
			{
				//IE
				objTitle.style.setAttribute("cssText",'position:absolute;width:'+w+'px;height:30px;z-index:'+z_index);
			}
			else 
			{
				//AUTRES
				objTitle.setAttribute("style",'position:absolute;width:'+w+'px;height:30px;z-index:'+z_index);
			}

			
			objHeader.appendChild(objTitle);


			//LE BOUTON FERMER DE LA FENETRE
			var objClose = document.createElement("div");
			objClose.setAttribute('id','close'+name);
			objClose.setAttribute('class',"winclose");
			objClose.setAttribute('className',"winclose");

			if (navigator.appVersion.indexOf("MSIE")!=-1)
			{
				//IE
				objClose.style.setAttribute("cssText",'position:absolute;text-align:center;width:26px;height:30px;z-index:'+z_index);
			}
			else 
			{
				//AUTRES
				objClose.setAttribute("style",'position:absolute;text-align:center;width:26px;height:30px;z-index:'+z_index);
			}
			objHeader.appendChild(objClose);

			var objBottomCloseWindow = document.createElement("a");
			objBottomCloseWindow.setAttribute('href','#');
			objBottomCloseWindow.setAttribute('class','fermer');
			objBottomCloseWindow.setAttribute('className','fermer');
			objBottomCloseWindow.onclick = function() { myLightbox.closeWindow(name); return false; }
			objClose.appendChild(objBottomCloseWindow);

			var objBottomClose = document.createTextNode("X");	
			objBottomCloseWindow.appendChild(objBottomClose);

			if(type!='iframe')
			{
				var obj = document.createElement("div");
				obj.setAttribute('id',name);
				obj.setAttribute('class',"windata");
				obj.setAttribute('className',"windata");

				if (navigator.appVersion.indexOf("MSIE")!=-1)
				{
					//IE
					obj.style.setAttribute("cssText",'width:'+width+'px;height:'+height+'px;z-index:'+z_index);
				}
				else 
				{
					//AUTRES
					obj.setAttribute("style",'width:'+width+'px;height:'+height+'px;z-index:'+z_index);
				}
				objOuter.appendChild(obj);
			}
			else
			{
				var iframe = document.createElement("iframe");
			    iframe.setAttribute("src", "about:blank");
				iframe.setAttribute('id',name);
				iframe.setAttribute('name',name);
				iframe.setAttribute('width',width);
				iframe.setAttribute('height',height);
/*				iframe.setAttribute('class',"windata");
				iframe.setAttribute('className',"windata");*/
				if (navigator.appVersion.indexOf("MSIE")!=-1)
				{
					//IE
					iframe.style.setAttribute("cssText",'border:1px gray solid;');
				}
				else 
				{
					//AUTRES
					iframe.setAttribute("style",'background-color:#FFFFFF;border:1px gray solid;');
				}
				iframe.setAttribute('NORESIZE','');
				iframe.setAttribute('FRAMEBORDER','0');
				iframe.setAttribute('MARGINWIDTH','0');
				iframe.setAttribute('MARGINHEIGHT','0');
				objOuter.appendChild(iframe);
			}

		}
		else
		{
			var w=width-25+1;
			Element.setWidth('title'+name,w);
			Element.setHeight('title'+name,30);
			Element.setWidth('close'+name,26);
			Element.setHeight('close'+name,30);
			Element.setWidth(name,width);
			Element.setHeight(name,height);
			document.getElementById(name).innerHTML='';
			if(document.getElementById(name+'box').style.display=='none')
				opened_windows++;

			document.getElementById(name+'box').style.zIndex=z_index;
			document.getElementById('header'+name).style.zIndex=z_index;
			document.getElementById('outer'+name).style.zIndex=z_index;
			document.getElementById('title'+name).style.zIndex=z_index;
			document.getElementById('close'+name).style.zIndex=z_index;
		}

		this.showMask();
		var zi=z_index-1;
		document.getElementById('overlay').style.zIndex=z_index-1;

	//	alert("Open : "+name+" Mask : "+zi+" Window : "+z_index);


		//Calcul de la position de la fenêtre
		var sizes = getPageSize();
		var scrolls = getPageScroll();

		var top = (scrolls[1] + ( sizes[3] - height ) / 2)+15;
		var left = scrolls[0] + ( sizes[2] - width ) / 2;

		Element.setTop(name+'box', top);
		Element.setLeft(name+'box', left);
		Element.setWidth(name+'box', width);
		Element.setHeight(name+'box', height);

		Element.setWidth('outer'+name, width);
		Element.setHeight('outer'+name, height);

		Element.setTop('title'+name, -30);

		Element.setTop('close'+name, -30);
		Element.setLeft('close'+name, width-24);

		document.getElementById(name).style.display='block';
		document.getElementById(name+'box').style.display='block';
		//new Effect.Appear(name+'box', { duration: .2, queue: 'end'} );
	},


	closeWindow:function(name)
	{
		new Effect.Fade(name+'box', { duration: .1, queue: 'front'} );

		opened_windows--;
		if(overlay_visible==1 && opened_windows==0)
			this.hideMask();

		z_index-=5;
		document.getElementById('overlay').style.zIndex=document.getElementById('overlay').style.zIndex-5;

	//	alert("Close : "+name+" Mask : "+document.getElementById('overlay').style.zIndex);

		bodyObject.removeChild(document.getElementById(name+'box'));
	},


	openURL:function(name,url)
	{
		document.getElementById(name).src=url;
		document.getElementById(name).style.display='block';

	},


	setTitle: function(name,title)
	{
		document.getElementById('title'+name).innerHTML=title;
	},

	
	//
	//	start()
	//	Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
	//
	start: function(imageLink) {	

		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		if(overlay_visible == 0 )
		{
			Element.setWidth('overlay', arrayPageSize[0]);
			Element.setHeight('overlay', arrayPageSize[1]);
			overlay_visible = 1;
			new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: overlayOpacity });
		}

		imageArray = [];
		imageNum = 0;		

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName( imageLink.tagName);

		// if image is NOT part of a set..
		if((imageLink.getAttribute('rel') == 'lightbox')){
			// add single image to imageArray
			imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title')));			
		} else {
		// if image is part of a set..

			// loop through anchors, find other images in set, and add them to imageArray
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
					imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title')));
				}
			}
			imageArray.removeDuplicates();
			while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
		}

		// calculate top and left offset for the lightbox 
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10) - 20;
		var lightboxLeft = arrayPageScroll[0];
		
		Element.show('lightbox');
		
		this.changeImage(imageNum);
	},



	show: function(imagePath,imageTitle) {	
		Element.setInnerHTML('description',imageTitle);

		imageArray = [];
		imageNum = 0;		

		imageArray.push(new Array(imagePath, imageTitle));
		
		Element.show('lightbox');
		
		this.changeImage(imageNum);
	},

	//
	//	changeImage()
	//	Hide most elements and preload image in preparation for resizing image container.
	//
	changeImage: function(imageNum) {	
		
		activeImage = imageNum;	// update global var

		// hide elements during transition
		if(animate){ Element.show('loading');}
		Element.hide('lightboxImage');
		Element.hide('imageDataContainer');

		
		imgPreloader = new Image();
		
		// once image is preloaded, resize image container
		imgPreloader.onload=function(){
			var sizes = getPageSize();
			var scrolls = getPageScroll();
			Element.setSrc('lightboxImage', imageArray[activeImage][0]);

			var limit_width = sizes[2] * percent_limit;
			var limit_height = sizes[3] * percent_limit - 10;
			
			var width = imgPreloader.width;
			var height = imgPreloader.height;


			if( width > limit_width )
			{
				var ratio = limit_width / width;
				width = limit_width;
				height = height * ratio;
			}

			if( height > limit_height )
			{
				var ratio = limit_height / height;
				height = limit_height;
				width = width * ratio;
			}

			Element.setWidth('lightboxImage', width);
			Element.setHeight('lightboxImage', height);

			var top = scrolls[1] + ( sizes[3] - height ) / 2;

			Element.setTop('lightbox', top);


			myLightbox.resizeImageContainer(width, height);
			
			imgPreloader.onload=function(){};	//	clear onLoad, IE behaves irratically with animated gifs otherwise 
		}
		imgPreloader.src = imageArray[activeImage][0];
	},

	//
	//	resizeImageContainer()
	//
	resizeImageContainer: function( imgWidth, imgHeight) {

		// get curren width and height
		this.widthCurrent = Element.getWidth('outerImageContainer');
		this.heightCurrent = Element.getHeight('outerImageContainer');

		// get new width and height
		var widthNew = (imgWidth  + (borderSize * 2));
		var heightNew = (imgHeight  + (borderSize * 2));

		// scalars based on change from old to new
		this.xScale = ( widthNew / this.widthCurrent) * 100;
		this.yScale = ( heightNew / this.heightCurrent) * 100;

		// calculate size difference between new and old image, and resize if necessary
		wDiff = this.widthCurrent - widthNew;
		hDiff = this.heightCurrent - heightNew;

		if(!( hDiff == 0)){ new Effect.Scale('outerImageContainer', this.yScale, {scaleX: false, duration: resizeDuration, queue: 'front'}); }
		if(!( wDiff == 0)){ new Effect.Scale('outerImageContainer', this.xScale, {scaleY: false, delay: resizeDuration, duration: resizeDuration}); }

		// if new and old image are same size and no scaling transition is necessary, 
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } else { pause(100);} 
		}

		Element.setWidth( 'imageDataContainer', widthNew);
		Element.setWidth( 'imageData', widthNew-20);

		this.showImage();
	},
	
	//
	//	showImage()
	//	Display image and begin preloading neighbors.
	//
	showImage: function(){
		if(opened_windows==0)
			this.hideMask();
		new Effect.Appear('lightboxImage', { duration: resizeDuration, queue: 'end', afterFinish: function(){	myLightbox.updateDetails(); } });
	},

	//
	//	updateDetails()
	//	Display  image number, and bottom nav.
	//
	updateDetails: function() {		

		new Effect.Parallel(
			[ new Effect.SlideDown( 'imageDataContainer', { sync: true, duration: resizeDuration, from: 0.0, to: 1.0 }), 
			  new Effect.Appear('imageDataContainer', { sync: true, duration: resizeDuration }) ], 
			{ duration: resizeDuration, afterFinish: function() {
				// update overlay size and update nav
				var arrayPageSize = getPageSize();
				Element.setHeight('overlay', arrayPageSize[1]);
				}
			} 
		);
	},

	//
	//	end()
	//
	end: function() {
		Element.hide('lightbox');
	}
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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 = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// 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'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	
// ---------------------------------------------------

function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}


// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Help from Ran Bar-On [ran2103@gmail.com]
//

function pause(ms){
	var date = new Date();
	curDate = null;
	do{var curDate = new Date();}
	while( curDate - date < ms);
}
/*
function pause(numberMillis) {
	var curently = new Date().getTime() + sender;
	while (new Date().getTime();	
}
*/
// ---------------------------------------------------



function initLightbox() 
{ 
		myLightbox = new Lightbox(); 
}
//Event.observe(window, 'load', initLightbox, false);
