LightboxOptions=Object.extend({fileLoadingImage:"img/item/loading.gif",fileBottomNavCloseImage:"img/item/close.gif",overlayOpacity:0.5,animate:true,resizeSpeed:9,borderSize:10,labelImage:"Image",labelOf:"sur"},window.LightboxOptions||{});var Lightbox=Class.create();
Lightbox.prototype={imageArray:[],activeImage:undefined,initialize:function(){this.updateImageList();this.keyboardAction=this.keyboardAction.bindAsEventListener(this);if(LightboxOptions.resizeSpeed>10)LightboxOptions.resizeSpeed=10;if(LightboxOptions.resizeSpeed<1)LightboxOptions.resizeSpeed=1;this.resizeDuration=LightboxOptions.animate?(11-LightboxOptions.resizeSpeed)*0.15:0;this.overlayDuration=LightboxOptions.animate?0.2:0;var a=(LightboxOptions.animate?250:1)+"px",b=$$("body")[0];b.appendChild(Builder.node("div",
{id:"overlay"}));b.appendChild(Builder.node("div",{id:"lightbox"},[Builder.node("div",{id:"outerImageContainer"},Builder.node("div",{id:"imageContainer"},[Builder.node("img",{id:"lightboxImage"}),Builder.node("div",{id:"hoverNav"},[Builder.node("a",{id:"prevLink",href:"#"}),Builder.node("a",{id:"nextLink",href:"#"})]),Builder.node("div",{id:"loading"},Builder.node("a",{id:"loadingLink",href:"#"},Builder.node("img",{src:LightboxOptions.fileLoadingImage})))])),Builder.node("div",{id:"imageDataContainer"},
Builder.node("div",{id:"imageData"},[Builder.node("div",{id:"imageDetails"},[Builder.node("span",{id:"numberDisplay"})]),Builder.node("div",{id:"bottomNav"},Builder.node("a",{id:"bottomNavClose",href:"#"},Builder.node("img",{src:LightboxOptions.fileBottomNavCloseImage})))]))]));$("overlay").hide().observe("click",function(){this.end()}.bind(this));$("lightbox").hide().observe("click",function(c){c.element().id=="lightbox"&&this.end()}.bind(this));$("outerImageContainer").setStyle({width:a,height:a});
$("prevLink").observe("click",function(c){c.stop();this.changeImage(this.activeImage-1)}.bindAsEventListener(this));$("nextLink").observe("click",function(c){c.stop();this.changeImage(this.activeImage+1)}.bindAsEventListener(this));$("loadingLink").observe("click",function(c){c.stop();this.end()}.bind(this));$("bottomNavClose").observe("click",function(c){c.stop();this.end()}.bind(this));var d=this;(function(){$w("overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink imageDataContainer imageData imageDetails caption numberDisplay bottomNav bottomNavClose").each(function(c){d[c]=
$(c)})}).defer()},updateImageList:function(){this.updateImageList=Prototype.emptyFunction;document.observe("click",function(a){var b=a.findElement("a[rel^=lightbox]")||a.findElement("area[rel^=lightbox]");if(b){a.stop();this.start(b)}}.bind(this))},start:function(a){$$("select","object","embed").each(function(d){d.style.visibility="hidden"});var b=this.getPageSize();$("overlay").setStyle({width:b[0]+"px",height:b[1]+"px"});new Effect.Appear(this.overlay,{duration:this.overlayDuration,from:0,to:LightboxOptions.overlayOpacity});
this.imageArray=[];b=0;if(a.rel=="lightbox")this.imageArray.push([a.href,a.title]);else for(this.imageArray=$$(a.tagName+'[href][rel="'+a.rel+'"]').collect(function(d){return[d.href,d.title]}).uniq();this.imageArray[b][0]!=a.href;)b++;a=document.viewport.getScrollOffsets();this.lightbox.setStyle({top:a[1]+document.viewport.getHeight()/10+"px",left:a[0]+"px"}).show();this.changeImage(b)},changeImage:function(a){this.activeImage=a;LightboxOptions.animate&&this.loading.show();this.lightboxImage.hide();
this.hoverNav.hide();this.prevLink.hide();this.nextLink.hide();this.imageDataContainer.setStyle({opacity:1.0E-4});this.numberDisplay.hide();var b=new Image;b.onload=function(){this.lightboxImage.src=this.imageArray[this.activeImage][0];this.resizeImageContainer(b.width,b.height)}.bind(this);b.src=this.imageArray[this.activeImage][0]},resizeImageContainer:function(a,b){var d=this.outerImageContainer.getWidth(),c=this.outerImageContainer.getHeight(),e=a+LightboxOptions.borderSize*2,f=b+LightboxOptions.borderSize*
2;a=e/d*100;var g=f/c*100;d=d-e;c=c-f;c!=0&&new Effect.Scale(this.outerImageContainer,g,{scaleX:false,duration:this.resizeDuration,queue:"front"});d!=0&&new Effect.Scale(this.outerImageContainer,a,{scaleY:false,duration:this.resizeDuration,delay:this.resizeDuration});a=0;if(c==0&&d==0){a=100;if(Prototype.Browser.IE)a=250}(function(){this.prevLink.setStyle({height:b+"px"});this.nextLink.setStyle({height:b+"px"});this.imageDataContainer.setStyle({width:e+"px"});this.showImage()}).bind(this).delay(a/
1E3)},showImage:function(){this.loading.hide();new Effect.Appear(this.lightboxImage,{duration:this.resizeDuration,queue:"end",afterFinish:function(){this.updateDetails()}.bind(this)});this.preloadNeighborImages()},updateDetails:function(){this.imageArray.length>1&&this.numberDisplay.update(LightboxOptions.labelImage+" "+(this.activeImage+1)+" "+LightboxOptions.labelOf+"  "+this.imageArray.length).show();new Effect.Parallel([new Effect.SlideDown(this.imageDataContainer,{sync:true,duration:this.resizeDuration,
from:0,to:1}),new Effect.Appear(this.imageDataContainer,{sync:true,duration:this.resizeDuration})],{duration:this.resizeDuration,afterFinish:function(){this.overlay.setStyle({height:this.getPageSize()[1]+"px"});this.updateNav()}.bind(this)})},updateNav:function(){this.hoverNav.show();this.activeImage>0&&this.prevLink.show();this.activeImage<this.imageArray.length-1&&this.nextLink.show();this.enableKeyboardNav()},enableKeyboardNav:function(){document.observe("keydown",this.keyboardAction)},disableKeyboardNav:function(){document.stopObserving("keydown",
this.keyboardAction)},keyboardAction:function(a){var b=a.keyCode;a=a.DOM_VK_ESCAPE?a.DOM_VK_ESCAPE:27;var d=String.fromCharCode(b).toLowerCase();if(d.match(/x|o|c/)||b==a)this.end();else if(d=="p"||b==37){if(this.activeImage!=0){this.disableKeyboardNav();this.changeImage(this.activeImage-1)}}else if(d=="n"||b==39)if(this.activeImage!=this.imageArray.length-1){this.disableKeyboardNav();this.changeImage(this.activeImage+1)}},preloadNeighborImages:function(){var a;if(this.imageArray.length>this.activeImage+
1){a=new Image;a.src=this.imageArray[this.activeImage+1][0]}if(this.activeImage>0){a=new Image;a.src=this.imageArray[this.activeImage-1][0]}},end:function(){this.disableKeyboardNav();this.lightbox.hide();new Effect.Fade(this.overlay,{duration:this.overlayDuration});$$("select","object","embed").each(function(a){a.style.visibility="visible"})},getPageSize:function(){var a,b;if(window.innerHeight&&window.scrollMaxY){a=window.innerWidth+window.scrollMaxX;b=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>
document.body.offsetHeight){a=document.body.scrollWidth;b=document.body.scrollHeight}else{a=document.body.offsetWidth;b=document.body.offsetHeight}var d,c;if(self.innerHeight){d=document.documentElement.clientWidth?document.documentElement.clientWidth:self.innerWidth;c=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){d=document.documentElement.clientWidth;c=document.documentElement.clientHeight}else if(document.body){d=document.body.clientWidth;c=document.body.clientHeight}pageHeight=
b<c?c:b;pageWidth=a<d?a:d;return[pageWidth,pageHeight]}};document.observe("dom:loaded",function(){new Lightbox;return true});

