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