// ColorBox v1.3.6 - a full featured, light-weight, customizable lightbox based on jQuery 1.3 c) 2009 Jack Moore - www.colorpowered.com - jack@colorpowered.com Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
(function(c){function q(b,d){d=d==="x"?m.width():m.height();return typeof b==="string"?Math.round(b.match(/%/)?d/100*parseInt(b,10):parseInt(b,10)):b}function L(b){b=c.isFunction(b)?b.call(i):b;return a.photo||b.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i)}function X(){for(var b in a)if(c.isFunction(a[b])&&b.substring(0,2)!=="on")a[b]=a[b].call(i);a.rel=a.rel||i.rel;a.href=a.href||i.href;a.title=a.title||i.title}function Y(b){i=b;a=c(i).data(p);X();if(a.rel&&a.rel!=="nofollow"){g=c(".cboxElement").filter(function(){return(c(this).data(p).rel||this.rel)===a.rel});j=g.index(i);if(j<0){g=g.add(i);j=g.length-1}}else{g=c(i);j=0}if(!A){B=A=true;M=i;M.blur();c(document).bind("keydown.cbox_close",function(d){if(d.keyCode===27){d.preventDefault();e.close()}}).bind("keydown.cbox_arrows",function(d){if(g.length>1)if(d.keyCode===37){d.preventDefault();C.click()}else if(d.keyCode===39){d.preventDefault();D.click()}});a.overlayClose&&r.css({cursor:"pointer"}).one("click",e.close);c.event.trigger($);a.onOpen&&a.onOpen.call(i);r.css({opacity:a.opacity}).show();a.w=q(a.initialWidth,"x");a.h=q(a.initialHeight,"y");e.position(0);N&&m.bind("resize.cboxie6 scroll.cboxie6",function(){r.css({width:m.width(),height:m.height(),top:m.scrollTop(),left:m.scrollLeft()})}).trigger("scroll.cboxie6")}O.add(C).add(D).add(s).add(P).hide();Q.html(a.close).show();e.slideshow();e.load()}var p="colorbox",E="hover",e,w=c.browser.msie&&!c.support.opacity,N=w&&c.browser.version<7,$="cbox_open",G="cbox_load",R="cbox_complete",S="resize.cbox_resize",r,k,t,o,T,U,V,W,g,m,l,H,I,J,P,O,s,D,C,Q,x,y,u,v,i,M,j,a,A,B,Z={transition:"elastic",speed:350,width:false,height:false,innerWidth:false,innerHeight:false,initialWidth:"400",initialHeight:"400",maxWidth:false,maxHeight:false,scalePhotos:true,scrolling:true,inline:false,html:false,iframe:false,photo:false,href:false,title:false,rel:false,opacity:0.9,preloading:true,current:"изображение {current} из {total}",previous:"Пред.",next:"След.",close:"закрыть",open:false,overlayClose:true,slideshow:false,slideshowAuto:false,slideshowSpeed:4E3,slideshowStart:"запустить слайд-шоу",slideshowStop:"остановить слайд-шоу",onOpen:false,onLoad:false,onComplete:false,onCleanup:false,onClosed:false};e=c.fn.colorbox=function(b,d){var h=this;if(!h.length)if(h.selector===""){h=c("<a/>");b.open=true}else return this;h.each(function(){var f=c.extend({},c(this).data(p)?c(this).data(p):Z,b);c(this).data(p,f).addClass("cboxElement");if(d)c(this).data(p).onComplete=d});b&&b.open&&Y(h);return this};e.init=function(){function b(d){return c('<div id="cbox'+d+'"/>')}m=c(window);k=c('<div id="colorbox"/>');r=b("Overlay").hide();t=b("Wrapper");o=b("Content").append(l=b("LoadedContent").css({width:0,height:0}),I=b("LoadingOverlay"),J=b("LoadingGraphic"),P=b("Title"),O=b("Current"),s=b("Slideshow"),D=b("Next"),C=b("Previous"),Q=b("Close"));t.append(c("<div/>").append(b("TopLeft"),T=b("TopCenter"),b("TopRight")),c("<div/>").append(U=b("MiddleLeft"),o,V=b("MiddleRight")),c("<div/>").append(b("BottomLeft"),W=b("BottomCenter"),b("BottomRight"))).children().children().css({"float":"left"});H=c("<div style='position:absolute; top:0; left:0; width:9999px; height:0;'/>");c("body").prepend(r,k.append(t,H));if(w){k.addClass("cboxIE");N&&r.css("position","absolute")}o.children().bind("mouseover mouseout",function(){c(this).toggleClass(E)}).addClass(E);x=T.height()+W.height()+o.outerHeight(true)-o.height();y=U.width()+V.width()+o.outerWidth(true)-o.width();u=l.outerHeight(true);v=l.outerWidth(true);k.css({"padding-bottom":x,"padding-right":y}).hide();D.click(e.next);C.click(e.prev);Q.click(e.close);o.children().removeClass(E);c(".cboxElement").live("click",function(d){if(d.button!==0&&typeof d.button!=="undefined")return true;else{Y(this);return false}})};e.position=function(b,d){function h(z){T[0].style.width=W[0].style.width=o[0].style.width=z.style.width;J[0].style.height=I[0].style.height=o[0].style.height=U[0].style.height=V[0].style.height=z.style.height}var f=m.height();f=Math.max(f-a.h-u-x,0)/2+m.scrollTop();var n=Math.max(document.documentElement.clientWidth-a.w-v-y,0)/2+m.scrollLeft();b=k.width()===a.w+v&&k.height()===a.h+u?0:b;t[0].style.width=t[0].style.height="9999px";k.dequeue().animate({width:a.w+v,height:a.h+u,top:f,left:n},{duration:b,complete:function(){h(this);B=false;t[0].style.width=a.w+v+y+"px";t[0].style.height=a.h+u+x+"px";d&&d()},step:function(){h(this)}})};e.resize=function(b){function d(){a.w=a.w||l.width();a.w=a.mw&&a.mw<a.w?a.mw:a.w;return a.w}function h(){a.h=a.h||l.height();a.h=a.mh&&a.mh<a.h?a.mh:a.h;return a.h}function f(F){e.position(F,function(){if(A){if(w){z&&l.fadeIn(100);k[0].style.removeAttribute("filter")}if(a.iframe)l.append("<iframe id='cboxIframe'"+(a.scrolling?" ":"scrolling='no'")+" name='iframe_"+(new Date).getTime()+"' frameborder=0 src='"+a.href+"' "+(w?"allowtransparency='true'":"")+" />");l.show();P.show().html(a.title);if(g.length>1){O.html(a.current.replace(/\{current\}/,j+1).replace(/\{total\}/,g.length)).show();D.html(a.next).show();C.html(a.previous).show();a.slideshow&&s.show()}I.hide();J.hide();c.event.trigger(R);a.onComplete&&a.onComplete.call(i);a.transition==="fade"&&k.fadeTo(K,1,function(){w&&k[0].style.removeAttribute("filter")});m.bind(S,function(){e.position(0)})}})}if(A){var n,z,K=a.transition==="none"?0:a.speed;m.unbind(S);if(b){l.remove();l=c('<div id="cboxLoadedContent"/>').html(b);l.hide().appendTo(H).css({width:d(),overflow:a.scrolling?"auto":"hidden"}).css({height:h()}).prependTo(o);c("#cboxPhoto").css({cssFloat:"none"});N&&c("select:not(#colorbox select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("cbox_cleanup",function(){this.style.visibility="inherit"});a.transition==="fade"&&k.fadeTo(K,0,function(){f(0)})||f(K);if(a.preloading&&g.length>1){b=j>0?g[j-1]:g[g.length-1];n=j<g.length-1?g[j+1]:g[0];n=c(n).data(p).href||n.href;b=c(b).data(p).href||b.href;L(n)&&c("<img />").attr("src",n);L(b)&&c("<img />").attr("src",b)}}else setTimeout(function(){var F=l.wrapInner("<div style='overflow:auto'></div>").children();a.h=F.height();l.css({height:a.h});F.replaceWith(F.children());e.position(K)},1)}};e.load=function(){var b,d,h,f=e.resize;B=true;i=g[j];a=c(i).data(p);X();c.event.trigger(G);a.onLoad&&a.onLoad.call(i);a.h=a.height?q(a.height,"y")-u-x:a.innerHeight?q(a.innerHeight,"y"):false;a.w=a.width?q(a.width,"x")-v-y:a.innerWidth?q(a.innerWidth,"x"):false;a.mw=a.w;a.mh=a.h;if(a.maxWidth){a.mw=q(a.maxWidth,"x")-v-y;a.mw=a.w&&a.w<a.mw?a.w:a.mw}if(a.maxHeight){a.mh=q(a.maxHeight,"y")-u-x;a.mh=a.h&&a.h<a.mh?a.h:a.mh}b=a.href;I.show();J.show();if(a.inline){c('<div id="cboxInlineTemp" />').hide().insertBefore(c(b)[0]).bind(G+" cbox_cleanup",function(){c(this).replaceWith(l.children())});f(c(b))}else if(a.iframe)f(" ");else if(a.html)f(a.html);else if(L(b)){d=new Image;d.onload=function(){var n;d.onload=null;d.id="cboxPhoto";c(d).css({margin:"auto",border:"none",display:"block",cssFloat:"left"});if(a.scalePhotos){h=function(){d.height-=d.height*n;d.width-=d.width*n};if(a.mw&&d.width>a.mw){n=(d.width-a.mw)/d.width;h()}if(a.mh&&d.height>a.mh){n=(d.height-a.mh)/d.height;h()}}if(a.h)d.style.marginTop=Math.max(a.h-d.height,0)/2+"px";f(d);g.length>1&&c(d).css({cursor:"pointer"}).click(e.next);if(w)d.style.msInterpolationMode="bicubic"};d.src=b}else c("<div />").appendTo(H).load(b,function(n,z){z==="success"?f(this):f(c("<p>Request unsuccessful.</p>"))})};e.next=function(){if(!B){j=j<g.length-1?j+1:0;e.load()}};e.prev=function(){if(!B){j=j>0?j-1:g.length-1;e.load()}};e.slideshow=function(){function b(){s.text(a.slideshowStop).bind(R,function(){h=setTimeout(e.next,a.slideshowSpeed)}).bind(G,function(){clearTimeout(h)}).one("click",function(){d();c(this).removeClass(E)});k.removeClass(f+"off").addClass(f+"on")}var d,h,f="cboxSlideshow_";s.bind("cbox_closed",function(){s.unbind();clearTimeout(h);k.removeClass(f+"off "+f+"on")});d=function(){clearTimeout(h);s.text(a.slideshowStart).unbind(R+" "+G).one("click",function(){b();h=setTimeout(e.next,a.slideshowSpeed);c(this).removeClass(E)});k.removeClass(f+"on").addClass(f+"off")};if(a.slideshow&&g.length>1)a.slideshowAuto?b():d()};e.close=function(){c.event.trigger("cbox_cleanup");a.onCleanup&&a.onCleanup.call(i);A=false;c(document).unbind("keydown.cbox_close keydown.cbox_arrows");m.unbind(S+" resize.cboxie6 scroll.cboxie6");r.css({cursor:"auto"}).fadeOut("fast");k.stop(true,false).fadeOut("fast",function(){c("#colorbox iframe").attr("src","about:blank");l.remove();k.css({opacity:1});try{M.focus()}catch(b){}c.event.trigger("cbox_closed");a.onClosed&&a.onClosed.call(i)})};e.element=function(){return c(i)};e.settings=Z;c(e.init)})(jQuery);
