var Lightbox={init:function(a){this.options=$extend({resizeSpeed:400,resizeTransition:false,initialWidth:250,initialHeight:250,animate:true,showCounter:true,overlayOpacity:0.8,allowSave:true,slideshowAutoplay:true,slideshowInterval:5000,slideshowAutoclose:false,lllImage:"Image",lllOf:"of"},a||{});this.options.resizeDuration=this.options.animate?this.options.resizeSpeed:0;this.anchors=[];$each(document.links,function(c){if(c.rel&&c.rel.test(/^lightbox/i)){c.onclick=this.click.pass(c,this);this.anchors.push(c)}},this);this.eventKeyDown=this.keyboardListener.bindWithEvent(this);this.eventPosition=this.position.bind(this);this.overlay=new Element("div",{id:"overlay"}).injectInside(document.body);this.center=new Element("div",{id:"sbCenter",styles:{width:this.options.initialWidth,height:this.options.initialHeight,marginLeft:-(this.options.initialWidth/2),display:"none"}}).injectInside(document.body);this.image=new Element("div",{id:"sbImage"}).injectInside(this.center);this.prevLink=new Element("a",{id:"prevLink",href:"#",styles:{display:"none"}}).injectInside(this.image);this.nextLink=this.prevLink.clone().setProperty("id","nextLink").injectInside(this.image);this.prevLink.onclick=this.previous.bind(this);this.nextLink.onclick=this.next.bind(this);this.bottomContainer=new Element("div",{id:"sbBottomContainer",styles:{display:"none"}}).injectInside(document.body);this.bottom=new Element("div",{id:"sbBottom"}).injectInside(this.bottomContainer);this.playLink=new Element("a",{id:"playLink",href:"#",styles:{display:"none"}}).injectInside(this.bottom);this.pauseLink=this.playLink.clone().setProperty("id","pauseLink").injectInside(this.bottom);this.playLink.onclick=this.play.bind(this);this.pauseLink.onclick=this.pause.bind(this);if(this.options.allowSave){this.saveLink=new Element("a",{id:"saveLink",href:"#"}).injectInside(this.bottom)}new Element("a",{id:"closeLink",href:"#"}).injectInside(this.bottom).onclick=this.overlay.onclick=this.close.bind(this);this.caption=new Element("div",{id:"sbCaption"}).injectInside(this.bottom);this.number=new Element("div",{id:"sbNumber"}).injectInside(this.bottom);this.present=new Element("div",{id:"sbPresent"}).injectInside(this.bottom);new Element("div",{styles:{clear:"both"}}).injectInside(this.bottom);var b=this.nextEffect.bind(this);this.fx={overlay:new Fx.Tween(this.overlay,{property:"opacity",duration:this.options.resizeDuration}).set(0),resize:new Fx.Morph(this.center,$extend({duration:this.options.resizeDuration,onComplete:b},this.options.resizeTransition?{transition:this.options.resizeTransition}:{})),image:new Fx.Tween(this.image,{property:"opacity",duration:this.options.resizeDuration,onComplete:b}),bottom:new Fx.Tween(this.bottom,{property:"margin-top",duration:this.options.resizeDuration,onComplete:b})};this.preloadPrev=new Image();this.preloadNext=new Image()},click:function(d){if(d.rel.length==8){return this.show(d.href,d.title)}var c,b,a=[];this.anchors.each(function(e){if(e.rel==d.rel){this.presentationMode=e.rel.test("present");this.slideshow=e.rel.test("slideshow");for(c=0;c<a.length;c++){if(a[c][0]==e.href){break}}if(c==a.length){var f=e.getChildren(".caption");a.push([e.href,e.title,e]);if(e.href==d.href){b=c}}}},this);if(this.slideshow){this.playLink.style.display="";this.pauseLink.style.display="";this.slideshowActive=this.options.slideshowAutoplay}else{this.playLink.style.display="none";this.pauseLink.style.display="none"}return this.open(a,b)},show:function(a,b){return this.open([[a,b]],0)},open:function(a,b){this.images=a;this.position();this.setup(true);this.top=window.getScrollTop()+(window.getHeight()/15);this.center.setStyles({top:this.top,display:""});this.fx.overlay.start(this.options.overlayOpacity);return this.changeImage(b)},position:function(){this.overlay.setStyles({top:window.getScrollTop(),height:window.getHeight()})},setup:function(a){var c=$A(document.getElementsByTagName("object"));c.extend(document.getElementsByTagName(window.ie?"select":"embed"));c.each(function(d){if(a){d.lbBackupStyle=d.style.visibility}d.style.visibility=a?"hidden":d.lbBackupStyle});var b=a?"addEvent":"removeEvent";window[b]("scroll",this.eventPosition)[b]("resize",this.eventPosition);document[b]("keydown",this.eventKeyDown);this.step=0},keyboardListener:function(a){switch(a.code){case 27:case 88:case 67:this.close();break;case 37:case 80:this.previous();break;case 39:case 78:this.next();break;case 83:if(this.slideshowActive){this.pause()}else{this.play()}}},previous:function(){this.pause();return this.changeImage(this.activeImage-1)},next:function(){this.pause();return this.changeImage(this.activeImage+1)},play:function(){this.slideshowActive=true;if(this.activeImage!=(this.images.length-1)){return this.changeImage(this.activeImage+1)}else{if(this.options.slideshowAutoclose){this.close()}else{return this.changeImage(0)}}},pause:function(){if(!this.slideshowActive){return false}this.slideshowTimer=$clear(this.slideshowTimer);this.slideshowActive=false;this.playLink.style.display="";this.pauseLink.style.display="none";return false},changeImage:function(a){if(this.step||(a<0)||(a>=this.images.length)){return false}this.step=1;this.activeImage=a;this.bottomContainer.style.display=this.prevLink.style.display=this.nextLink.style.display="none";this.fx.image.set(0);this.center.className="sbLoading";this.preload=new Image();this.preload.onload=this.nextEffect.bind(this);this.preload.src=this.images[a][0];return false},nextEffect:function(){switch(this.step++){case 1:this.center.className="";this.image.style.backgroundImage="url("+this.images[this.activeImage][0]+")";this.image.style.width=this.bottom.style.width=this.preload.width+"px";this.image.style.height=this.prevLink.style.height=this.nextLink.style.height=this.preload.height+"px";var c=this.images[this.activeImage][2].getChildren(".tx-photocontest-pi1-list-item-image-caption");if(c.length>0){this.caption.style.display="";this.caption.set("html",c.get("html"));txPhotocontestVoting.init(this.caption.getChildren("ul.tx-photocontest-pi1-list-voting"))}else{if(this.images[this.activeImage][1]){this.caption.style.display="";this.caption.set("html",this.images[this.activeImage][1])}else{this.caption.style.display="none";this.caption.set("html","")}}if(!this.options.showCounter||(this.images.length==1)||this.presentationMode){this.number.style.display="none";this.caption.set("html","")}else{this.number.style.display="";this.number.set("html",this.options.lllImage+" "+(this.activeImage+1)+" "+this.options.lllOf+" "+this.images.length)}this.present.style.display="none";this.present.empty();if(this.presentationMode){this.present.style.display="";for(var a=1;a<=(this.images.length);a++){var b=this.activeImage==(a-1)?"act":"no";this.presentLink=new Element("a",{id:"pmi"+a+"",href:"#","class":b}).injectInside(this.present);this.presentLink.set("html","");this.presentLink.onclick=this.changeImage.bind(this,(a-1));this.presentLink.addEvent("click",function(){Lightbox.pause()})}}if(this.options.allowSave){this.saveLink.set({href:this.images[this.activeImage][0],target:"_blank"})}if(this.slideshow){if(this.slideshowActive){this.playLink.style.display="none";this.pauseLink.style.display=""}else{this.playLink.style.display="";this.pauseLink.style.display="none"}}if(this.activeImage){this.preloadPrev.src=this.images[this.activeImage-1][0]}if(this.activeImage!=(this.images.length-1)){this.preloadNext.src=this.images[this.activeImage+1][0]}if(this.center.clientHeight!=this.image.offsetHeight){this.fx.resize.start({height:this.image.offsetHeight});break}this.step++;case 2:if(this.center.clientWidth!=this.image.offsetWidth){this.fx.resize.start({width:this.image.offsetWidth,marginLeft:-this.image.offsetWidth/2});break}this.step++;case 3:this.bottomContainer.setStyles({top:this.top+this.center.clientHeight,height:0,marginLeft:this.center.style.marginLeft,display:""});this.fx.image.start(1);break;case 4:if(this.options.animate){this.fx.bottom.set(-this.bottom.offsetHeight);this.bottomContainer.style.height="";this.fx.bottom.start(0);break}this.bottomContainer.style.height="";case 5:if(this.activeImage){this.prevLink.style.display=""}if(this.activeImage!=(this.images.length-1)){this.nextLink.style.display=""}if(this.slideshowActive){if(this.activeImage!=(this.images.length-1)){this.slideshowTimer=this.changeImage.delay(this.options.slideshowInterval,Lightbox,this.activeImage+1)}else{if(this.options.slideshowAutoclose){this.slideshowTimer=this.close.delay(this.options.slideshowInterval,Lightbox)}else{this.pause()}}}this.step=0}},close:function(){this.slideshowTimer=$clear(this.slideshowTimer);this.slideshowActive=false;if(this.step<0){return}this.step=-1;if(this.preload){this.preload.onload=new Class();this.preload=null}for(var a in this.fx){this.fx[a].cancel()}this.center.style.display=this.bottomContainer.style.display="none";this.fx.overlay.chain(this.setup.pass(false,this)).start(0);return false}};