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

	Additions by Peter Klein
	-	Added TYPO3 specific Print & Save options.
	
*/
var Slimbox=(function(){var K=window,p=Browser.Engine.trident4,z,i,L=-1,q,B,J,A,D,S,x,o={},y=new Image(),Q=new Image(),O,b,j,s,P,g,M,c,F,R,w,d,C,k,e,H;K.addEvent("domready",function(){$(document.body).adopt($$(O=new Element("div",{id:"lbOverlay",events:{click:I}}),b=new Element("div",{id:"lbCenter"}),M=new Element("div",{id:"lbBottomContainer"})).setStyle("display","none"));j=new Element("div",{id:"lbImage"}).injectInside(b).adopt(s=new Element("div",{styles:{position:"relative"}}).adopt(P=new Element("a",{id:"lbPrevLink",href:"#",events:{click:G}}),g=new Element("a",{id:"lbNextLink",href:"#",events:{click:h}})));c=new Element("div",{id:"lbBottom"}).injectInside(M).adopt(new Element("a",{id:"lbCloseLink",href:"#",events:{click:I}}),w=new Element("a",{id:"lbPrintLink",href:"#"}).addEvent("click",N),d=new Element("a",{id:"lbSaveLink",href:"#"}).addEvent("click",v),F=new Element("div",{id:"lbCaption"}),R=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}))});function E(){var T=K.getScroll(),U=K.getSize();$$(b,M).setStyle("left",T.x+(U.x/2));if(A){O.setStyles({left:T.x,top:T.y,width:U.x,height:U.y})}}function n(T){["object",p?"select":"embed"].forEach(function(V){Array.forEach(document.getElementsByTagName(V),function(W){if(T){W._slimbox=W.style.visibility}W.style.visibility=T?"hidden":W._slimbox})});O.style.display=T?"":"none";var U=T?"addEvent":"removeEvent";K[U]("scroll",E)[U]("resize",E);document[U]("keydown",r)}function r(U){var T=U.code;return z.closeKeys.contains(T)?I():z.nextKeys.contains(T)?h():z.previousKeys.contains(T)?G():false}function G(){return a(B)}function h(){return a(J)}function a(T){if(T>=0){L=T;q=i[T][0];B=(L||(z.loop?i.length:0))-1;J=((L+1)%i.length)||(z.loop?0:-1);t();b.className="lbLoading";o=new Image();o.onload=m;o.src=q}return false}function u(T){return T.replace(/^#(.*)#/,"<h4>$1</h4><p>")+"</p>"}function m(){b.className="";e.set(0);j.setStyles({backgroundImage:"url("+q+")",display:""});s.setStyle("width",o.width);$$(s,P,g).setStyle("height",o.height);F.set("html",u(i[L][1])||"");R.set("html",(((i.length>1)&&z.counterText)||"").replace(/{x}/,L+1).replace(/{y}/,i.length));if(B>=0){y.src=i[B][0]}if(J>=0){Q.src=i[J][0]}S=j.offsetWidth;x=j.offsetHeight;var U=Math.max(0,D-(x/2)),T;if(b.offsetHeight!=x){k.start({height:x,top:U})}if(b.offsetWidth!=S){k.start({width:S,marginLeft:-S/2})}T=function(){M.setStyles({width:S,top:U+x,marginLeft:-S/2,visibility:"hidden",display:""});e.start(1)};if(k.check(T)){T()}}function l(){if(B>=0){P.style.display=""}if(J>=0){g.style.display=""}H.set(-c.offsetHeight).start(0);M.style.visibility=""}function t(){o.onload=$empty;o.src=y.src=Q.src=q;k.cancel();e.cancel();H.cancel();$$(P,g,j,M).setStyle("display","none")}function I(){if(L>=0){t();L=B=J=-1;b.style.display="none";C.cancel().chain(n).start(0)}return false}function N(){return f("print")}function v(){return f("save")}function f(U){if(z.psScriptPath){var T=window.open(z.psScriptPath+"?mode="+U+"&image="+i[L][0],"printsave","left=0,top=0,width="+(parseInt(j.style.width))+",height="+(parseInt(j.style.height))+",toolbar=0,resizable=1");return false}return true}Element.implement({slimbox:function(T,U){$$(this).slimbox(T,U);return this}});Elements.implement({slimbox:function(T,W,V){W=W||function(X){return[X.href,X.title]};V=V||function(){return true};var U=this;U.removeEvents("click").addEvent("click",function(){var X=U.filter(V,this);return Slimbox.open(X.map(W),X.indexOf(this),T)});return U}});return{open:function(V,U,T){z=$extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,psScriptPath:"",enablePrintButton:0,enableSaveButton:0,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},T||{});C=new Fx.Tween(O,{property:"opacity",duration:z.overlayFadeDuration});k=new Fx.Morph(b,$extend({duration:z.resizeDuration,link:"chain"},z.resizeTransition?{transition:z.resizeTransition}:{}));e=new Fx.Tween(j,{property:"opacity",duration:z.imageFadeDuration,onComplete:l});H=new Fx.Tween(c,{property:"margin-top",duration:z.captionAnimationDuration});if(typeof V=="string"){V=[[V,U]];U=0}if(!z.enablePrintButton||!z.psScriptPath){w.setStyles({visibility:"hidden",display:"none",width:"0px"})}if(!z.enableSaveButton||!z.psScriptPath){d.setStyles({visibility:"hidden",display:"none",width:"0px"})}D=K.getScrollTop()+(K.getHeight()/2);S=z.initialWidth;x=z.initialHeight;b.setStyles({top:Math.max(0,D-(x/2)),width:S,height:x,marginLeft:-S/2,display:""});A=p||(O.currentStyle&&(O.currentStyle.position!="fixed"));if(A){O.style.position="absolute"}C.set(0).start(z.overlayOpacity);E();n(1);i=V;z.loop=z.loop&&(i.length>1);return a(U)}}})();
