var Slimbox=(function(){var U=window,AM=Browser.Engine.trident4,AF,AT,T=-1,AL,AD,V,AE,AB,N,AH,AN={},AG=new Image(),P=new Image(),R,AZ,AS,AJ,Q,AV,S,AX,Z,O,AC,AR,AW,X;
U.addEvent("domready",function(){$(document.body).adopt($$(R=new Element("div",{id:"lbOverlay",events:{click:W}}),AZ=new Element("div",{id:"lbCenter"}),S=new Element("div",{id:"lbBottomContainer"})).setStyle("display","none"));
AS=new Element("div",{id:"lbImage"}).injectInside(AZ).adopt(AJ=new Element("div",{styles:{position:"relative"}}).adopt(Q=new Element("a",{id:"lbPrevLink",href:"#",events:{click:Y}}),AV=new Element("a",{id:"lbNextLink",href:"#",events:{click:AU}})));
AX=new Element("div",{id:"lbBottom"}).injectInside(S).adopt(new Element("a",{id:"lbCloseLink",href:"#",events:{click:W}}),Z=new Element("div",{id:"lbCaption"}),O=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}))
});
function AA(){var B=U.getScroll(),A=U.getSize();
$$(AZ,S).setStyle("left",B.x+(A.x/2));
if(AE){R.setStyles({left:B.x,top:B.y,width:A.x,height:A.y})
}}function AO(B){["object",AM?"select":"embed"].forEach(function(C){Array.forEach(document.getElementsByTagName(C),function(D){if(B){D._slimbox=D.style.visibility
}D.style.visibility=B?"hidden":D._slimbox
})
});
R.style.display=B?"":"none";
var A=B?"addEvent":"removeEvent";
U[A]("scroll",AA)[A]("resize",AA);
document[A]("keydown",AK)
}function AK(A){var B=A.code;
return AF.closeKeys.contains(B)?W():AF.nextKeys.contains(B)?AU():AF.previousKeys.contains(B)?Y():false
}function Y(){return AY(AD)
}function AU(){return AY(V)
}function AY(A){if(A>=0){T=A;
AL=AT[A][0];
AD=(T||(AF.loop?AT.length:0))-1;
V=((T+1)%AT.length)||(AF.loop?0:-1);
AI();
AZ.className="lbLoading";
AN=new Image();
AN.onload=AP;
AN.src=AL
}return false
}function AP(){AZ.className="";
AW.set(0);
AS.setStyles({backgroundImage:"url("+AL+")",display:""});
AJ.setStyle("width",AN.width);
$$(AJ,Q,AV).setStyle("height",AN.height);
Z.set("html",AT[T][1]||"");
O.set("html",(((AT.length>1)&&AF.counterText)||"").replace(/{x}/,T+1).replace(/{y}/,AT.length));
if(AD>=0){AG.src=AT[AD][0]
}if(V>=0){P.src=AT[V][0]
}N=AS.offsetWidth;
AH=AS.offsetHeight;
var A=Math.max(0,AB-(AH/2)),C=0,B;
if(AZ.offsetHeight!=AH){C=AR.start({height:AH,top:A})
}if(AZ.offsetWidth!=N){C=AR.start({width:N,marginLeft:-N/2})
}B=function(){S.setStyles({width:N,top:A+AH,marginLeft:-N/2,visibility:"hidden",display:""});
AW.start(1)
};
if(C){AR.chain(B)
}else{B()
}}function AQ(){if(AD>=0){Q.style.display=""
}if(V>=0){AV.style.display=""
}X.set(-AX.offsetHeight).start(0);
S.style.visibility=""
}function AI(){AN.onload=$empty;
AN.src=AG.src=P.src=AL;
AR.cancel();
AW.cancel();
X.cancel();
$$(Q,AV,AS,S).setStyle("display","none")
}function W(){if(T>=0){AI();
T=AD=V=-1;
AZ.style.display="none";
AC.cancel().chain(AO).start(0)
}return false
}Element.implement({slimbox:function(B,A){$$(this).slimbox(B,A);
return this
}});
Elements.implement({slimbox:function(D,A,B){A=A||function(E){return[E.href,E.title]
};
B=B||function(){return true
};
var C=this;
C.removeEvents("click").addEvent("click",function(){var E=C.filter(B,this);
return Slimbox.open(E.map(A),E.indexOf(this),D)
});
return C
}});
return{open:function(A,B,C){AF=$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]},C||{});
AC=new Fx.Tween(R,{property:"opacity",duration:AF.overlayFadeDuration});
AR=new Fx.Morph(AZ,$extend({duration:AF.resizeDuration,link:"chain"},AF.resizeTransition?{transition:AF.resizeTransition}:{}));
AW=new Fx.Tween(AS,{property:"opacity",duration:AF.imageFadeDuration,onComplete:AQ});
X=new Fx.Tween(AX,{property:"margin-top",duration:AF.captionAnimationDuration});
if(typeof A=="string"){A=[[A,B]];
B=0
}AB=U.getScrollTop()+(U.getHeight()/2);
N=AF.initialWidth;
AH=AF.initialHeight;
AZ.setStyles({top:Math.max(0,AB-(AH/2)),width:N,height:AH,marginLeft:-N/2,display:""});
AE=AM||(R.currentStyle&&(R.currentStyle.position!="fixed"));
if(AE){R.style.position="absolute"
}AC.set(0).start(AF.overlayOpacity);
AA();
AO(1);
AT=A;
AF.loop=AF.loop&&(AT.length>1);
return AY(B)
}}
})();
Slimbox.scanPage=function(){$$(document.links).filter(function(A){return A.rel&&A.rel.test(/^lightbox/i)
}).slimbox({},null,function(A){return(this==A)||((this.rel.length>8)&&(this.rel==A.rel))
})
};
window.addEvent("domready",Slimbox.scanPage);
