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]}};