// -----------------------------------------------------------------------------------
//
//	Lightbox v2.04
//	by Lokesh Dhakar - http://www.lokeshdhakar.com
//	Last Modification: 2/9/08
//
//	For more information, visit:
//	http://lokeshdhakar.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//  	- Free for use in both personal and commercial projects
//		- Attribution requires leaving author name, author link, and the license info intact.
//	
//  Thanks: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.com), and Thomas Fuchs(mir.aculo.us) for ideas, libs, and snippets.
//  		Artemy Tregubenko (arty.name) for cleanup and help in updating to latest ver of proto-aculous.
//
// -----------------------------------------------------------------------------------
LightboxOptions=Object.extend({fileLoadingImage:"./skins/default/medias/loading.gif",fileBottomNavCloseImage:"./skins/default/medias/closelabel.gif",overlayOpacity:.8,animate:true,resizeSpeed:7,borderSize:10,labelImage:"Image",labelOf:"of"},window.LightboxOptions||{});var Lightbox=Class.create();Lightbox.prototype={imageArray:[],activeImage:undefined,initialize:function(){var c="click",i="bottomNavClose",h="loadingLink",g="nextLink",f="prevLink",e="outerImageContainer",d="lightbox",b="div",a=this;a.updateImageList();a.keyboardAction=a.keyboardAction.bindAsEventListener(a);if(LightboxOptions.resizeSpeed>10)LightboxOptions.resizeSpeed=10;if(LightboxOptions.resizeSpeed<1)LightboxOptions.resizeSpeed=1;a.resizeDuration=LightboxOptions.animate?(11-LightboxOptions.resizeSpeed)*.15:0;a.overlayDuration=LightboxOptions.animate?.2:0;var k=(LightboxOptions.animate?250:1)+"px",j=$$("body")[0];j.appendChild(Builder.node(b,{id:"overlay"}));j.appendChild(Builder.node(b,{id:d},[Builder.node(b,{id:e},Builder.node(b,{id:"imageContainer"},[Builder.node("img",{id:"lightboxImage"}),Builder.node(b,{id:"hoverNav"},[Builder.node("a",{id:f,href:"#"}),Builder.node("a",{id:g,href:"#"})]),Builder.node(b,{id:"loading"},Builder.node("a",{id:h,href:"#"},Builder.node("img",{src:LightboxOptions.fileLoadingImage})))])),Builder.node(b,{id:"imageDataContainer"},Builder.node(b,{id:"imageData"},[Builder.node(b,{id:"imageDetails"},[Builder.node("span",{id:"caption"}),Builder.node("span",{id:"numberDisplay"})]),Builder.node(b,{id:"bottomNav"},Builder.node("a",{id:i,href:"#"},Builder.node("img",{src:LightboxOptions.fileBottomNavCloseImage})))]))]));$("overlay").hide().observe(c,function(){this.end()}.bind(a));$(d).hide().observe(c,function(a){a.element().id==d&&this.end()}.bind(a));$(e).setStyle({width:k,height:k});$(f).observe(c,function(a){a.stop();this.changeImage(this.activeImage-1)}.bindAsEventListener(a));$(g).observe(c,function(a){a.stop();this.changeImage(this.activeImage+1)}.bindAsEventListener(a));$(h).observe(c,function(a){a.stop();this.end()}.bind(a));$(i).observe(c,function(a){a.stop();this.end()}.bind(a));var l=a;(function(){var a="overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink imageDataContainer imageData imageDetails caption numberDisplay bottomNav bottomNavClose";$w(a).each(function(a){l[a]=$(a)})}).defer()},updateImageList:function(){this.updateImageList=Prototype.emptyFunction;document.observe("click",function(a){var b=a.findElement("a[rel^=lightbox]")||a.findElement("area[rel^=lightbox]");if(b){a.stop();this.start(b)}}.bind(this))},start:function(b){var c="px",a=this;$$("select","object","embed").each(function(a){a.style.visibility="hidden"});var f=a.getPageSize();$("overlay").setStyle({width:f[0]+c,height:f[1]+c});new Effect.Appear(a.overlay,{duration:a.overlayDuration,from:0,to:LightboxOptions.overlayOpacity});a.imageArray=[];var d=0;if(b.rel=="lightbox")a.imageArray.push([b.href,b.title]);else{a.imageArray=$$(b.tagName+'[href][rel="'+b.rel+'"]').collect(function(a){return [a.href,a.title]}).uniq();while(a.imageArray[d][0]!=b.href)d++}var e=document.viewport.getScrollOffsets(),h=e[1]+document.viewport.getHeight()/10,g=e[0];a.lightbox.setStyle({top:h+c,left:g+c}).show();a.changeImage(d)},changeImage:function(c){var a=this;a.activeImage=c;LightboxOptions.animate&&a.loading.show();a.lightboxImage.hide();a.hoverNav.hide();a.prevLink.hide();a.nextLink.hide();a.imageDataContainer.setStyle({opacity:1e-4});a.numberDisplay.hide();var b=new Image;b.onload=function(){var a=this;a.lightboxImage.src=a.imageArray[a.activeImage][0];a.resizeImageContainer(b.width,b.height)}.bind(a);b.src=a.imageArray[a.activeImage][0]},resizeImageContainer:function(j,b){var a=this,f=a.outerImageContainer.getWidth(),e=a.outerImageContainer.getHeight(),c=j+LightboxOptions.borderSize*2,g=b+LightboxOptions.borderSize*2,k=c/f*100,l=g/e*100,i=f-c,h=e-g;h!=0&&new Effect.Scale(a.outerImageContainer,l,{scaleX:false,duration:a.resizeDuration,queue:"front"});i!=0&&new Effect.Scale(a.outerImageContainer,k,{scaleY:false,duration:a.resizeDuration,delay:a.resizeDuration});var d=0;if(h==0&&i==0){d=100;if(Prototype.Browser.IE)d=250}(function(){var a=this;a.prevLink.setStyle({height:b+"px"});a.nextLink.setStyle({height:b+"px"});a.imageDataContainer.setStyle({width:c+"px"});a.showImage()}).bind(a).delay(d/1e3)},showImage:function(){var a=this;a.loading.hide();new Effect.Appear(a.lightboxImage,{duration:a.resizeDuration,queue:"end",afterFinish:function(){this.updateDetails()}.bind(a)});a.preloadNeighborImages()},updateDetails:function(){var a=this;a.imageArray[a.activeImage][1]!=""&&a.caption.update(a.imageArray[a.activeImage][1]).show();a.imageArray.length>1&&a.numberDisplay.update(LightboxOptions.labelImage+" "+(a.activeImage+1)+" "+LightboxOptions.labelOf+"  "+a.imageArray.length).show();new Effect.Parallel([new Effect.SlideDown(a.imageDataContainer,{sync:true,duration:a.resizeDuration,from:0,to:1}),new Effect.Appear(a.imageDataContainer,{sync:true,duration:a.resizeDuration})],{duration:a.resizeDuration,afterFinish:function(){var a=this.getPageSize();this.overlay.setStyle({height:a[1]+"px"});this.updateNav()}.bind(a)})},updateNav:function(){var a=this;a.hoverNav.show();a.activeImage>0&&a.prevLink.show();a.activeImage<a.imageArray.length-1&&a.nextLink.show();a.enableKeyboardNav()},enableKeyboardNav:function(){document.observe("keydown",this.keyboardAction)},disableKeyboardNav:function(){document.stopObserving("keydown",this.keyboardAction)},keyboardAction:function(d){var a=this,b=d.keyCode,c;if(d.DOM_VK_ESCAPE)c=d.DOM_VK_ESCAPE;else c=27;var e=String.fromCharCode(b).toLowerCase();if(e.match(/x|o|c/)||b==c)a.end();else if(e=="p"||b==37){if(a.activeImage!=0){a.disableKeyboardNav();a.changeImage(a.activeImage-1)}}else if(e=="n"||b==39)if(a.activeImage!=a.imageArray.length-1){a.disableKeyboardNav();a.changeImage(a.activeImage+1)}},preloadNeighborImages:function(){var a=this,b,c;if(a.imageArray.length>a.activeImage+1){b=new Image;b.src=a.imageArray[a.activeImage+1][0]}if(a.activeImage>0){c=new Image;c.src=a.imageArray[a.activeImage-1][0]}},end:function(){var a=this;a.disableKeyboardNav();a.lightbox.hide();new Effect.Fade(a.overlay,{duration:a.overlayDuration});$$("select","object","embed").each(function(a){a.style.visibility="visible"})},getPageSize:function(){var c,d;if(window.innerHeight&&window.scrollMaxY){c=window.innerWidth+window.scrollMaxX;d=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){c=document.body.scrollWidth;d=document.body.scrollHeight}else{c=document.body.offsetWidth;d=document.body.offsetHeight}var a,b;if(self.innerHeight){if(document.documentElement.clientWidth)a=document.documentElement.clientWidth;else a=self.innerWidth;b=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){a=document.documentElement.clientWidth;b=document.documentElement.clientHeight}else if(document.body){a=document.body.clientWidth;b=document.body.clientHeight}if(d<b)pageHeight=b;else pageHeight=d;if(c<a)pageWidth=c;else pageWidth=a;return [pageWidth,pageHeight]}};document.observe("dom:loaded",function(){new Lightbox});
