var Lightbox=Class.create();Lightbox.prototype={imageArray:[],activeImage:undefined,options:undefined,initialize:function(N){this.options=N;this.imageArray=this.options.gallery_json;this.keyboardAction=this.keyboardAction.bindAsEventListener(this);if(this.options.resizeSpeed>10){this.options.resizeSpeed=10}if(this.options.resizeSpeed<1){this.options.resizeSpeed=1}this.resizeDuration=this.options.animate?((11-this.options.resizeSpeed)*0.15):0;this.overlayDuration=this.options.animate?0.2:0;var L=(this.options.animate?250:1)+"px";var M=$$("body")[0];M.appendChild(new Element("div",{id:"overlay"}));var E=new Element("div",{id:"hoverNav"});E.appendChild(new Element("a",{id:"prevLink",href:"#"}));E.appendChild(new Element("a",{id:"nextLink",href:"#"}));var D=new Element("a",{id:"loadingLink",href:"#"});D.appendChild(new Element("img",{src:this.options.fileLoadingImage}));var G=new Element("div",{id:"loading"});G.appendChild(D);var C=new Element("div",{id:"imageContainer"});C.appendChild(new Element("img",{id:"lightboxImage"}));C.appendChild(E);C.appendChild(G);var F=new Element("div",{id:"outerImageContainer"});F.appendChild(C);var I=new Element("div",{id:"imageDetails"});I.appendChild(new Element("span",{id:"caption"}));I.appendChild(new Element("span",{id:"numberDisplay"}));var J=new Element("a",{id:"bottomNavClose",href:"#"});J.appendChild(new Element("img",{src:this.options.fileBottomNavCloseImage}));var B=new Element("div",{id:"bottomNav"});B.appendChild(J);var A=new Element("div",{id:"imageData"});A.appendChild(I);A.appendChild(B);var K=new Element("div",{id:"imageDataContainer"});K.appendChild(A);var H=new Element("div",{id:"lightbox"});H.appendChild(F);H.appendChild(K);M.appendChild(H);$("overlay").hide().observe("click",(function(){this.end()}).bind(this));$("lightbox").hide().observe("click",(function(O){if(O.element().id=="lightbox"){this.end()}}).bind(this));$("outerImageContainer").setStyle({width:L,height:L});this.prevEventListener=(function(O){O.stop();this.changeImage(this.activeImage-1)}).bindAsEventListener(this);$("prevLink").observe("click",this.prevEventListener);this.nextEventListener=(function(O){O.stop();this.changeImage(this.activeImage+1)}).bindAsEventListener(this);$("nextLink").observe("click",this.nextEventListener);$("loadingLink").observe("click",(function(O){O.stop();this.end()}).bind(this));$("bottomNavClose").observe("click",(function(O){O.stop();this.end()}).bind(this))},start:function(D){$$("select","object","embed").invoke("setStyle","visibility:hidden");var C=this.getPageSize();$("overlay").setStyle({height:C[1]+"px"});new Effect.Appear($("overlay"),{duration:this.overlayDuration,from:0,to:this.options.overlayOpacity});var A=document.viewport.getScrollOffsets();var F=A[1]+(document.viewport.getHeight()/15);var E=A[0];$("lightbox").setStyle({top:F+"px",left:E+"px"}).show();var B=0;while(this.imageArray[B][3]!=D||B>this.imageArray.length-1){B++}this.changeImage(B);return false},changeImage:function(B){this.activeImage=B;if(this.options.animate){$("loading").show()}$("lightboxImage","hoverNav","prevLink","nextLink","numberDisplay").invoke("hide");$("imageDataContainer").setStyle({opacity:0.0001});var A=new Image();A.onload=(function(){$("lightboxImage").src=this.imageArray[this.activeImage][0];this.resizeImageContainer(A.width,A.height)}).bind(this);A.src=this.imageArray[this.activeImage][0]},resizeImageContainer:function(E,F){var H=$("outerImageContainer").getWidth();var C=$("outerImageContainer").getHeight();var G=(E+this.options.borderSize*2);var J=(F+this.options.borderSize*2);var K=(G/H)*100;var B=(J/C)*100;var I=H-G;var A=C-J;if(A!=0){new Effect.Scale($("outerImageContainer"),B,{scaleX:false,duration:this.resizeDuration,queue:"front"})}if(I!=0){new Effect.Scale($("outerImageContainer"),K,{scaleY:false,duration:this.resizeDuration,delay:this.resizeDuration})}var D=0;if((A==0)&&(I==0)){D=100;if(Prototype.Browser.IE){D=250}}(function(){$("prevLink","nextLink").invoke("setStyle","height:"+F+"px");$("imageDataContainer").setStyle({width:G+"px"});this.showImage()}).bind(this).delay(D/1000)},showImage:function(){$("loading").hide();new Effect.Appear($("lightboxImage"),{duration:this.resizeDuration,queue:"end",afterFinish:(function(){this.updateDetails()}).bind(this)});this.preloadNeighborImages()},updateDetails:function(){if(this.imageArray[this.activeImage][2]!=""){$("caption").update(this.imageArray[this.activeImage][2]).show()}else{$("caption").update(this.imageArray[this.activeImage][1]).show()}if(this.imageArray.length>1){$("numberDisplay").update(this.options.labelImage+" "+(this.activeImage+1)+" "+this.options.labelOf+"  "+this.imageArray.length).show()}new Effect.Parallel([new Effect.SlideDown($("imageDataContainer"),{sync:true,duration:this.resizeDuration,from:0,to:1}),new Effect.Appear($("imageDataContainer"),{sync:true,duration:this.resizeDuration})],{duration:this.resizeDuration,afterFinish:(function(){var A=this.getPageSize();$("overlay").setStyle({height:A[1]+"px"});this.updateNav()}).bind(this)})},updateNav:function(){$("hoverNav").show();if(this.activeImage>0){$("prevLink").show()}if(this.activeImage<(this.imageArray.length-1)){$("nextLink").show()}this.enableKeyboardNav()},enableKeyboardNav:function(){document.observe("keydown",this.keyboardAction)},disableKeyboardNav:function(){document.stopObserving("keydown",this.keyboardAction)},keyboardAction:function(D){var A=D.keyCode;var B;if(D.DOM_VK_ESCAPE){B=D.DOM_VK_ESCAPE}else{B=27}var C=String.fromCharCode(A).toLowerCase();if(C.match(/x|o|c/)||(A==B)){this.end()}else{if((C=="p")||(A==37)){if(this.activeImage!=0){this.disableKeyboardNav();this.changeImage(this.activeImage-1)}}else{if((C=="n")||(A==39)){if(this.activeImage!=(this.imageArray.length-1)){this.disableKeyboardNav();this.changeImage(this.activeImage+1)}}}}},preloadNeighborImages:function(){var A,B;if(this.imageArray.length>this.activeImage+1){A=new Image();A.src=this.imageArray[this.activeImage+1][0]}if(this.activeImage>0){B=new Image();B.src=this.imageArray[this.activeImage-1][0]}},end:function(){this.disableKeyboardNav();$("lightbox").hide();new Effect.Fade($("overlay"),{duration:this.overlayDuration});$$("select","object","embed").invoke("setStyle","visibility:visible");if(this.options.startPage!=this.imageArray[this.activeImage][4]){location.href=this.options.returnURL+"page="+this.imageArray[this.activeImage][4]}},getPageSize:function(){var C,A;if(window.innerHeight&&window.scrollMaxY){C=window.innerWidth+window.scrollMaxX;A=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){C=document.body.scrollWidth;A=document.body.scrollHeight}else{C=document.body.offsetWidth;A=document.body.offsetHeight}}var B,D;if(self.innerHeight){if(document.documentElement.clientWidth){B=document.documentElement.clientWidth}else{B=self.innerWidth}D=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){B=document.documentElement.clientWidth;D=document.documentElement.clientHeight}else{if(document.body){B=document.body.clientWidth;D=document.body.clientHeight}}}if(A<D){pageHeight=D}else{pageHeight=A}if(C<B){pageWidth=C}else{pageWidth=B}return[pageWidth,pageHeight]}};