/*
	Slimbox v1.64 - The ultimate lightweight Lightbox clone
	(c) 2007-2008 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
/*
	Modifications copyright 2008 Creative Spark <http://www.creativespark.co.uk>
*/
var Slimbox;

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

window.addEvent('domready', function(){
	var lightboxElements = $$('a[rel^=lightbox]');
	if (lightboxElements) lightboxElements.slimbox({}, null, function(el){
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});

	var lightboxDownloadElements = $$('a[rel^=lightboxdownload]');
	if (lightboxDownloadElements) lightboxDownloadElements.slimbox({downloadLink: true}, null, function(el){
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
});