/*
	Slimbox v2.04 - The ultimate lightweight Lightbox clone for jQuery
	(c) 2007-2010 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
(function(w){var C=w(window),r,F,g=-1,o,n,D,t,l,L,v,m=!window.XMLHttpRequest,u=[],k=document.documentElement,y={},s=new Image(),K=new Image(),b,H,e,p,a,c,f,G,z,J;w(function(){w("body").append(w([b=w('<div id="lbOverlay" />')[0],H=w('<div id="lbCenter" />')[0],f=w('<div id="lbBottomContainer" />')[0]]).css("display","none"));e=w('<div id="lbImage" />').appendTo(H).append(p=w('<div style="position: relative;" />').append([a=w('<a id="lbPrevLink" href="#" />').click(j)[0],c=w('<a id="lbNextLink" href="#" />').click(d)[0]])[0])[0];G=w('<div id="lbBottom" />').appendTo(f).append([w('<a id="lbCloseLink" href="#" />').add(b).click(B)[0],z=w('<div id="lbCaption" />')[0],J=w('<div id="lbNumber" />')[0],w('<div style="clear: both;" />')[0]])[0]});w.slimbox=function(O,N,M){r=w.extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeEasing:"swing",initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78],skipHotkeys:false},M);if(typeof O=="string"||typeof O=="function"){O=[[O,N]];N=0}l=C.scrollTop()+(C.height()/2);L=r.initialWidth;v=r.initialHeight;w(H).css({top:Math.max(0,l-(v/2)),width:L,height:v,marginLeft:-L/2}).show();t=m||(b.currentStyle&&(b.currentStyle.position!="fixed"));if(t){b.style.position="absolute"}w(b).css("opacity",r.overlayOpacity).fadeIn(r.overlayFadeDuration);A();i(1);F=O;r.loop=r.loop&&(F.length>1);return I(N)};w.fn.slimbox=function(M,P,O){P=P||function(Q){return[Q.href,Q.title]};O=O||function(){return true};var N=this;return N.unbind("click").click(function(){var S=this,U=0,T,R=0,Q;T=w.grep(N,function(W,V){return O.call(S,W,V)});for(Q=T.length;R<Q;++R){if(T[R]==S){U=R}T[R]=P(T[R],R)}return w.slimbox(T,U,M)})};function A(){var N=C.scrollLeft(),M=C.width();w([H,f]).css("left",N+(M/2));if(t){w(b).css({left:N,top:C.scrollTop(),width:M,height:C.height()})}}function i(M){if(M){w("object").add(m?"select":"embed").each(function(O,P){u[O]=[P,P.style.visibility];P.style.visibility="hidden"})}else{w.each(u,function(O,P){P[0].style.visibility=P[1]});u=[]}var N=M?"bind":"unbind";C[N]("scroll resize",A);w(document)[N]("keydown",x)}function x(O){if(r.skipHotkeys==true){return true}var N=O.keyCode,M=w.inArray;return(M(N,r.closeKeys)>=0)?B():(M(N,r.nextKeys)>=0)?d():(M(N,r.previousKeys)>=0)?j():false}function j(){return I(n)}function d(){return I(D)}function I(M){if(M>=0){g=M;o=F[g][0];n=(g||(r.loop?F.length:0))-1;D=((g+1)%F.length)||(r.loop?0:-1);q();H.className="lbLoading";if(typeof o=="function"){y=o(w(e));h()}else{y=new Image();y.onload=h;y.src=o}}return false}function h(){H.className="";if(y.src){w(e).css({backgroundImage:"url("+y.src+")"})}w(e).css({visibility:"hidden",display:""});w(p).width(y.width);w([p,a,c]).height(y.height);w(z).html(F[g][1]||"");w(J).html((((F.length>1)&&r.counterText)||"").replace(/{x}/,g+1).replace(/{y}/,F.length));if(n>=0){s.src=F[n][0]}if(D>=0){K.src=F[D][0]}L=e.offsetWidth;v=e.offsetHeight;var M=Math.max(0,l-(v/2));if(H.offsetHeight!=v){w(H).animate({height:v,top:M},r.resizeDuration,r.resizeEasing)}if(H.offsetWidth!=L){w(H).animate({width:L,marginLeft:-L/2},r.resizeDuration,r.resizeEasing)}w(H).queue(function(){w(f).css({width:L,top:M+v,marginLeft:-L/2,visibility:"hidden",display:""});w(e).css({display:"none",visibility:"",opacity:""}).fadeIn(r.imageFadeDuration,E)})}function E(){if(n>=0){w(a).show()}if(D>=0){w(c).show()}w(G).css("marginTop",-G.offsetHeight).animate({marginTop:0},r.captionAnimationDuration);f.style.visibility=""}function q(){y.onload=null;if(typeof o!="function"){y.src=s.src=K.src=o}w([H,e,G]).stop(true);w([a,c,e,f]).hide()}function B(){if(g>=0){q();g=n=D=-1;w(H).hide();if(typeof o=="function"&&y.storeFunction){y.storeFunction()}w(b).stop().fadeOut(r.overlayFadeDuration,i)}return false}})(jQuery);
