/*!
	Slimbox v1.64 - The ultimate lightweight Lightbox clone
	(c) 2007-2008 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/

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

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
Slimbox.scanPage = function() {
	$$("a").filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	}).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
	$$("a").filter(function(el) {
		return el.rel && el.rel.test(/^lightdrag/i);
	}).slimbox({drag: true}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};
window.addEvent("domready", Slimbox.scanPage);
