var Lightbox={init:function(I){var l=this;l.options=$extend({resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,animateCaption:true,showCounter:true},I||{});document.body.scroll="yes";l.anchors=[];$each(document.links,function(i){var I=this;if(i.rel&&i.rel.test(/^lightbox/i)){i.onclick=I.click.pass(i,I);I.anchors.push(i)}},l);l.eventKeyDown=l.keyboardListener.bindAsEventListener(l);l.eventPosition=l.position.bind(l);l.overlay=new Element('div',{'id':'lbOverlay'}).injectInside(document.body);l.center=new Element('div',{'id':'lbCenter','styles':{'width':l.options.initialWidth,'height':l.options.initialHeight,'marginLeft':-(l.options.initialWidth/2),'display':'none'}}).injectInside(document.body);l.image=new Element('div',{'id':'lbImage'}).injectInside(l.center);l.prevLink=new Element('a',{'id':'lbPrevLink','href':'#','styles':{'display':'none'}}).injectInside(l.image);l.nextLink=l.prevLink.clone().setProperty('id','lbNextLink').injectInside(l.image);l.prevLink.onclick=l.previous.bind(l);l.nextLink.onclick=l.next.bind(l);l.bottomContainer=new Element('div',{'id':'lbBottomContainer','styles':{'display':'none'}}).injectInside(document.body);l.bottom=new Element('div',{'id':'lbBottom'}).injectInside(l.bottomContainer);new Element('a').setProperties({id:'lbCloseLink',href:'#'}).injectInside(l.bottom).onclick=l.close.bind(l);l.caption=new Element('div',{'id':'lbCaption'}).injectInside(l.bottom);l.number=new Element('div',{'id':'lbNumber'}).injectInside(l.bottom);new Element('div',{'styles':{'clear':'both'}}).injectInside(l.bottom);var i=l.nextEffect.bind(l);l.fx={overlay:l.overlay.effect('opacity',{duration:500}).hide(),resize:l.center.effects($extend({duration:l.options.resizeDuration,onComplete:i},l.options.resizeTransition?{transition:l.options.resizeTransition}:{})),image:l.image.effect('opacity',{duration:500,onComplete:i}),bottom:l.bottom.effect('margin-top',{duration:400,onComplete:i})};l.preloadPrev=new Image;l.preloadNext=new Image},click:function(I){var O=this;if(I.rel.length==8)return O.show(I.href,I.title);var o,i,l=[];O.anchors.each(function(O){if(O.rel==I.rel){for(o=0;o<l.length;o++)if(l[o][0]==O.href)break;if(o==l.length){l.push([O.href,O.title]);if(O.href==I.href)i=o}}},O);return O.open(l,i)},show:function(I,i){return this.open([[I,i]],0)},open:function(I,i){var l=this;document.body.scroll="no";l.images=I;l.setup(true);l.top=window.getScrollTop()+(window.getHeight()/15);l.center.setStyles({top:l.top,display:''});l.fx.overlay.start(0.8);document.body.scroll="no";return l.changeImage(i)},position:function(){},setup:function(i){var l=this,I=i?'addEvent':'removeEvent';window[I]('scroll',l.eventPosition)[I]('resize',l.eventPosition);document[I]('keydown',l.eventKeyDown);l.step=0},keyboardListener:function(i){var I=this;switch(i.keyCode){case 27:case 88:case 67:I.close();break;case 37:case 80:I.previous();break;case 39:case 78:I.next()}},previous:function(){var i=this;return i.changeImage(i.activeImage-1)},next:function(){var i=this;return i.changeImage(i.activeImage+1)},changeImage:function(i){var I=this;if(I.step||(i<0)||(i>=I.images.length))return false;I.step=1;I.activeImage=i;I.bottomContainer.style.display=I.prevLink.style.display=I.nextLink.style.display='none';I.fx.image.hide();I.center.className='lbLoading';I.preload=new Image;I.preload.onload=I.nextEffect.bind(I);I.preload.src=I.images[i][0];return false},nextEffect:function(){var i=this;switch(i.step++){case 1:i.center.className='';i.image.style.backgroundImage='url('+i.images[i.activeImage][0]+')';i.image.style.width=i.bottom.style.width=i.preload.width+'px';i.image.style.height=i.prevLink.style.height=i.nextLink.style.height=i.preload.height+'px';i.caption.setHTML(i.images[i.activeImage][1]||'');i.number.setHTML((!i.options.showCounter||(i.images.length==1))?'':'Image '+(i.activeImage+1)+' of '+i.images.length);if(i.activeImage)i.preloadPrev.src=i.images[i.activeImage-1][0];if(i.activeImage!=(i.images.length-1))i.preloadNext.src=i.images[i.activeImage+1][0];if(i.center.clientHeight!=i.image.offsetHeight){i.fx.resize.start({height:i.image.offsetHeight});break}
i.step++;case 2:if(i.center.clientWidth!=i.image.offsetWidth){i.fx.resize.start({width:i.image.offsetWidth,marginLeft:-i.image.offsetWidth/2});break}
i.step++;case 3:i.bottomContainer.setStyles({top:i.top+i.center.clientHeight,height:0,marginLeft:i.center.style.marginLeft,display:''});i.fx.image.start(1);break;case 4:if(i.options.animateCaption){i.fx.bottom.set(-i.bottom.offsetHeight);i.bottomContainer.style.height='';i.fx.bottom.start(0);break}
i.bottomContainer.style.height='';case 5:if(i.activeImage)i.prevLink.style.display='';if(i.activeImage!=(i.images.length-1))i.nextLink.style.display='';i.step=0}},close:function(){var i=this;if(i.step<0)return;i.step=-1;if(i.preload){i.preload.onload=Class.empty;i.preload=null}
for(var I in i.fx)i.fx[I].stop();i.center.style.display=i.bottomContainer.style.display='none';i.fx.overlay.chain(i.setup.pass(false,i)).start(0);if(document.all){document.body.scroll="yes"}else{document.body.style.overflow='auto'}
return false}};window.addEvent('domready',Lightbox.init.bind(Lightbox));