var Slimbox;(function(){var H=0,G,M,B,U,X,Q,F,N,K=new Image(),L=new Image(),c,f,R,I,b,e,J,d,C,W,V;window.addEvent("domready",function(){$(document.body).adopt($$([c=new Element("div",{id:"lbOverlay"}).addEvent("click",P),f=new Element("div",{id:"lbCenter"}),e=new Element("div",{id:"lbBottomContainer"})]).setStyle("display","none"));R=new Element("div",{id:"lbImage"}).injectInside(f).adopt(I=new Element("a",{id:"lbPrevLink",href:"#"}).addEvent("click",E),b=new Element("a",{id:"lbNextLink",href:"#"}).addEvent("click",T));J=new Element("div",{id:"lbBottom"}).injectInside(e).adopt(new Element("a",{id:"lbCloseLink",href:"#"}).addEvent("click",P),W=new Element("a",{id:"lbPrintLink",href:"#"}).addEvent("click",D),V=new Element("a",{id:"lbSaveLink",href:"#"}).addEvent("click",Z),d=new Element("div",{id:"lbCaption"}),C=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}));F={overlay:new Fx.Tween(c,{property:"opacity",duration:500}).set(0),image:new Fx.Tween(R,{property:"opacity",duration:500,onComplete:A}),bottom:new Fx.Tween(J,{property:"margin-top",duration:400})}});Slimbox={open:function(j,i,h){G=$extend({loop:false,overlayOpacity:0.8,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,psScriptPath:"",enablePrintButton:0,enableSaveButton:0,animateCaption:true,showCounter:true,counterText:"Image {x} of {y}"},h||{});if(typeof j=="string"){j=[[j,i]];i=0}if(!G.enablePrintButton||!psScriptPath){W.setStyle("display","none")}if(!G.enableSaveButton||!psScriptPath){V.setStyle("display","none")}M=j;G.loop=G.loop&&(M.length>1);g();S(true);Q=window.getScrollTop()+(window.getHeight()/15);F.resize=new Fx.Morph(f,$extend({duration:G.resizeDuration,onComplete:A},G.resizeTransition?{transition:G.resizeTransition}:{}));f.setStyles({top:Q,width:G.initialWidth,height:G.initialHeight,marginLeft:-(G.initialWidth/2),display:""});F.overlay.start(G.overlayOpacity);H=1;return Y(i)}};Element.implement({slimbox:function(h,i){$$(this).slimbox(h,i);return this}});Elements.implement({slimbox:function(h,k,j){k=k||function(l){return[l.href,l.title]};j=j||function(){return true};var i=this;i.removeEvents("click").addEvent("click",function(){var l=i.filter(j,this);return Slimbox.open(l.map(k),l.indexOf(this),h)});return i}});function g(){c.setStyles({top:window.getScrollTop(),height:window.getHeight()})}function S(h){["object",window.ie?"select":"embed"].forEach(function(j){Array.forEach(document.getElementsByTagName(j),function(k){if(h){k._slimbox=k.style.visibility}k.style.visibility=h?"hidden":k._slimbox})});c.style.display=h?"":"none";var i=h?"addEvent":"removeEvent";window[i]("scroll",g)[i]("resize",g);document[i]("keydown",a)}function a(h){switch(h.code){case 27:case 88:case 67:P();break;case 37:case 80:E();break;case 39:case 78:T()}return false}function E(){return Y(U)}function T(){return Y(X)}function Y(h){if((H==1)&&(h>=0)){H=2;B=h;U=((B||!G.loop)?B:M.length)-1;X=B+1;if(X==M.length){X=G.loop?0:-1}$$(I,b,R,e).setStyle("display","none");F.bottom.cancel().set(0);F.image.set(0);f.className="lbLoading";N=new Image();N.onload=A;N.src=M[h][0]}return false}function A(){switch(H++){case 2:f.className="";R.setStyles({backgroundImage:"url("+M[B][0]+")",display:""});$$(R,J).setStyle("width",N.width);$$(R,I,b).setStyle("height",N.height);d.set("html",M[B][1]||"");C.set("html",(G.showCounter&&(M.length>1))?G.counterText.replace(/{x}/,B+1).replace(/{y}/,M.length):"");if(U>=0){K.src=M[U][0]}if(X>=0){L.src=M[X][0]}if(f.clientHeight!=R.offsetHeight){F.resize.start({height:R.offsetHeight});break}H++;case 3:if(f.clientWidth!=R.offsetWidth){F.resize.start({width:R.offsetWidth,marginLeft:-R.offsetWidth/2});break}H++;case 4:e.setStyles({top:Q+f.clientHeight,marginLeft:f.style.marginLeft,visibility:"hidden",display:""});F.image.start(1);break;case 5:if(U>=0){I.style.display=""}if(X>=0){b.style.display=""}if(G.animateCaption){F.bottom.set(-J.offsetHeight).start(0)}e.style.visibility="";H=1}}function P(){if(H){H=0;N.onload=$empty;for(var h in F){F[h].cancel()}$$(f,e).setStyle("display","none");F.overlay.chain(S).start(0)}return false}function D(){return O("print")}function Z(){return O("save")}function O(i){if(G.psScriptPath){var h=window.open(G.psScriptPath+"?mode="+i+"I="+M[B][0],"printsave","left=0,top=0,width="+(parseInt(R.style.width))+",height="+(parseInt(R.style.height))+",toolbar=0,resizable=1");return false}return true}})()
