/*
	Slimbox v1.7 - The ultimate lightweight Lightbox clone
	(c) 2007-2009 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
var Slimbox=(function(){
var _1=window,_2=Browser.Engine.trident4,_3,_4,_5=-1,_6,_7,_8,_9,_a,_b,_c,_d={},_e=new Image(),_f=new Image(),_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_1a,_1b,_1c,_1d;
_1.addEvent("domready",function(){
$(document.body).adopt($$(_10=new Element("div",{id:"lbOverlay",events:{click:_1e}}),_11=new Element("div",{id:"lbCenter"}),_16=new Element("div",{id:"lbBottomContainer"})).setStyle("display","none"));
_12=new Element("div",{id:"lbImage"}).injectInside(_11).adopt(_13=new Element("div",{styles:{position:"relative"}}).adopt(_14=new Element("a",{id:"lbPrevLink",href:"#",events:{click:_1f}}),_15=new Element("a",{id:"lbNextLink",href:"#",events:{click:_20}})));
_17=new Element("div",{id:"lbBottom"}).injectInside(_16).adopt(new Element("a",{id:"lbCloseLink",href:"#",events:{click:_1e}}),_18=new Element("div",{id:"lbCaption"}),_19=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}));
});
function _21(){
var _22=_1.getScroll(),_23=_1.getSize();
$$(_11,_16).setStyle("left",_22.x+(_23.x/2));
if(_9){
_10.setStyles({left:_22.x,top:_22.y,width:_23.x,height:_23.y});
}
};
function _24(_25){
["object",_2?"select":"embed"].forEach(function(tag){
Array.forEach(document.getElementsByTagName(tag),function(el){
if(_25){
el._slimbox=el.style.visibility;
}
el.style.visibility=_25?"hidden":el._slimbox;
});
});
_10.style.display=_25?"":"none";
var fn=_25?"addEvent":"removeEvent";
_1[fn]("scroll",_21)[fn]("resize",_21);
document[fn]("keydown",_29);
};
function _29(_2a){
var _2b=_2a.code;
return _3.closeKeys.contains(_2b)?_1e():_3.nextKeys.contains(_2b)?_20():_3.previousKeys.contains(_2b)?_1f():false;
};
function _1f(){
return _2c(_7);
};
function _20(){
return _2c(_8);
};
function _2c(_2d){
if(_2d>=0){
_5=_2d;
_6=_4[_2d][0];
_7=(_5||(_3.loop?_4.length:0))-1;
_8=((_5+1)%_4.length)||(_3.loop?0:-1);
_2e();
_11.className="lbLoading";
_d=new Image();
_d.onload=_2f;
_d.src=_6;
}
return false;
};
function _2f(){
_11.className="";
_1c.set(0);
_12.setStyles({backgroundImage:"url("+_6+")",display:""});
_13.setStyle("width",_d.width);
$$(_13,_14,_15).setStyle("height",_d.height);
_18.set("html",_4[_5][1]||"");
_19.set("html",(((_4.length>1)&&_3.counterText)||"").replace(/{x}/,_5+1).replace(/{y}/,_4.length));
if(_7>=0){
_e.src=_4[_7][0];
}
if(_8>=0){
_f.src=_4[_8][0];
}
_b=_12.offsetWidth;
_c=_12.offsetHeight;
var top=Math.max(0,_a-(_c/2)),_31=0,fn;
if(_11.offsetHeight!=_c){
_31=_1b.start({height:_c,top:top});
}
if(_11.offsetWidth!=_b){
_31=_1b.start({width:_b,marginLeft:-_b/2});
}
fn=function(){
_16.setStyles({width:_b,top:top,marginLeft:-_b/2,visibility:"visible",display:""});
_1c.start(1);
};
if(_31){
_1b.chain(fn);
}else{
fn();
}
};
function _33(){
if(_7>=0){
_14.style.display="";
}
if(_8>=0){
_15.style.display="";
}
_16.style.visibility="";
};
function _2e(){
_d.onload=$empty;
_d.src=_e.src=_f.src=_6;
_1b.cancel();
_1c.cancel();
_1d.cancel();
$$(_14,_15,_12,_16).setStyle("display","none");
};
function _1e(){
if(_5>=0){
_2e();
_5=_7=_8=-1;
_11.style.display="none";
_1a.cancel().chain(_24).start(0);
}
return false;
};
Element.implement({slimbox:function(_34,_35){
$$(this).slimbox(_34,_35);
return this;
}});
Elements.implement({slimbox:function(_36,_37,_38){
_37=_37||function(el){
return [el.href,el.title];
};
_38=_38||function(){
return true;
};
var _3a=this;
_3a.removeEvents("click").addEvent("click",function(){
var _3b=_3a.filter(_38,this);
return Slimbox.open(_3b.map(_37),_3b.indexOf(this),_36);
});
return _3a;
}});
return {open:function(_3c,_3d,_3e){
_3=$extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},_3e||{});
_1a=new Fx.Tween(_10,{property:"opacity",duration:_3.overlayFadeDuration});
_1b=new Fx.Morph(_11,$extend({duration:_3.resizeDuration,link:"chain"},_3.resizeTransition?{transition:_3.resizeTransition}:{}));
_1c=new Fx.Tween(_12,{property:"opacity",duration:_3.imageFadeDuration,onComplete:_33});
_1d=new Fx.Tween(_17,{property:"margin-top",duration:_3.captionAnimationDuration});
if(typeof _3c=="string"){
_3c=[[_3c,_3d]];
_3d=0;
}
_a=_1.getScrollTop()+(_1.getHeight()/2);
_b=_3.initialWidth;
_c=_3.initialHeight;
_11.setStyles({top:Math.max(0,_a-(_c/2)),width:_b,height:_c,marginLeft:-_b/2,display:""});
_9=_2||(_10.currentStyle&&(_10.currentStyle.position!="fixed"));
if(_9){
_10.style.position="absolute";
}
_1a.set(0).start(_3.overlayOpacity);
_21();
_24(1);
_4=_3c;
_3.loop=_3.loop&&(_4.length>1);
return _2c(_3d);
}};
})();
Slimbox.scanPage=function(){
$$(document.links).filter(function(el){
return el.rel&&el.rel.test(/^lightbox/i);
}).slimbox({},null,function(el){
return (this==el)||((this.rel.length>8)&&(this.rel==el.rel));
});
};
window.addEvent("domready",Slimbox.scanPage);

