/*
	Slimbox v1.66 - The ultimate lightweight Lightbox clone
	(c) 2007-2008 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
var Slimbox;
(function(){
	var B=window,
		J=0,
		q,g,C,s,A,r,u,I,o,m,
		p=new Image(),
		G=new Image(),
		E,a,h,F,e,D,c,w,H,t,i,d,y,
		F_png,e_png;
	B.addEvent("domready",function(){
		$(document.body).adopt(
			$$(
				E=new Element("div",{id:"lbOverlay"}).addEvent("click",z),
				a=new Element("div",{id:"lbCenter"}),
				D=new Element("div",{id:"lbBottomContainer"})
			).setStyle("display","none")
		);
		new Element("div",{id:"lbImageBack"}).injectInside(a).adopt(
			new Element("div", {id:"lbHorizontal"}),
			new Element("div", {id:"lbVertical"}),
			new Element("div", {id:"lbLeftTopCorner"}).adopt(new Element("b")),
			new Element("div", {id:"lbRightTopCorner"}).adopt(new Element("b")),
			new Element("div", {id:"lbLeftBottomCorner"}).adopt(new Element("b")),
			new Element("div", {id:"lbRightBottomCorner"}).adopt(new Element("b"))
		);
		h=new Element("div",{id:"lbImage"}).injectInside(a).adopt(
			F=new Element("a", {id:"lbPrevLink",href:"#"}).adopt(F_png=new Element("u").adopt(new Element("b"))).addEvents({
																													 "click":x,
																													 "mouseenter":block_F,
																													 "mouseleave":none_F
																													 }),
			e=new Element("a", {id:"lbNextLink",href:"#"}).adopt(e_png=new Element("u").adopt(new Element("b"))).addEvents({
																													 "click":f,
																													 "mouseenter":block_e,
																													 "mouseleave":none_e
																													 })
		);
		c=new Element("div",{id:"lbBottom"}).injectInside(D).adopt(
			  new Element("a",   {id:"lbCloseLink",href:"#"}).adopt(new Element("b")).addEvent("click",z),
//			w=new Element("div", {id:"lbCaption"}),
			H=new Element("div", {id:"lbNumber", 'class': 'small_numbers number'}),
		 	  new Element("div", {styles:{clear:"both"}})
		)
	});
	Slimbox={
		open:function(M,L,K){
			q=$extend(
				{
					loop:true,
					overlayOpacity:0.8,
					overlayFadeDuration:200,
					resizeDuration:100,
					resizeTransition:false,
					initialWidth:250,
					initialHeight:250,
					imageFadeDuration:200,
					captionAnimationDuration:200,
					counterText:'{x}<div class="number from"><b></b></div>{y}',
					closeKeys:[27,88,67],
					previousKeys:[37,80],
					nextKeys:[39,78]
				},
				K||{}
			);
			t=new Fx.Tween(E, {
				property:"opacity",
				duration:q.overlayFadeDuration
			});
			i=new Fx.Morph(
				a,
				$extend(
					{
						duration:q.resizeDuration,
						link:"chain"
						
					},
					q.resizeTransition?{
						transition:q.resizeTransition
					}:{}
				)
			);
			d=new Fx.Tween(
				h,
				{
					property:"opacity",
					duration:q.imageFadeDuration,
					onComplete:j
				}
			);
			y=new Fx.Tween(
				c,
				{
					property:"margin-top",
					duration:q.captionAnimationDuration
				}
			);
			if(typeof M=="string"){
				M=[[M,L]];
				L=0
			}
			u=B.getScrollTop()+(B.getHeight()/2);
			I=q.initialWidth;
			o=q.initialHeight;
			a.setStyles(
				{
					top:Math.max(0,u-(o/2)),
					width:I,
					height:o,
					marginLeft:-I/2,
					display:""
				}
			);
			r=!B.XMLHttpRequest||(E.currentStyle&&(E.currentStyle.position!="fixed"));
			if(r){
				E.style.position="absolute"
			}
			t.set(0).start(q.overlayOpacity);
			v();
			l(true);
			J=1;
			g=M;
			q.loop=q.loop&&(g.length>1);
			return b(L)
		}
	};
	Element.implement(
		{
			slimbox:function(K,L){
				$$(this).slimbox(K,L);
				return this
			}
		}
	);
	Elements.implement(
		{
			slimbox:function(K,N,M){
				N=N||function(O){
					return[O.href,O.title]
				};
				M=M||function(){
					return true
				};
				var L=this;
				L.removeEvents("click").addEvent("click",function(){
					var O=L.filter(M,this);
					return Slimbox.open(O.map(N),O.indexOf(this),K)
				});
				return L
			}
		}
	);
	function v(){
		var K=B.getScroll(),
			L=B.getSize();
		$$(a,D).setStyle("left",K.x+(L.x/2));
		if(r){
			E.setStyles({
				left:K.x,
				top:K.y,
				width:L.x,
				height:L.y
			})
		}
	}
	function l(K){
		["object",Browser.Engine.trident?"select":"embed"].forEach(function(M){
			Array.forEach(document.getElementsByTagName(M),function(N){
				if(K){
					N._slimbox=N.style.visibility
				}
				N.style.visibility=K?"hidden":N._slimbox
			})
		});
		E.style.display=K?"":"none";
		var L=K?"addEvent":"removeEvent";
		B[L]("scroll",v)[L]("resize",v);
		document[L]("keydown",n)
	}
	function n(L){
		var K=L.code;
		return q.closeKeys.contains(K)?z():q.nextKeys.contains(K)?f():q.previousKeys.contains(K)?x():false
	}
	function karamba(obj){
		alert('Karamba!'+obj.getParent().get('html'))
	}
	function none_this(obj) {
		obj.setStyle('display', 'none')
	}
	function block_this(obj) {
		obj.setStyle('display', 'block')
	}
	function none_F(obj) {
		return none_this(F_png)
	}
	function none_e(obj) {
		return none_this(e_png)
	}
	function block_F(obj) {
		return block_this(F_png)
	}
	function block_e(obj) {
		return block_this(e_png)
	}
	
	function x(){
		none_this(F_png)
		return b(s)
	}
	function f(){
		none_this(e_png)
		return b(A)
	}
	function b(K){
		if((J==1)&&(K>=0)){
			J=2;
			C=K;
			s=(C||(q.loop?g.length:0))-1;
			A=((C+1)%g.length)||(q.loop?0:-1);
			y.cancel();
			$$(F,e,h,D).setStyle("display","none");
			a.className="lbLoading";
			m=new Image();
			m.onload=k;
			m.src=g[K][0]
		}
		return false;
	}
	function k(){
		a.className="";
		d.set(0);
		h.setStyles({
			width:m.width+10,
			backgroundImage:"url("+g[C][0]+")",
			display:""
		});
		$$(h,F,e).setStyle("height",m.height+10);
//		w.set("html",g[C][1]||"");
		H.set("html",(((g.length>1)&&q.counterText)||"").replace(/{x}/, (new Element("b").convert_digit_to_png(C+1).get('html'))).replace(/{y}/, (new Element("b").convert_digit_to_png(g.length).get('html'))));
		if(s>=0){
			p.src=g[s][0]
		}
		if(A>=0){
			G.src=g[A][0]
		}
		I=h.offsetWidth;
		o=h.offsetHeight;
		var L=Math.max(0,u-(o/2)),
			K;
		if(a.clientHeight!=o){
			i.start({
				height:o,
				top:L
			})
		}
		if(a.clientWidth!=I){
			i.start({
				width:I,
				marginLeft:-I/2
			})
		}
		K=function(){
			D.setStyles({
				width:I,
				top:L+o,
				marginLeft:-I/2,
				visibility:"hidden",
				display:""
			});
			d.start(1).chain(function(){
				if(s>=0){
//					alert('left')
				}
				if(A>=0){
	//				alert('right')
				}
			})
		};
			if(i.check(K)){
				K()
			}
		}
		function j(){
			if(s>=0){
				F.style.display=""
			}
			if(A>=0){
				e.style.display=""
			}
			y.set(-4*c.offsetHeight).start(0);
			D.style.visibility="";
			J=1
		}
		function z(){
			if(J){
				J=0;
				m.onload=$empty;
				[t,i,d,y].forEach(function(K){
					K.cancel()
				});
				$$(a,D).setStyle("display","none");
				t.chain(l).start(0)
			}
			return false
		}
	})();

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
Slimbox.scanPage = function() {
	$$(document.links).filter(function(el) {
		return el.rel && el.rel.test(/^l_b/i);
	}).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};
window.addEvent("domready", Slimbox.scanPage);























