/*
 * Thickbox 3.1 - 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
 * - Modified.
*/

//function called when the user clicks on a thickbox link
function tb_show(caption, url, imageGroup) {
	try {
		//if IE 6
		if (typeof document.body.style.maxHeight === "undefined") {
			jQueryFaculte("body","html").css({height: "100%", width: "100%"});
			jQueryFaculte("html").css("overflow","hidden");
			
			//iframe to hide select elements in ie6
			if (document.getElementById("TB_HideSelect") === null) {
				jQueryFaculte("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				
				//clicking on dark area removes thickbox
				//jQueryFaculte("#TB_overlay").click(tb_remove);
			}
		}
		//all others
		else {
			if(document.getElementById("TB_overlay") === null){
				jQueryFaculte("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				
				//clicking on dark area removes thickbox
				//jQueryFaculte("#TB_overlay").click(tb_remove);
			}
		}
		
		var tb_userAgent = navigator.userAgent.toLowerCase();
  		if (tb_userAgent.indexOf('mac') != -1 && tb_userAgent.indexOf('firefox')!=-1) {
			jQueryFaculte("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}
		else {
			jQueryFaculte("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		
		//add loader to the page
		jQueryFaculte("body").prepend("<div id='TB_load'><p>Loading Content...</p></div>");
		
		//show loader
		jQueryFaculte('#TB_load').show();
		
		jQueryFaculte("#TB_iframeContent").remove();
		var iframe_name = "TB_iframeContent"+Math.round(Math.random()*1000);
		var tb_content = "<div id='TB_top'><div id='TB_close'><a href='#' id='TB_closeWindowButton' title='Close'>&nbsp;</a></div><div id='TB_title'>"+caption+"</div></div><iframe frameborder='0' hspace='0' src='"+url+"' id='TB_iframeContent' name='"+ iframe_name +"' onload='tb_showIframe()' allowtransparency='true'></iframe>";
		jQueryFaculte("#TB_window").prepend(tb_content);
		jQueryFaculte("#TB_closeWindowButton").click(tb_remove);

		//safari needs help because it will not fire iframe onload
		if($.browser.safari){
			jQueryFaculte("#TB_load").remove();
			jQueryFaculte("#TB_window").css({display:"block"});
		}

		document.onkeyup = function(e){ 	
			if (e == null) {keycode = event.keyCode;} 
			else {keycode = e.which;}
			if(keycode == 27){tb_remove();}	
		};
		
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function tb_showIframe(){
	jQueryFaculte("#TB_load").remove();
	jQueryFaculte("#TB_window").css({display:"block"});
}

function tb_remove() {
 	jQueryFaculte("#TB_imageOff").unbind("click");
	jQueryFaculte("#TB_closeWindowButton").unbind("click");
	jQueryFaculte("#TB_window").fadeOut("fast",function(){jQueryFaculte('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	jQueryFaculte("#TB_load").remove();
	
	//if IE 6
	if (typeof document.body.style.maxHeight == "undefined") {
		jQueryFaculte("body","html").css({height: "auto", width: "auto"});
		jQueryFaculte("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_fullscreen() {
	if (window.frames[0].location.href.split("#")[1] == "tb_full") {
		jQueryFaculte("html").addClass("TB_fullscreen");
	}
	else jQueryFaculte("html").removeClass("TB_fullscreen");
	setTimeout("tb_fullscreen()", 0.1 * 1000);
}

