/*
 * Thickbox 3 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

var tb_pathToImage2 = "http://www.eluniversal.com.mx/ajax/thickbox/loadingAnimation.gif";


$(document).ready(function () {
	tb_init2('a.thickbox2, area.thickbox2, input.thickbox2');
	imgLoader = new Image();
	imgLoader.src = tb_pathToImage2
});
function tb_init2(b) {
	$(b).click(function () {
		var t = this.title || this.name || null;
		var a = this.href || this.alt;
		var g = this.rel || false;
		tb_show2(t, a, g);
		this.blur();
		return false
	})
}
function tb_show2(d, f, g) {
	try {
		if (typeof document.body.style.maxHeight === "undefined") {
			$("body", "html").css({
				height: "100%",
				width: "100%"
			});
			$("html").css("overflow", "hidden");
			if (document.getElementById("TB_HideSelect2") === null) {
				$("body").append("<iframe id='TB_HideSelect2'></iframe><div id='TB_overlay2'></div><div id='TB_window2'></div>");
				$("#TB_overlay2").click(tb_remove2)
			}
		} else {
			if (document.getElementById("TB_overlay2") === null) {
				$("body").append("<div id='TB_overlay2'></div><div id='TB_window2'></div>");
				$("#TB_overlay2").click(tb_remove2)
			}
		}
		if (tb_detectMacXFF2()) {
			$("#TB_overlay2").addClass("TB_overlayMacFFBGHack2")
		} else {
			$("#TB_overlay2").addClass("TB_overlayBG2")
		}
		if (d === null) {
			d = ""
		}
		$("body").append("<div id='TB_load2'><img src='" + imgLoader.src + "' /></div>");
		$('#TB_load2').show();
		var h;
		if (f.indexOf("?") !== -1) {
			h = f.substr(0, f.indexOf("?"))
		} else {
			h = f
		}
		var i = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
		var j = h.toLowerCase().match(i);
		if (j == '.jpg' || j == '.jpeg' || j == '.png' || j == '.gif' || j == '.bmp') {
			TB_PrevCaption2 = "";
			TB_PrevURL2 = "";
			TB_PrevHTML2 = "";
			TB_NextCaption2 = "";
			TB_NextURL2 = "";
			TB_NextHTML2 = "";
			TB_imageCount2 = "";
			TB_FoundURL2 = false;
			if (g) {
				TB_TempArray2 = $("a[@rel=" + g + "]").get();
				for (TB_Counter2 = 0;
				((TB_Counter2 < TB_TempArray2.length) && (TB_NextHTML2 === "")); TB_Counter2++) {
					var k = TB_TempArray2[TB_Counter2].href.toLowerCase().match(i);
					if (! (TB_TempArray2[TB_Counter2].href == f)) {
						if (TB_FoundURL2) {
							TB_NextCaption2 = TB_TempArray2[TB_Counter2].title;
							TB_NextURL2 = TB_TempArray2[TB_Counter2].href;
							TB_NextHTML2 = "<span id='TB_next2'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>"
						} else {
							TB_PrevCaption2 = TB_TempArray2[TB_Counter2].title;
							TB_PrevURL2 = TB_TempArray2[TB_Counter2].href;
							TB_PrevHTML2 = "<span id='TB_prev2'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>"
						}
					} else {
						TB_FoundURL2 = true;
						TB_imageCount2 = "Image " + (TB_Counter2 + 1) + " of " + (TB_TempArray2.length)
					}
				}
			}
			imgPreloader = new Image();
			imgPreloader.onload = function () {
				imgPreloader.onload = null;
				var a = tb_getPageSize2();
				var x = a[0] - 150;
				var y = a[1] - 150;
				var b = imgPreloader.width;
				var c = imgPreloader.height;
				if (b > x) {
					c = c * (x / b);
					b = x;
					if (c > y) {
						b = b * (y / c);
						c = y
					}
				} else if (c > y) {
					b = b * (y / c);
					c = y;
					if (b > x) {
						c = c * (x / b);
						b = x
					}
				}
				TB_WIDTH2 = b + 30;
				TB_HEIGHT2 = c + 60;
				$("#TB_window2").append("<a href='' id='TB_ImageOff2' title='X'><img id='TB_Image2' src='" + f + "' width='" + b + "' height='" + c + "' alt='" + d + "'/></a>" + "<div id='TB_caption2'>" + d + "<div id='TB_secondLine2'>" + TB_imageCount2 + TB_PrevHTML2 + TB_NextHTML2 + "</div></div><div id='TB_closeWindow2'><a href='#' id='TB_closeWindowButton2' title='X'>X</a> &nbsp; &nbsp; &nbsp;</div>");
				$("#TB_closeWindowButton2").click(tb_remove2);
				if (! (TB_PrevHTML2 === "")) {
					function goPrev() {
						if ($(document).unbind("click", goPrev)) {
							$(document).unbind("click", goPrev)
						}
						$("#TB_window2").remove();
						$("body").append("<div id='TB_window2'></div>");
						tb_show2(TB_PrevCaption2, TB_PrevURL2, g);
						return false
					}
					$("#TB_prev2").click(goPrev)
				}
				if (! (TB_NextHTML2 === "")) {
					function goNext() {
						$("#TB_window2").remove();
						$("body").append("<div id='TB_window2'></div>");
						tb_show2(TB_NextCaption2, TB_NextURL2, g);
						return false
					}
					$("#TB_next2").click(goNext)
				}
				document.onkeydown = function (e) {
					if (e == null) {
						keycode = event.keyCode
					} else {
						keycode = e.which
					}
					if (keycode == 27) {
						tb_remove2()
					} else if (keycode == 190) {
						if (! (TB_NextHTML2 == "")) {
							document.onkeydown = "";
							goNext()
						}
					} else if (keycode == 188) {
						if (! (TB_PrevHTML2 == "")) {
							document.onkeydown = "";
							goPrev()
						}
					}
				};
				tb_position2();
				$("#TB_load2").remove();
				$("#TB_ImageOff2").click(tb_remove2);
				$("#TB_window2").css({
					display: "block"
				})
			};
			imgPreloader.src = f
		} else {
			var l = f.replace(/^[^\?]+\??/, '');
			var m = tb_parseQuery2(l);
			TB_WIDTH2 = (m['width'] * 1) + 30 || 630;
			TB_HEIGHT2 = (m['height'] * 1) + 40 || 440;
			ajaxContentW = TB_WIDTH2 - 30;
			ajaxContentH = TB_HEIGHT2 - 45;
			if (f.indexOf('TB_iframe2') != -1) {
				urlNoQuery = f.split('TB_');
				$("#TB_iframeContent2").remove();
				if (m['modal'] != "true") {
					$("#TB_window2").append("<div id='TB_title2'><div id='TB_ajaxWindowTitle2'>" + d + "</div><div id='TB_closeAjaxWindow2'><a href='#' id='TB_closeWindowButton2' title='X'>X</a> &nbsp; &nbsp; &nbsp;</div></div><iframe frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='TB_iframeContent2' name='TB_iframeContent2" + Math.round(Math.random() * 1000) + "' onload='tb_showIframe2()' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;' > </iframe>")
				} else {
					$("#TB_overlay2").unbind();
					$("#TB_window2").append("<iframe frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='TB_iframeContent2' name='TB_iframeContent2" + Math.round(Math.random() * 1000) + "' onload='tb_showIframe2()' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;'> </iframe>")
				}
			} else {
				if ($("#TB_window2").css("display") != "block") {
					if (m['modal'] != "true") {
						$("#TB_window2").append("<div id='TB_title2'><div id='TB_ajaxWindowTitle2'>" + d + "</div><div id='TB_closeAjaxWindow2'><a href='#' id='TB_closeWindowButton2'>X</a> &nbsp; &nbsp; &nbsp;</div></div><div id='TB_ajaxContent2' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px'></div>")
					} else {
						$("#TB_overlay2").unbind();
						$("#TB_window2").append("<div id='TB_ajaxContent2' class='TB_modal2' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px;'></div>")
					}
				} else {
					$("#TB_ajaxContent2")[0].style.width = ajaxContentW + "px";
					$("#TB_ajaxContent2")[0].style.height = ajaxContentH + "px";
					$("#TB_ajaxContent2")[0].scrollTop = 0;
					$("#TB_ajaxWindowTitle2").html(d)
				}
			}
			$("#TB_closeWindowButton2").click(tb_remove2);
			if (f.indexOf('TB_inline2') != -1) {
				$("#TB_ajaxContent2").append($('#' + m['inlineId']).children());
				$("#TB_window2").unload(function () {
					$('#' + m['inlineId']).append($("#TB_ajaxContent2").children())
				});
				tb_position2();
				$("#TB_load2").remove();
				$("#TB_window2").css({
					display: "block"
				})
			} else if (f.indexOf('TB_iframe2') != -1) {
				tb_position2();
				if ($.browser.safari) {
					$("#TB_load2").remove();
					$("#TB_window2").css({
						display: "block"
					})
				}
			} else {
				$("#TB_ajaxContent2").load(f += "&random=" + (new Date().getTime()), function () {
					tb_position2();
					$("#TB_load2").remove();
					tb_init2("#TB_ajaxContent2 a.thickbox2");
					$("#TB_window2").css({
						display: "block"
					})
				})
			}
		}
		if (!m['modal']) {
			document.onkeyup = function (e) {
				if (e == null) {
					keycode = event.keyCode
				} else {
					keycode = e.which
				}
				if (keycode == 27) {
					tb_remove2()
				}
			}
		}
	} catch(e) {}
}
function tb_showIframe2() {
	$("#TB_load2").remove();
	$("#TB_window2").css({
		display: "block"
	})
}
function tb_remove2() {
	$("#TB_imageOff2").unbind("click");
	$("#TB_closeWindowButton2").unbind("click");
	$("#TB_window2").fadeOut("fast", function () {
		$('#TB_window2,#TB_overlay2,#TB_HideSelect2').trigger("unload").unbind().remove()
	});
	$("#TB_load2").remove();
	if (typeof document.body.style.maxHeight == "undefined") {
		$("body", "html").css({
			height: "auto",
			width: "auto"
		});
		$("html").css("overflow", "")
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false
}
function tb_position2() {
	$("#TB_window2").css({
		marginLeft: '-' + parseInt((TB_WIDTH2 / 2), 10) + 'px',
		width: TB_WIDTH2 + 'px'
	});
	if (! (jQuery.browser.msie && jQuery.browser.version < 7)) {
		$("#TB_window2").css({
			marginTop: '-' + parseInt((TB_HEIGHT2 / 2), 10) + 'px'
		})
	}
}
function tb_parseQuery2(a) {
	var b = {};
	if (!a) {
		return b
	}
	var c = a.split(/[;&]/);
	for (var i = 0; i < c.length; i++) {
		var d = c[i].split('=');
		if (!d || d.length != 2) {
			continue
		}
		var e = unescape(d[0]);
		var f = unescape(d[1]);
		f = f.replace(/\+/g, ' ');
		b[e] = f
	}
	return b
}
function tb_getPageSize2() {
	var a = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (a && a.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (a && a.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w, h];
	return arrayPageSize
}
function tb_detectMacXFF2() {
	var a = navigator.userAgent.toLowerCase();
	if (a.indexOf('mac') != -1 && a.indexOf('firefox') != -1) {
		return true
	}
}
