/*
	Picbox v2.0
	(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 p(){var b={x:v.scrollLeft(),y:v.scrollTop()},d={x:v.width(),y:v.height()};s=d.x/2;q=d.y/2.2;if(O){s+=b.x;q+=b.y;a(m).css({left:b.x,top:b.y,width:d.x,height:d.y})}a(i).css({top:Math.max(0,q),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")})});m.style.display=b?"":"none";var d=b?"bind":"unbind";a(document)[d]("keydown", c);a(document)[d]("mousewheel",z)}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(A,true)}function k(){return e(B,true)}function e(b,d){if(b>=0){t=b;F=n[b][0];A=(t||(h.loop?n.length:0))-1;B=(t+1)%n.length||(h.loop?0:-1);M();m.className="pbLoading";a(i).css("display","none");a(R).html(n[t][1]||"");a(S).html((n.length>1&&h.counterText||"").replace(/{x}/,t+1).replace(/{y}/,n.length));if(A>= 0){T.src=n[A][0];a(G).css("visibility","")}if(B>=0){U.src=n[B][0];a(H).css("visibility","")}a(C).css("display","");l=new Image;l.onload=function(){o(d)};l.src=F}return false}function o(b){I();var d=v.width()/1.3,j=v.height()/1.3,g=1;if(l.width>d||l.height>j)g=Math.min(d/l.width,j/l.height);w=N=g;u(g,b);a(i).attr("src",F);a(i).css("display","");m.className=""}function u(b,d,j){var g=b/w;x=s-(s-x)*g;D=q-(q-D)*g;w=b;g=l.width*b;b=l.height*b;var y=x-g/2,J=D-b/2;d=h.animateResize?d?0:h.resizeDuration: 0;a(i).animate({width:g,height:b,top:J,left:y},{queue:false,duration:d,easing:h.resizeEasing,complete:j});return false}function I(){x=s;D=q}function z(b,d){return K(d)}function K(b){b=w+b*(w/10);return u(b)}function E(){if(w==N&&Math.abs(x-s+(q==q))<2)u(1);else{I();u(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(t>=0){M();t=A=B=-1;u(0,false,function(){a([i,C]).hide()});a(m).stop().fadeOut(h.overlayFadeDuration,f)}return false} var v=a(window),h,n,t=-1,F,A,B,P=window.XMLHttpRequest==undefined&&ActiveXObject!=undefined,O,s,q,x,D,w,N,l={},T=new Image,U=new Image,m,V,i,G,H,C,R,S;a(document).ready(function(){a(document.body).append(a([m=a('<div id="pbOverlay" />').click(Q).append(V=a('<div id="pbCloseBtn" />')[0])[0],i=a('<img id="pbImage" />').dblclick(E)[0],C=a('<div id="pbBottomContainer" />')[0]]).css("display","none"));bottom=a('<div id=pbBottom" />').appendTo(C).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||m.currentStyle&&m.currentStyle.position!="fixed"){a([m,V,i,C]).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+b.width()/2;D=d.top+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(m).fadeOut(0).fadeTo(h.overlayFadeDuration,h.overlayOpacity);p();f(1);n=b;h.loop=h.loop&&n.length>1;return e(d)};a.fn.picbox=function(b,d,j){d=d||function(y){return[y.href,y.title]};j=j||function(){return true};var g=this;a(g).unbind("click").click(function(){var y=this;filteredLinks=a.grep(g,function(W){return j.call(y, 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 p(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],p,false);else this.onmousewheel=p},teardown:function(){if(this.removeEventListener)for(var c=f.length;c;)this.removeEventListener(f[--c], p,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,o){return r(this,o,"d",e)};a.fn.jqResize=function(e,o){return r(this,o,"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",p.drag).unbind("mouseup");e&&e()}};var p=a.jqDnR,f=p.dnr,c=p.e,r=function(e,o,u,I){return e.each(function(){o=o?a(o,e):e;o.bind("mousedown",{e:e,k:u},function(z){var K= z.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:z.pageX,pY:z.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);

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)

if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
	jQuery(function($) {
		$("a[rel^='lightbox']").picbox({/* Put custom options here */}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	});
}