/*
	Picbox v2.0.2
	(c) 2009 Ben Kay <http://bunnyfire.co.uk>

	Based on code from Slimbox v1.7 (and glances at v2.02) - The ultimate lightweight Lightbox clone
	(c) 2007-2009 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/

(function(a){function o(){var b={x:q.scrollLeft(),y:q.scrollTop()},d={x:q.width(),y:q.height()};s=d.x/2;t=d.y/2.2;if(O){s+=b.x;t+=b.y;a(p).css({left:b.x,top:b.y,width:d.x,height:d.y})}a(i).css({top:Math.max(0,t),left:Math.max(0,s),width:1,height:1})}function f(b){a.each(["object",P?"select":"embed"],function(j,g){a(g).each(function(){b&&this.data("vis",this.style.visibility);this.style.visibility=b?"hidden":this.data("vis")})});var d=b?"bind":"unbind";a(document)[d]("keydown",c);a(document)[d]("mousewheel", A)}function c(b){b=b.keyCode;return a.inArray(b,h.closeKeys)>=0?Q():a.inArray(b,h.nextKeys)>=0?k():a.inArray(b,h.previousKeys)>=0?r():false}function r(){return e(B,true)}function k(){return e(C,true)}function e(b,d){if(b>=0){u=b;F=m[b][0];B=(u||(h.loop?m.length:0))-1;C=(u+1)%m.length||(h.loop?0:-1);M();p.className="pbLoading";a(i).css("display","none");a(R).html(m[u][1]||"");a(S).html((m.length>1&&h.counterText||"").replace(/{x}/,u+1).replace(/{y}/,m.length));if(B>=0){T.src=m[B][0];a(G).css("visibility", "")}if(C>=0){U.src=m[C][0];a(H).css("visibility","")}a(D).css("display","");l=new Image;l.onload=function(){n(d)};l.src=F}return false}function n(b){I();var d=q.width()/1.3,j=q.height()/1.3,g=1;if(l.width>d||l.height>j)g=Math.min(d/l.width,j/l.height);w=N=g;v(g,b);a(i).attr("src",F);a(i).css("display","");p.className=""}function v(b,d,j){var g=b/w;x=s-(s-x)*g;y=t-(t-y)*g;w=b;g=l.width*b;b=l.height*b;var z=x-g/2,J=y-b/2;d=h.animateResize?d?0:h.resizeDuration:0;a(i).animate({width:g,height:b,top:J, left:z},{queue:false,duration:d,easing:h.resizeEasing,complete:j});return false}function I(){x=s;y=t}function A(b,d){return K(d)}function K(b){return v(w+b*(w/10))}function E(){if(w==N&&Math.abs(x-s+(y-t))<2)v(1);else{I();v(N)}}function M(){l.onload=function(){};l.src=T.src=U.src=F;a(i).stop();a([G,H]).css("visibility","hidden")}function Q(){if(u>=0){M();u=B=C=-1;v(0,false,function(){a([i,D]).hide()});a(p).stop().fadeOut(h.overlayFadeDuration,f)}return false}var q=a(window),h,m,u=-1,F,B,C,P=window.XMLHttpRequest== undefined&&ActiveXObject!=undefined,O,s,t,x,y,w,N,l={},T=new Image,U=new Image,p,V,i,G,H,D,R,S;a(document).ready(function(){a(document.body).append(a([p=a('<div id="pbOverlay" />').click(Q).append(V=a('<div id="pbCloseBtn" />')[0])[0],i=a('<img id="pbImage" />').dblclick(E)[0],D=a('<div id="pbBottomContainer" />')[0]]).css("display","none"));bottom=a('<div id=pbBottom" />').appendTo(D).append(R=a('<div id="pbCaption" />')[0],S=a('<div id="pbNumber" />')[0],a('<div id="pbArrows" />').append(G=a('<a id="pbPrevLink" href="#">Prev</a>').click(r)[0], H=a('<a id="pbNextLink" href="#">Next</a>').click(k)[0]),a('<div style="clear: both;" />'));if(O=P||p.currentStyle&&p.currentStyle.position!="fixed"){a([p,V,i,D]).css("position","absolute");a([G,H]).css({"background-image":"none","text-indent":0})}a(i).jqDrag(function(){var b=a(i),d=b.position();x=d.left-q.scrollLeft()+b.width()/2;y=d.top-q.scrollTop()+b.height()/2})});a.picbox=function(b,d,j){h=a.extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,animateResize:true,resizeDuration:300, resizeEasing:"swing",counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},j||{});if(typeof b=="string"){b=[[b,d]];d=0}a(p).attr("opacity",0).show().fadeTo(h.overlayFadeDuration,h.overlayOpacity);o();f(1);m=b;h.loop=h.loop&&m.length>1;return e(d)};a.fn.picbox=function(b,d,j){d=d||function(z){return[z.href,z.title]};j=j||function(){return true};var g=this;a(g).unbind("click").click(function(){var z=this;filteredLinks=a.grep(g,function(W){return j.call(z,W)});for(var J= [],L=0;L<filteredLinks.length;L++)J[L]=d(filteredLinks[L]);return a.picbox(J,a.inArray(this,filteredLinks),b)});return g}})(jQuery); (function(a){function o(c){var r=[].slice.call(arguments,1),k=0;c=a.event.fix(c||window.event);c.type="mousewheel";if(c.wheelDelta)k=c.wheelDelta/120;if(c.detail)k=-c.detail/3;r.unshift(c,k);return a.event.handle.apply(this,r)}var f=["DOMMouseScroll","mousewheel"];a.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var c=f.length;c;)this.addEventListener(f[--c],o,false);else this.onmousewheel=o},teardown:function(){if(this.removeEventListener)for(var c=f.length;c;)this.removeEventListener(f[--c], o,false);else this.onmousewheel=null}};a.fn.extend({mousewheel:function(c){return c?this.bind("mousewheel",c):this.trigger("mousewheel")},unmousewheel:function(c){return this.unbind("mousewheel",c)}})})(jQuery); (function(a){a.fn.jqDrag=function(e,n){return r(this,n,"d",e)};a.fn.jqResize=function(e,n){return r(this,n,"r",e)};a.jqDnR={dnr:{},e:0,drag:function(e){f.k=="d"?c.css({left:f.X+e.pageX-f.pX,top:f.Y+e.pageY-f.pY}):c.css({width:Math.max(e.pageX-f.pX+f.W,0),height:Math.max(e.pageY-f.pY+f.H,0)});return false},stop:function(e){a().unbind("mousemove",o.drag).unbind("mouseup");e&&e()}};var o=a.jqDnR,f=o.dnr,c=o.e,r=function(e,n,v,I){return e.each(function(){n=n?a(n,e):e;n.bind("mousedown",{e:e,k:v},function(A){var K= A.data,E={};c=K.e;if(c.css("position")!="relative")try{c.position(E)}catch(M){}f={X:E.left||k("left")||0,Y:E.top||k("top")||0,W:k("width")||c[0].scrollWidth||0,H:k("height")||c[0].scrollHeight||0,pX:A.pageX,pY:A.pageY,k:K.k,o:c.css("opacity")};a().mousemove(a.jqDnR.drag).mouseup(function(){a.jqDnR.stop(I)});return false})})},k=function(e){return parseInt(c.css(e))||false}})(jQuery);