(function(a){a.fn.superbox=function(f){var f=a.extend({thumbs:5,overlayColor:"#999",overlayOpacity:0.8,overlaySpeed:500,scrollSpeed:500,zoomSpeed:250,showOne:!1,preventImgOverflow:!0,keyboardNavigation:!0,wheelNavigation:!0,showLabel:!0,labelPosition:"bottom",descAttr:"alt",dockPosition:"top",timeOut:15,maxThumbWidth:0,maxThumbHeight:0,openImageEffect:"linear",closeImageEffect:"linear",scrollDockEffect:"linear"},f),b=[],e=void 0,y=void 0,o=void 0,q=void 0,h=void 0,p=!1,i=!1,k=!1,z=0;$all=a(this);storeData=
function(a,b){for(key in b)a.data(key,b[key])};$all.each(function(c,d){objList=d.tagName=="A"?a(d):a(d).find("a");objList.size()==1?(storeData(objList,f),a(objList).bind("click",function(c){a(this).blur();c.preventDefault();k=!1;img=a(this).find("img");label=a(img).attr(f.descAttr);big=a(this).attr("href");coord={left:a(img).offset().left,top:a(img).offset().top,width:a(img).outerWidth(),height:a(img).outerHeight()};var c=big,d=label,j=coord;A(f);i=!0;s();B();C(j,c,d,void 0);b.wheelNavigation&&D();
b.keyboardNavigation&&a(window).bind("keydown",t)})):objList.each(function(c,b){a(b).bind("click",function(c){c.preventDefault();a(this).blur();k=!1;showDock(a(this).data("objlist"),a(this).data("params"),a(this).data("indeximg"))});storeData(a(b),{indeximg:c+1,params:f,objlist:a(d)});a(b).find("img").data("big",a(b).attr("href"));f.showOne&&c>0&&a(b).css({position:"absolute",left:-5E3,top:-3E3})})});getDim=function(a,b,e,l){a>e&&(b/=a/e,a=e);b>l&&(a/=b/l,b=l);return[a,b]};showDock=function(c,d,f){A(d);
k=!1;s();maxThumbW=b.maxThumbWidth===0?1E6:b.maxThumbWidth;maxThumbH=b.maxThumbHeight===0?1E6:b.maxThumbHeight;cls=!1;pgs='<div class="superbox-page" page="1">';qtd=a(c).find("a").find("img").size();pag=1;a(c).find("a").find("img").each(function(c,d){src=a(d).attr("src");big=a(d).data("big");lbl=a(d).attr("alt");widthThumb=a(d).width();heightThumb=a(d).height();newSizes=getDim(widthThumb,heightThumb,maxThumbW,maxThumbH);widthThumb=newSizes[0];heightThumb=newSizes[1];pgs+='<img src="'+src+'" alt="'+
lbl+'" big="'+big+'" imgindex="'+(c+1)+'" width="'+widthThumb+'" height="'+heightThumb+'" />';(c+1)%b.thumbs||(pgs+="</div>",cls=!0,c+1<qtd&&(pag+=1,pgs+='<div class="superbox-page" page="'+pag+'">',cls=!1))});cls||(pgs+="</div>");a("body").append('<div id="superbox-dock"><div class="superbox-arrowdock superbox-leftarrow" arrowdir="p"></div><div class="superbox-scrollerpages"><div class="superbox-pages">'+pgs+'</div></div><div class="superbox-arrowdock superbox-rightarrow" arrowdir="n"></div></div>');hd=
a(".superbox-scrollerpages").height();a(".superbox-page > img").each(function(c,b){v=(hd-a(b).attr("height"))/2-2;a(b).css("margin-bottom",v)});a(".superbox-page > img").bind("click",function(c){e||g(a(c.target).attr("imgindex"))}).bind("mouseover",function(c){a(c.target).addClass("superbox-hoverImage")}).bind("mouseout",function(c){a(c.target).removeClass("superbox-hoverImage")});a(".superbox-arrowdock").bind("click",function(c){e||(page=o,u(a(c.target).attr("arrowdir")=="n"?page+1:page-1))});b.wheelNavigation&&
D();b.keyboardNavigation&&a(document).bind("keydown",t);a("#superbox-dock > .superbox-leftarrow").fadeTo(0,0.1);a(".superbox-page").size()==1&&a("#superbox-dock > .superbox-rightarrow").fadeTo(0,0.1);wmax=hmax=0;a(".superbox-page").each(function(c,b){a(b).width()>wmax&&(wmax=a(b).width());a(b).height()>hmax&&(hmax=a(b).height())});a(".superbox-page, .superbox-scrollerpages, #superbox-dock").css({width:wmax,height:hmax});a(".superbox-pages").css({width:wmax*a(".superbox-page").size()});a(".superbox-arrowdock").css({height:hmax});
B();e=!0;y=wmax;o=1;q=qtd;i=p=h=!1;tTop=b.dockPosition=="top"?a(document).scrollTop()+10:a(window).height()+a(document).scrollTop()-a("#superbox-dock").height()-10;a("#superbox-dock").css({top:tTop,width:wmax+40,left:a(window).width()/2-wmax/2-20}).hide().fadeIn(b.overlaySpeed,function(){e=!1;f!=void 0&&u(Math.ceil(f/b.thumbs),f)})};var D=function(){document.attachEvent?document.attachEvent("onmousewheel",r):window.addEventListener&&window.addEventListener(a.browser.mozilla?"DOMMouseScroll":"mousewheel",
r,!1)},r=function(c){if(!(a.browser.msie&&Number(a.browser.version)<8||a.browser.opera)){var b=0;if(!c)c=window.event;c.wheelDelta?(b=c.wheelDelta/120,window.opera&&(b=-b)):c.detail&&(b=-c.detail/3);b&&(b>0?e||g(h-1):e||g(h+1))}},t=function(a){if(a.keyCode==27)k=!0,n();else if(b.keyboardNavigation&&jQuery.inArray(a.keyCode,[39,40,13,32,37,38,8,27,36,35])!=-1&&(a.preventDefault(),!e))switch(a.keyCode){case 39:case 40:case 13:case 32:i||g(h+1);break;case 37:case 38:case 8:i||g(h-1);break;case 36:i||
g(1);break;case 35:i||g(q);break;case 27:n()}},E=function(){a(document).unbind("keydown",t);document.detachEvent?document.detachEvent("onmousewheel",r):window.removeEventListener&&window.removeEventListener(a.browser.mozilla?"DOMMouseScroll":"onmousewheel",r,!1)},s=function(){a("#superbox-loader").size()||(a("body").append('<div id="superbox-loader"></div>'),a("#superbox-loader").css({left:a(window).width()/2-64,top:a(window).height()/2+a(document).scrollTop()-7}))},w=function(){a("#superbox-loader").remove()},
A=function(c){b=c;if(a.easing.def==void 0)b.openImageEffect="linear",b.closeImageEffect="linear",b.scrollDockEffect="linear"},g=function(c){!(c<1)&&!(c>q)&&h!=c&&(e=!0,page=Math.ceil(c/b.thumbs),o!=page?u(page,c):(a(".superbox-page > img").removeClass("superbox-currentImage"),a(".superbox-page").find('img[imgindex="'+c+'"]').addClass("superbox-currentImage"),h=c,thumb=a('.superbox-page > img[imgindex="'+c+'"]'),urlImg=a(thumb).attr("big"),label=a(thumb).attr(b.descAttr),s(),a("#superbox-image").size()?
F(c):(cord={left:a(thumb).offset().left+5,top:a(thumb).offset().top+5,width:a(thumb).outerWidth()-10,height:a(thumb).outerHeight()-10},C(cord,urlImg,label,c))))},C=function(c,d,f,l){p=c;var j=document.createElement("img");a("body").append(j);z=0;var i=setInterval(function(){z>b.timeOut&&(clearInterval(i),k=!0,n(),x())},1E3);a(j).hide().attr("src",d);var m=new Image;m.onerror=null;m.onload=function(){clearInterval(i);w();k?a(j).remove():(j.id="superbox-image",j.src=d,b.preventImgOverflow?(diff=34,b.showLabel&&
(diff+=60),newDim=getDim(m.width,m.height,a(window).width(),a(window).height()-diff),imgWidth=newDim[0],imgHeight=newDim[1]):(imgWidth=m.width,imgHeight=m.height),a(j).css(c).show().animate({left:a(window).width()/2-imgWidth/2,top:a(window).height()/2-imgHeight/2+a(document).scrollTop(),width:imgWidth,height:imgHeight},{easing:b.openImageEffect,duration:b.zoomSpeed,complete:function(){k||(a("body").append('<div id="superbox-border"></div>'),pos=jQuery(j).position(),a("#superbox-border").hide().css({width:imgWidth+
12,height:imgHeight+12,left:pos.left-6,top:pos.top-6}).fadeIn("normal",function(){e=!1;a("body").append('<div id="superbox-close"></div>');a("#superbox-close").bind("click",function(){e||n()}).css({left:pos.left-12+imgWidth,top:pos.top-6-12})}),l!=1&&l!=void 0&&(a("body").append('<div id="superbox-buttonPrev"></div>'),a("#superbox-buttonPrev").bind("click",function(){e||g(h-1)})),l!=q&&l!=void 0&&(a("body").append('<div id="superbox-buttonNext"></div>'),a("#superbox-buttonNext").bind("click",function(){e||
g(h+1)})),topBtn=pos.top+imgHeight/2-33,a("#superbox-buttonPrev").css({top:topBtn,left:pos.left-51}),a("#superbox-buttonNext").css({top:topBtn,left:pos.left+imgWidth+10}),a.browser.msie||a("#superbox-buttonPrev, #superbox-buttonNext").hide().fadeIn(),b.showLabel&&f!=""&&f!=void 0&&(a("body").append('<div id="superbox-label"></div>'),a("#superbox-label").html(f),topPosLabel=b.labelPosition=="bottom"?pos.top+imgHeight+10:pos.top-25-a("#superbox-label").height(),a("#superbox-label").css({top:topPosLabel,left:pos.left+
imgWidth/2-a("#superbox-label").width()/2}),a.browser.msie||a("#superbox-label").hide().fadeIn()))}}),m.onload=function(){})};m.src=d},B=function(){a("body").append('<div id="superbox-overlay"></div>').css({overflow:"hidden"});a("#superbox-overlay").bind("click",function(){k=!0;n()}).css({width:a(window).width(),height:a(document).height(),background:b.overlayColor}).fadeTo(b.overlaySpeed,b.overlayOpacity)},x=function(){a("#superbox-overlay").fadeOut(b.overlaySpeed,function(){a("#superbox-overlay").remove().unbind();
w();a("body").css({overflow:"auto"})})},u=function(c,d){page=o;move=!0;c==page&&(move=!1);dir=c>page?"n":"p";siz=Math.abs(c-page)*y;dir=="p"&&page==1&&(move=!1);dir=="n"&&page>=a(".superbox-page").size()&&(move=!1);move?(walk=(dir=="n"?"-":"+")+"="+siz,o=c,p=!1,c==1?a("#superbox-dock > .superbox-leftarrow").fadeTo("normal",0.1):a("#superbox-dock > .superbox-leftarrow").fadeTo("normal",1),c==a(".superbox-page").size()?a("#superbox-dock > .superbox-rightarrow").fadeTo("normal",0.1):a("#superbox-dock > .superbox-rightarrow").fadeTo("normal",
1),a(".superbox-pages").animate({left:walk},{easing:b.scrollDockEffect,duration:b.scrollSpeed,complete:function(){d!=void 0?g(d):e=!1}})):d!=void 0?g(d):e=!1},G=function(){a("#superbox-border").remove();els="#superbox-close, #superbox-buttonNext, #superbox-buttonPrev, #superbox-label";a.browser.msie?a(els).unbind().remove():a(els).unbind().fadeOut("fast",function(){a(els).remove()})},F=function(c,d){a("#superbox-image").size()&&(G(),coord=p!=!1?p:{left:a(window).width()/2,top:a(window).height()/2+a(document).scrollTop(),
width:0,height:0},a("#superbox-image").animate(coord,{easing:b.closeImageEffect,duration:b.zoomSpeed,complete:function(){a("#superbox-image").remove();h=!1;c!=void 0?g(c):E();d!=void 0&&n()}}))},n=function(){e=!0;a("#superbox-image").size()?F(void 0,!0):(E(),a("#superbox-dock").size()?(G(),a("#superbox-dock").fadeOut(b.overlaySpeed,function(){w();a(".superbox-arrowdock, .superbox-page > img").unbind();a("#superbox-dock").remove();x()})):x())}}})(jQuery,document);
