var Slimbox;(function(){var v=0,w,q,aa,j,i,n,x,p,s=new Image(),r=new Image(),e,ad,m,u,f,c,t,d,z;window.addEvent("domready",function(){$(document.body).adopt($$([e=new Element("div",{id:"lbOverlay"}).addEvent("click",o),ad=new Element("div",{id:"lbCenter"}),c=new Element("div",{id:"lbBottomContainer"})]).setStyle("display","none"));m=new Element("div",{id:"lbImage"}).injectInside(ad).adopt(u=new Element("a",{id:"lbPrevLink",href:"#"}).addEvent("click",y),f=new Element("a",{id:"lbNextLink",href:"#"}).addEvent("click",k));t=new Element("div",{id:"lbBottom"}).injectInside(c).adopt(new Element("a",{id:"lbCloseLink",href:"#"}).addEvent("click",o),d=new Element("div",{id:"lbCaption"}),z=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}));x={overlay:new Fx.Tween(e,{property:"opacity",duration:500}).set(0),image:new Fx.Tween(m,{property:"opacity",duration:500,onComplete:ab}),bottom:new Fx.Tween(t,{property:"margin-top",duration:400})}});Slimbox={open:function(a,b,A){w=$extend({loop:false,overlayOpacity:0.8,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,animateCaption:true,showCounter:true,counterText:"Image {x} of {y}"},A||{});if(typeof a=="string"){a=[[a,b]];b=0}q=a;w.loop=w.loop&&(q.length>1);ac();l(true);n=window.getScrollTop()+(window.getHeight()/15);x.resize=new Fx.Morph(ad,$extend({duration:w.resizeDuration,onComplete:ab},w.resizeTransition?{transition:w.resizeTransition}:{}));ad.setStyles({top:n,width:w.initialWidth,height:w.initialHeight,marginLeft:-(w.initialWidth/2),display:""});x.overlay.start(w.overlayOpacity);v=1;return h(b)}};Element.implement({slimbox:function(b,a){$$(this).slimbox(b,a);return this}});Elements.implement({slimbox:function(B,a,b){a=a||function(C){return[C.href,C.title]};b=b||function(){return true};var A=this;A.removeEvents("click").addEvent("click",function(){var C=A.filter(b,this);return Slimbox.open(C.map(a),C.indexOf(this),B)});return A}});function ac(){e.setStyles({top:window.getScrollTop(),height:window.getHeight()})}function l(b){["object",window.ie?"select":"embed"].forEach(function(A){Array.forEach(document.getElementsByTagName(A),function(B){if(b){B._slimbox=B.style.visibility}B.style.visibility=b?"hidden":B._slimbox})});e.style.display=b?"":"none";var a=b?"addEvent":"removeEvent";window[a]("scroll",ac)[a]("resize",ac);document[a]("keydown",g)}function g(a){switch(a.code){case 27:case 88:case 67:o();break;case 37:case 80:y();break;case 39:case 78:k()}return false}function y(){return h(j)}function k(){return h(i)}function h(a){if((v==1)&&(a>=0)){v=2;aa=a;j=((aa||!w.loop)?aa:q.length)-1;i=aa+1;if(i==q.length){i=w.loop?0:-1}$$(u,f,m,c).setStyle("display","none");x.bottom.cancel().set(0);x.image.set(0);ad.className="lbLoading";p=new Image();p.onload=ab;p.src=q[a][0]}return false}function ab(){switch(v++){case 2:ad.className="";m.setStyles({backgroundImage:"url("+q[aa][0]+")",display:""});$$(m,t).setStyle("width",p.width);$$(m,u,f).setStyle("height",p.height);d.set("html",q[aa][1]||"");z.set("html",(w.showCounter&&(q.length>1))?w.counterText.replace(/{x}/,aa+1).replace(/{y}/,q.length):"");if(j>=0){s.src=q[j][0]}if(i>=0){r.src=q[i][0]}if(ad.clientHeight!=m.offsetHeight){x.resize.start({height:m.offsetHeight});break}v++;case 3:if(ad.clientWidth!=m.offsetWidth){x.resize.start({width:m.offsetWidth,marginLeft:-m.offsetWidth/2});break}v++;case 4:c.setStyles({top:n+ad.clientHeight,marginLeft:ad.style.marginLeft,visibility:"hidden",display:""});x.image.start(1);break;case 5:if(j>=0){u.style.display=""}if(i>=0){f.style.display=""}if(w.animateCaption){x.bottom.set(-t.offsetHeight).start(0)}c.style.visibility="";v=1}}function o(){if(v){v=0;p.onload=$empty;for(var a in x){x[a].cancel()}$$(ad,c).setStyle("display","none");x.overlay.chain(l).start(0)}return false}})();Slimbox.scanPage=function(){var a=$$("a").filter(function(b){return b.rel&&b.rel.test(/^lightbox/i)});$$(a).slimbox({},null,function(b){return(this==b)||((this.rel.length>8)&&(this.rel==b.rel))})};window.addEvent("domready",Slimbox.scanPage);
