/*
	Slimbox v2.04 - The ultimate lightweight Lightbox clone for jQuery
	(c) 2007-2010 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
 */
(function(E) {
	var N = E(window), A, h, O = -1, s, F, M, B, G, X, w, q = !window.XMLHttpRequest, x = [], p = document.documentElement, o = {}, y = new Image(), U = new Image(), Q, f, z, n, T, W, r, C, R, b, j, u, S, e, P, c, K, V;
	E(function() {
		E("body").append(
				E(
						[ R = E('<div id="sbOverlay" />')[0],
								b = E('<div id="sbCenter" />')[0],
								P = E('<div id="sbBottomContainer" />')[0] ])
						.css("display", "none"));
		j = E('<div id="sbImage" />').appendTo(b).append(
				u = E('<div style="position: relative;" />')
						.append(
								[
										S = E('<a id="prevLink" href="#" />')
												.click(I)[0],
												E('<a id="closeLink" href="#" />').add(R)
												.click(L)[0],
										e = E('<a id="nextLink" href="#" />')
												.click(g)[0] ])[0])[0];
		c = E('<div id="sbBottom" />')
				.appendTo(P)
				.append(
						[
								W = E('<a id="playLink" href="#" />').click(D)[0],
								r = E('<a id="pauseLink" href="#" />').click(d)[0],
								C = E('<a id="saveLink" href="#" target="_blank" />')[0],
								K = E('<div id="sbCaption" />')[0],
								V = E('<div id="sbNumber" />')[0],
								Q = E('<div id="sbPresent" />')[0],
								E('<div style="clear: both;" />')[0] ])[0]
	});
	E.slimbox = function(aa, Z, Y) {
		A = E.extend({
			loop : false,
			overlayOpacity : 0.8,
			overlayFadeDuration : 400,
			resizeDuration : 400,
			resizeEasing : "swing",
			initialWidth : 250,
			initialHeight : 250,
			imageFadeDuration : 400,
			captionAnimationDuration : 400,
			counterText : "Image ###x### of ###y###",
			closeKeys : [ 27, 88, 67 ],
			previousKeys : [ 37, 80 ],
			nextKeys : [ 39, 78 ],
			slideshowKeys : [ 83 ],
			allowSave : false,
			slideshowAutoplay : false,
			slideshowInterval : 3000,
			slideshowAutoclose : true
		}, Y);
		if (typeof aa == "string") {
			aa = [ [ aa, Z ] ];
			Z = 0
		}
		G = N.scrollTop() + (N.height() / 2);
		X = A.initialWidth;
		w = A.initialHeight;
		E(b).css({
			top : Math.max(0, G - (w / 2)),
			width : X,
			height : w,
			marginLeft : -X / 2
		}).show();
		B = q || (R.currentStyle && (R.currentStyle.position != "fixed"));
		if (B) {
			R.style.position = "absolute"
		}
		E(R).css("opacity", A.overlayOpacity).fadeIn(A.overlayFadeDuration);
		J();
		m(1);
		h = aa;
		A.loop = A.loop && (h.length > 1);
		n = A.slideshowAutoplay && z;
		return a(Z)
	};
	E.fn.slimbox = function(Y, ab, aa) {
		ab = ab || function(ac) {
			ac.rel.match(/present.+/) ? f = true : f = false;
			ac.rel.match(/slideshow.+/) ? z = true : z = false;
			return [ ac.href, ac.title ]
		};
		aa = aa || function() {
			return true
		};
		var Z = this;
		return Z.unbind("click").click(function() {
			var ae = this, ag = 0, af, ac = 0, ad;
			af = E.grep(Z, function(ai, ah) {
				return aa.call(ae, ai, ah)
			});
			for (ad = af.length; ac < ad; ++ac) {
				if (af[ac] == ae) {
					ag = ac
				}
				af[ac] = ab(af[ac], ac)
			}
			return E.slimbox(af, ag, Y)
		})
	};
	function J() {
		var Z = N.scrollLeft(), Y = N.width();
		E([ b, P ]).css("left", Z + (Y / 2));
		if (B) {
			E(R).css({
				left : Z,
				top : N.scrollTop(),
				width : Y,
				height : N.height()
			})
		}
	}
	function m(Y) {
		if (Y) {
			E("object").add(q ? "select" : "embed").each(function(aa, ab) {
				x[aa] = [ ab, ab.style.visibility ];
				ab.style.visibility = "hidden"
			})
		} else {
			E.each(x, function(aa, ab) {
				ab[0].style.visibility = ab[1]
			});
			x = []
		}
		var Z = Y ? "bind" : "unbind";
		N[Z]("scroll resize", J);
		E(document)[Z]("keydown", t)
	}
	function t(aa) {
		var Z = aa.keyCode, Y = E.inArray;
		return (Y(Z, A.closeKeys) >= 0) ? L() : (Y(Z, A.nextKeys) >= 0) ? g()
				: (Y(Z, A.previousKeys) >= 0) ? I()
						: (Y(Z, A.slideshowKeys) >= 0) ? H() : false
	}
	function I() {
		return a(F)
	}
	function g() {
		return a(M)
	}
	function a(Y) {
		if (Y >= 0) {
			O = Y;
			s = h[O][0];
			F = (O || (A.loop ? h.length : 0)) - 1;
			M = ((O + 1) % h.length) || (A.loop ? 0 : -1);
			v();
			b.className = "sbLoading";
			o = new Image();
			o.onload = l;
			o.src = s
		}
		return false
	}
	function l() {
		b.className = "";
		E(j).css({
			backgroundImage : "url(" + s + ")",
			visibility : "hidden",
			display : ""
		});
		E(u).width(o.width);
		E([ u, S, e ]).height(o.height);
		E(K).html(h[O][1] || "");
		E(V).html(
				(((h.length > 1) && A.counterText) || "").replace(/###x###/,
						O + 1).replace(/###y###/, h.length));
		if (f) {
			E(V).css("display", "none");
			E(Q).html("").css("display", "");
			for (i = 0; i < h.length; i++) {
				var Z = O == i ? "act" : "no";
				var Y = E(
						'<a id="pmi' + (i + 1) + '" href="#" class="' + Z
								+ '"></a>').click(function() {
					var ab = parseInt(E(this).text()) - 1;
					d();
					return a(ab)
				});
				i < 9 ? Y.html("0" + (i + 1)) : Y.html(i + 1);
				Y.appendTo(Q)
			}
		} else {
			E(V).css("display", "");
			E(Q).html("").css("display", "none")
		}
		if (F >= 0) {
			y.src = h[F][0]
		}
		if (M >= 0) {
			U.src = h[M][0]
		}
		X = j.offsetWidth;
		w = j.offsetHeight;
		var aa = Math.max(0, G - (w / 2));
		if (b.offsetHeight != w) {
			E(b).animate({
				height : w,
				top : aa
			}, A.resizeDuration, A.resizeEasing)
		}
		if (b.offsetWidth != X) {
			E(b).animate({
				width : X,
				marginLeft : -X / 2
			}, A.resizeDuration, A.resizeEasing)
		}
		E(b).queue(function() {
			E(P).css({
				width : X,
				top : aa + w,
				marginLeft : -X / 2,
				visibility : "hidden",
				display : ""
			});
			E(j).css({
				display : "none",
				visibility : "",
				opacity : ""
			}).fadeIn(A.imageFadeDuration, k)
		})
	}
	function k() {
		if (F >= 0) {
			E(S).show()
		}
		if (M >= 0) {
			E(e).show()
		}
		E(c).css("marginTop", -c.offsetHeight).animate({
			marginTop : 0
		}, A.captionAnimationDuration);
		P.style.visibility = "";
		E(W).css("display", "none");
		E(r).css("display", "none");
		if (z) {
			clearTimeout(T);
			if (n) {
				E(r).css("display", "");
				if (O != (h.length - 1)) {
					T = setTimeout(g, A.slideshowInterval)
				} else {
					if (A.slideshowAutoclose) {
						T = setTimeout(L, A.slideshowInterval)
					} else {
						if (A.loop) {
							T = setTimeout(a, A.slideshowInterval, 0)
						} else {
							d()
						}
					}
				}
			} else {
				E(W).css("display", "")
			}
		}
		A.allowSave ? E(C).attr("href", h[O][0]).css("display", "") : E(C).css(
				"display", "none")
	}
	function H() {
		if (n) {
			d()
		} else {
			D()
		}
		return false
	}
	function D() {
		n = true;
		if (O != (h.length - 1)) {
			g()
		} else {
			if (A.slideshowAutoclose && !A.loop) {
				T = setTimeout(L, 0)
			} else {
				if (A.loop) {
					a(0)
				} else {
				}
			}
		}
		return false
	}
	function d() {
		n = false;
		clearTimeout(T);
		E(W).css("display", "");
		E(r).css("display", "none");
		return false
	}
	function v() {
		o.onload = null;
		o.src = y.src = U.src = s;
		E([ b, j, c ]).stop(true);
		E([ S, e, j, P ]).hide()
	}
	function L() {
		if (O >= 0) {
			d();
			v();
			O = F = M = -1;
			E(b).hide();
			E(R).stop().fadeOut(A.overlayFadeDuration, m);
			clearTimeout(T)
		}
		return false
	}
})(jQuery);
var SlimboxOptions = jQuery.extend({}, window.SlimboxOptions || {});
if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i
		.test(navigator.userAgent)) {
	jQuery(function(a) {
		a("a[rel^='lightbox']").slimbox(
				SlimboxOptions,
				null,
				function(b) {
					return (this == b)
							|| ((this.rel.length > 8) && (this.rel == b.rel))
				})
	})
};
