/*
	Original Code:
	Slimbox v1.64 - The ultimate lightweight Lightbox clone
	(c) 2007-2008 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.

	Slimbox Plus v1.00
	Modified by OrangeBread (http://www.lifewithpixel.com)
	License is the same as the original Slimbox v1.64
	29th Sept, 2008
	1) Added IFrame support to Slimbox v1.64.

	Additions by Peter Klein
	-	Added TYPO3 specific Print & Save options.
	- 	Support to set content size. You can add width/height parameters in the "rev" attribute of the anchor url.
		ex1) <a href="image.jpg" rev="width=50%, height=50%" rel="lightbox"><img src="image_thumb.jpg" alt="image"></a>
		ex2) <a href="text.html" rev="width=500, height=300" rel="lightbox">some text here</a>
*/
var Slimbox;(function(){var i=0,g,o,b,w,z,s,f,p,l=new Image(),m=new Image(),E,H,t,n,j,D,G,k,F,c,y,x;window.addEvent("domready",function(){$(document.body).adopt($$([E=new Element("div",{id:"lbOverlay"}).addEvent("click",r),G=new Element("div",{id:"lbBottomContainer"}),H=new Element("div",{id:"lbCenter"})]).setStyle("display","none"));t=new Element("div",{id:"lbImage"}).injectInside(H).adopt(j=new Element("a",{id:"lbPrevLink",href:"#"}).addEvent("click",e),D=new Element("a",{id:"lbNextLink",href:"#"}).addEvent("click",v));n=new Element("iframe",{id:"lbImage"}).addEvent("load",a).injectInside(t);k=new Element("div",{id:"lbBottom"}).injectInside(G).adopt(new Element("a",{id:"lbCloseLink",href:"#"}).addEvent("click",r),y=new Element("a",{id:"lbPrintLink",href:"#"}).addEvent("click",d),x=new Element("a",{id:"lbSaveLink",href:"#"}).addEvent("click",B),F=new Element("div",{id:"lbCaption"}),c=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}));f={overlay:new Fx.Tween(E,{property:"opacity",duration:500}).set(0),image:new Fx.Tween(t,{property:"opacity",duration:500,onComplete:a}),bottom:new Fx.Tween(k,{property:"margin-top",duration:400})}});Slimbox={open:function(L,K,J){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:"Item {x} of {y}",defaultIframeWidth:850,defaultIframeHeight:500},J||{});if(typeof L=="string"){L=[[L,K]];K=0}if(!g.enablePrintButton||!g.psScriptPath){y.setStyles({visibility:"hidden",display:"none",width:"0px"})}if(!g.enableSaveButton||!g.psScriptPath){x.setStyles({visibility:"hidden",display:"none",width:"0px"})}o=L;g.loop=g.loop&&(o.length>1);I();u(true);s=window.getScrollTop()+(window.getHeight()/15)+35;f.resize=new Fx.Morph(H,$extend({duration:g.resizeDuration,onComplete:a},g.resizeTransition?{transition:g.resizeTransition}:{}));H.setStyles({top:s,width:g.initialWidth,height:g.initialHeight,marginLeft:-(g.initialWidth/2),display:""});f.overlay.start(g.overlayOpacity);i=1;return A(K)}};Element.implement({slimbox:function(J,K){$$(this).slimbox(J,K);return this}});Elements.implement({slimbox:function(J,M,L){M=M||function(N){return[N.href,N.title,N.rev]};L=L||function(){return true};var K=this;K.removeEvents("click").addEvent("click",function(){var N=K.filter(L,this);return Slimbox.open(N.map(M),N.indexOf(this),J)});return K}});function I(){E.setStyles({top:window.getScrollTop(),height:window.getHeight()})}function u(J){["object",window.ie?"select":"embed"].forEach(function(L){Array.forEach(document.getElementsByTagName(L),function(M){if(J){M._slimbox=M.style.visibility}M.style.visibility=J?"hidden":M._slimbox})});E.style.display=J?"":"none";var K=J?"addEvent":"removeEvent";window[K]("scroll",I)[K]("resize",I);document[K]("keydown",C)}function C(J){switch(J.code){case 27:case 88:case 67:r();break;case 37:case 80:e();break;case 39:case 78:v()}return false}function e(){return A(w)}function v(){return A(z)}function A(J){if((i==1)&&(J>=0)){i=2;b=J;w=((b||!g.loop)?b:o.length)-1;z=b+1;if(z==o.length){z=g.loop?0:-1}$$(j,D,t,n,G).setStyle("display","none");f.bottom.cancel().set(0);f.image.set(0);H.className="lbLoading";var K=o[b][0];var L=/\.(jpe?g|png|gif|bmp)/i;if(K.match(L)){$$(y,x).setStyle("display","");p=new Image();p.datatype="image";p.onload=a;p.src=K}else{$$(y,x).setStyle("display","none");p=new Object();p.datatype="iframe";rev=o[b][2];p.w=h(rev,new RegExp("width=(\\d+)","i"),g.defaultIframeWidth);p.h=h(rev,new RegExp("height=(\\d+)","i"),g.defaultIframeHeight);n.setStyle("overflow", "hidden");n.setProperties({id:"lbFrame_"+new Date().getTime(),width:p.w,height:p.h,scrolling:"no",frameBorder:0,src:K})}}return false}function a(){switch(i++){case 2:H.className="";if(p.datatype=="image"){t.setStyles({backgroundImage:"url("+p.src+")",display:""});$$(t,k).setStyle("width",p.width);$$(t,j,D).setStyle("height",p.height);$$(j,D).setStyle("width","50%")}else{t.setStyles({backgroundImage:"",display:""});$$(t,k).setStyle("width",p.w);$$(t).setStyle("height",p.h);$$(j,D).setStyle("height","35px");$$(j,D).setStyle("width","65px");n.setStyles({display:""})}F.set("html",o[b][1]||"");c.set("html",(g.showCounter&&(o.length>1))?g.counterText.replace(/{x}/,b+1).replace(/{y}/,o.length):"");if(w>=0){l.src=o[w][0]}if(z>=0){m.src=o[z][0]}if(H.clientHeight!=t.offsetHeight){f.resize.start({height:t.offsetHeight});break}i++;case 3:if(H.clientWidth!=t.offsetWidth){f.resize.start({width:t.offsetWidth,marginLeft:-t.offsetWidth/2});break}i++;case 4:G.setStyles({top:s-35,marginLeft:H.style.marginLeft,visibility:"hidden",display:""});f.image.start(1);break;case 5:if(w>=0){j.style.display=""}if(z>=0){D.style.display=""}if(g.animateCaption){f.bottom.set(k.offsetHeight).start(0)}G.style.visibility="";i=1}}function r(){if(i){i=0;p.onload=$empty;for(var J in f){f[J].cancel()}$$(H,G).setStyle("display","none");f.overlay.chain(u).start(0)}return false}function h(M,K,L){var J=M.match(K);return J?J[1]:L}function d(){return q("print")}function B(){return q("save")}function q(K){if(g.psScriptPath){var J=window.open(g.psScriptPath+"?mode="+K+"&image="+o[b][0],"printsave","left=0,top=0,width="+(parseInt(t.style.width))+",height="+(parseInt(t.style.height))+",toolbar=0,resizable=1");return false}return true}})();
