/*  ----------------------------------------------------------------------
 *  This is a compressed and slightly modified version of:
 * 	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:BM.assetsDir+"/lightbox_loading.gif",fileBottomNavCloseImage:BM.assetsDir+"/lightbox_close.gif",overlayOpacity:0.8,animate:true,resizeSpeed:9,borderSize:10,labelImage:"",labelOf:"/"},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 _1=(LightboxOptions.animate?250:1)+"px";
var _2=$$("body")[0];
_2.appendChild(Builder.node("div",{id:"bmlbox_overlay"}));
_2.appendChild(Builder.node("div",{id:"bmlbox_lightbox"},[Builder.node("div",{id:"bmlbox_outerImageContainer"},Builder.node("div",{id:"bmlbox_imageContainer"},[Builder.node("img",{id:"bmlbox_lightboxImage"}),Builder.node("div",{id:"bmlbox_hoverNav"},[Builder.node("a",{id:"bmlbox_prevLink",href:"#"}),Builder.node("a",{id:"bmlbox_nextLink",href:"#"})]),Builder.node("div",{id:"bmlbox_loading"},Builder.node("a",{id:"bmlbox_loadingLink",href:"#"},Builder.node("img",{src:LightboxOptions.fileLoadingImage})))])),Builder.node("div",{id:"bmlbox_imageDataContainer"},Builder.node("div",{id:"bmlbox_imageData"},[Builder.node("div",{id:"bmlbox_imageDetails"},[Builder.node("span",{id:"bmlbox_caption"}),Builder.node("span",{id:"bmlbox_numberDisplay"})]),Builder.node("div",{id:"bmlbox_bottomNav"},Builder.node("a",{id:"bmlbox_bottomNavClose",href:"#"},Builder.node("img",{src:LightboxOptions.fileBottomNavCloseImage})))]))]));
$("bmlbox_overlay").hide().observe("click",(function(){
this.end();
}).bind(this));
$("bmlbox_lightbox").hide().observe("click",(function(_3){
if(_3.element().id=="bmlbox_lightbox"){
this.end();
}
}).bind(this));
$("bmlbox_outerImageContainer").setStyle({width:_1,height:_1});
$("bmlbox_prevLink").observe("click",(function(_4){
_4.stop();
this.changeImage(this.activeImage-1);
}).bindAsEventListener(this));
$("bmlbox_nextLink").observe("click",(function(_5){
_5.stop();
this.changeImage(this.activeImage+1);
}).bindAsEventListener(this));
$("bmlbox_loadingLink").observe("click",(function(_6){
_6.stop();
this.end();
}).bind(this));
$("bmlbox_bottomNavClose").observe("click",(function(_7){
_7.stop();
this.end();
}).bind(this));
[$("bmlbox_prevLink"),$("bmlbox_nextLink")].each(function(e){
e.setOpacity(0.3);
e.onmouseover=function(){
e.setOpacity(0.99);
};
e.onmouseout=function(){
e.setOpacity(0.3);
};
});
var th=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(id){
th[id]=$("bmlbox_"+id);
});
}).defer();
},updateImageList:function(){
this.updateImageList=Prototype.emptyFunction;
document.observe("click",(function(_c){
var _d=_c.findElement("a[rel^=bm_lightbox]")||_c.findElement("area[rel^=bm_lightbox]");
if(_d){
_c.stop();
this.start(_d);
}
}).bind(this));
},start:function(_e){
$$("select","object","embed").each(function(_f){
_f.style.visibility="hidden";
});
var _10=this.getPageSize();
$("bmlbox_overlay").setStyle({width:_10[0]+"px",height:_10[1]+"px"});
new Effect.Appear(this.overlay,{duration:this.overlayDuration,from:0,to:LightboxOptions.overlayOpacity});
this.imageArray=[];
var _11=0;
if((_e.rel=="bm_lightbox")){
this.imageArray.push([_e.href,_e.title]);
}else{
this.imageArray=$$(_e.tagName+"[href][rel=\""+_e.rel+"\"]").collect(function(_12){
return [_12.href,_12.title];
}).uniq();
while(this.imageArray[_11][0]!=_e.href){
_11++;
}
}
this.hovernavHeight=this.imageArray.length>1?35:0;
this.lightboxImage.style.marginTop=this.hovernavHeight+"px";
this.hoverNav.style.height=this.hovernavHeight?"100%":"0px";
var _13=document.viewport.getScrollOffsets();
var _14=_13[1]+(document.viewport.getHeight()/30);
var _15=_13[0];
this.lightbox.setStyle({top:_14+"px",left:_15+"px"}).show();
this.changeImage(_11);
},changeImage:function(_16){
this.activeImage=_16;
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 _17=new Image();
_17.onload=(function(){
this.lightboxImage.src=this.imageArray[this.activeImage][0];
this.lightboxImage.setStyle({width:'auto'});
this.lightboxImage.setStyle({height:'auto'});
this.resizeImageContainer(_17.width,_17.height);
}).bind(this);
_17.src=this.imageArray[this.activeImage][0];
},resizeImageContainer:function(_18,_19){
var _1a=this.outerImageContainer.getWidth();
var _1b=this.outerImageContainer.getHeight();
var _1c=(_18+LightboxOptions.borderSize*2);
var _1d=(_19+LightboxOptions.borderSize*2);
_1d=_1d+this.hovernavHeight;
var _1e=(_1c/_1a)*100;
var _1f=(_1d/_1b)*100;
var _20=_1a-_1c;
var _21=_1b-_1d;
if(_21!=0){
new Effect.Scale(this.outerImageContainer,_1f,{scaleX:false,duration:this.resizeDuration,queue:"front"});
}
if(_20!=0){
new Effect.Scale(this.outerImageContainer,_1e,{scaleY:false,duration:this.resizeDuration});
}
var _22=0;
if((_21==0)&&(_20==0)){
_22=100;
if(Prototype.Browser.IE){
_22=250;
}
}
(function(){
this.prevLink.setStyle({height:_19+"px"});
this.nextLink.setStyle({height:_19+"px"});
this.imageDataContainer.setStyle({width:_1c+"px"});
this.showImage();
}).bind(this).delay(_22/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 _23=this.getPageSize();
this.overlay.setStyle({height:_23[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(_24){
var _25=_24.keyCode;
var _26;
if(_24.DOM_VK_ESCAPE){
_26=_24.DOM_VK_ESCAPE;
}else{
_26=27;
}
var key=String.fromCharCode(_25).toLowerCase();
if(key.match(/x|o|c/)||(_25==_26)){
this.end();
}else{
if((key=="p")||(_25==37)){
if(this.activeImage!=0){
this.disableKeyboardNav();
this.changeImage(this.activeImage-1);
}
}else{
if((key=="n")||(_25==39)){
if(this.activeImage!=(this.imageArray.length-1)){
this.disableKeyboardNav();
this.changeImage(this.activeImage+1);
}
}
}
}
},preloadNeighborImages:function(){
var _28,preloadPrevImage;
if(this.imageArray.length>this.activeImage+1){
_28=new Image();
_28.src=this.imageArray[this.activeImage+1][0];
}
if(this.activeImage>0){
preloadPrevImage=new Image();
preloadPrevImage.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(_29){
_29.style.visibility="visible";
});
},getPageSize:function(){
var _2a,yScroll;
if(window.innerHeight&&window.scrollMaxY){
_2a=window.innerWidth+window.scrollMaxX;
yScroll=window.innerHeight+window.scrollMaxY;
}else{
if(document.body.scrollHeight>document.body.offsetHeight){
_2a=document.body.scrollWidth;
yScroll=document.body.scrollHeight;
}else{
_2a=document.body.offsetWidth;
yScroll=document.body.offsetHeight;
}
}
var _2b,windowHeight;
if(self.innerHeight){
if(document.documentElement.clientWidth){
_2b=document.documentElement.clientWidth;
}else{
_2b=self.innerWidth;
}
windowHeight=self.innerHeight;
}else{
if(document.documentElement&&document.documentElement.clientHeight){
_2b=document.documentElement.clientWidth;
windowHeight=document.documentElement.clientHeight;
}else{
if(document.body){
_2b=document.body.clientWidth;
windowHeight=document.body.clientHeight;
}
}
}
if(yScroll<windowHeight){
pageHeight=windowHeight;
}else{
pageHeight=yScroll;
}
if(_2a<_2b){
pageWidth=_2a;
}else{
pageWidth=_2b;
}
return [pageWidth,pageHeight];
}};
if (Prototype.Browser.IE) {
Event.observe(window,'load', function(){new Lightbox();});
}
else {
Event.observe(document,"dom:loaded", function(){new Lightbox();});
}
