LightboxOptions=Object.extend({fileLoadingImage:"/images/lightbox/loading.gif",fileBottomNavCloseImage:"/images/lightbox/closelabel.gif",overlayOpacity:0.8,animate:true,resizeSpeed:7,borderSize:10,labelImage:"Изображение",labelOf:"из",labelClose:"Закрыть"},window.LightboxOptions||{});var Lightbox=Class.create();Lightbox.prototype={imageArray:[],activeImage:undefined,initialize:function(){this.updateImageList();this.keyboardAction=this.keyboardAction.bindAsEventListener(this);if(LightboxOptions.resizeSpeed>10){LightboxOptions.resizeSpeed=10}if(LightboxOptions.resizeSpeed<1){LightboxOptions.resizeSpeed=1}this.resizeDuration=LightboxOptions.animate?((11-LightboxOptions.resizeSpeed)*0.15):0;this.overlayDuration=LightboxOptions.animate?0.2:0;var d=(LightboxOptions.animate?250:1)+"px";var e=$$("body")[0];e.appendChild(Builder.node("div",{id:"overlay"}));e.appendChild(Builder.node("div",{id:"lightbox"},[Builder.node("div",{id:"outerImageContainer"},Builder.node("div",{id:"imageContainer"},[Builder.node("img",{id:"lightboxImage"}),Builder.node("div",{id:"hoverNav"},[Builder.node("a",{id:"prevLink",href:"#"}),Builder.node("a",{id:"nextLink",href:"#"})]),Builder.node("div",{id:"loading"},Builder.node("a",{id:"loadingLink",href:"#"},Builder.node("img",{src:LightboxOptions.fileLoadingImage})))])),Builder.node("div",{id:"imageDataContainer"},Builder.node("div",{id:"imageData"},[Builder.node("div",{id:"imageDetails"},[Builder.node("span",{id:"caption"}),Builder.node("span",{id:"numberDisplay"})]),Builder.node("div",{id:"bottomNav"},Builder.node("a",{id:"bottomNavClose",href:"#"},Builder.node("img",{src:LightboxOptions.fileBottomNavCloseImage})))]))]));$("overlay").hide().observe("click",(function(){this.end()}).bind(this));$("lightbox").hide().observe("click",(function(a){if(a.element().id=="lightbox"){this.end()}}).bind(this));$("outerImageContainer").setStyle({width:d,height:d});$("prevLink").observe("click",(function(a){a.stop();this.changeImage(this.activeImage-1)}).bindAsEventListener(this));$("nextLink").observe("click",(function(a){a.stop();this.changeImage(this.activeImage+1)}).bindAsEventListener(this));$("loadingLink").observe("click",(function(a){a.stop();this.end()}).bind(this));$("bottomNavClose").observe("click",(function(a){a.stop();this.end()}).bind(this));var f=this;(function(){var a="overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink imageDataContainer imageData imageDetails caption numberDisplay bottomNav bottomNavClose";$w(a).each(function(b){f[b]=$(b)})}).defer()},updateImageList:function(){this.updateImageList=Prototype.emptyFunction;document.observe("click",(function(d){var c=d.findElement("a[rel^=lightbox]")||d.findElement("area[rel^=lightbox]");if(c){d.stop();this.start(c)}}).bind(this))},start:function(i){$$("select","object","embed").each(function(a){a.style.visibility="hidden"});var l=this.getPageSize();$("overlay").setStyle({width:l[0]+"px",height:l[1]+"px"});new Effect.Appear(this.overlay,{duration:this.overlayDuration,from:0,to:LightboxOptions.overlayOpacity});this.imageArray=[];var g=0;if((i.rel=="lightbox")){this.imageArray.push([i.href,i.title])}else{this.imageArray=$$(i.tagName+'[href][rel="'+i.rel+'"]').collect(function(a){return[a.href,a.title]}).uniq();while(this.imageArray[g][0]!=i.href){g++}}var h=document.viewport.getScrollOffsets();var j=h[1]+(document.viewport.getHeight()/10);var k=h[0];this.lightbox.setStyle({top:j+"px",left:k+"px"}).show();this.changeImage(g)},changeImage:function(c){this.activeImage=c;if(LightboxOptions.animate){this.loading.show()}this.lightboxImage.hide();this.hoverNav.hide();this.prevLink.hide();this.nextLink.hide();this.imageDataContainer.setStyle({opacity:0.0001});this.numberDisplay.hide();var d=new Image();d.onload=(function(){this.lightboxImage.src=this.imageArray[this.activeImage][0];this.resizeImageContainer(d.width,d.height)}).bind(this);d.src=this.imageArray[this.activeImage][0]},resizeImageContainer:function(r,q){var o=this.outerImageContainer.getWidth();var t=this.outerImageContainer.getHeight();var p=(r+LightboxOptions.borderSize*2);var m=(q+LightboxOptions.borderSize*2);var l=(p/o)*100;var u=(m/t)*100;var n=o-p;var v=t-m;if(v!=0){new Effect.Scale(this.outerImageContainer,u,{scaleX:false,duration:this.resizeDuration,queue:"front"})}if(n!=0){new Effect.Scale(this.outerImageContainer,l,{scaleY:false,duration:this.resizeDuration,delay:this.resizeDuration})}var s=0;if((v==0)&&(n==0)){s=100;if(Prototype.Browser.IE){s=250}}(function(){this.prevLink.setStyle({height:q+"px"});this.nextLink.setStyle({height:q+"px"});this.imageDataContainer.setStyle({width:p+"px"});this.showImage()}).bind(this).delay(s/1000)},showImage:function(){this.loading.hide();new Effect.Appear(this.lightboxImage,{duration:this.resizeDuration,queue:"end",afterFinish:(function(){this.updateDetails()}).bind(this)});this.preloadNeighborImages()},updateDetails:function(){if(this.imageArray[this.activeImage][1]!=""){this.caption.update(this.imageArray[this.activeImage][1]).show()}if(this.imageArray.length>1){this.numberDisplay.update(LightboxOptions.labelImage+" "+(this.activeImage+1)+" "+LightboxOptions.labelOf+"  "+this.imageArray.length).show()}new Effect.Parallel([new Effect.SlideDown(this.imageDataContainer,{sync:true,duration:this.resizeDuration,from:0,to:1}),new Effect.Appear(this.imageDataContainer,{sync:true,duration:this.resizeDuration})],{duration:this.resizeDuration,afterFinish:(function(){var b=this.getPageSize();this.overlay.setStyle({height:b[1]+"px"});this.updateNav()}).bind(this)})},updateNav:function(){this.hoverNav.show();if(this.activeImage>0){this.prevLink.show()}if(this.activeImage<(this.imageArray.length-1)){this.nextLink.show()}this.enableKeyboardNav()},enableKeyboardNav:function(){document.observe("keydown",this.keyboardAction)},disableKeyboardNav:function(){document.stopObserving("keydown",this.keyboardAction)},keyboardAction:function(g){var f=g.keyCode;var e;if(g.DOM_VK_ESCAPE){e=g.DOM_VK_ESCAPE}else{e=27}var h=String.fromCharCode(f).toLowerCase();if(h.match(/x|o|c/)||(f==e)){this.end()}else{if((h=="p")||(f==37)){if(this.activeImage!=0){this.disableKeyboardNav();this.changeImage(this.activeImage-1)}}else{if((h=="n")||(f==39)){if(this.activeImage!=(this.imageArray.length-1)){this.disableKeyboardNav();this.changeImage(this.activeImage+1)}}}}},preloadNeighborImages:function(){var d,c;if(this.imageArray.length>this.activeImage+1){d=new Image();d.src=this.imageArray[this.activeImage+1][0]}if(this.activeImage>0){c=new Image();c.src=this.imageArray[this.activeImage-1][0]}},end:function(){this.disableKeyboardNav();this.lightbox.hide();new Effect.Fade(this.overlay,{duration:this.overlayDuration});$$("select","object","embed").each(function(b){b.style.visibility="visible"})},getPageSize:function(){var h,f;if(window.innerHeight&&window.scrollMaxY){h=window.innerWidth+window.scrollMaxX;f=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){h=document.body.scrollWidth;f=document.body.scrollHeight}else{h=document.body.offsetWidth;f=document.body.offsetHeight}}var e,g;if(self.innerHeight){if(document.documentElement.clientWidth){e=document.documentElement.clientWidth}else{e=self.innerWidth}g=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){e=document.documentElement.clientWidth;g=document.documentElement.clientHeight}else{if(document.body){e=document.body.clientWidth;g=document.body.clientHeight}}}if(f<g){pageHeight=g}else{pageHeight=f}if(h<e){pageWidth=h}else{pageWidth=e}return[pageWidth,pageHeight]}};document.observe("dom:loaded",function(){new Lightbox()});
