/*
 * 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
*/
var timer;
/* MANUALLY ADDED */
function tb_show_tafaz(caption, text, w, h, iframe) {//function called when the user clicks on a thickbox link
	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$__("body","html").css({height: "100%", width: "100%"});
			$__("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$__("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$__("#TB_overlay").click(tb_remove);
			}
		} else { //all others
			if(document.getElementById("TB_overlay") === null){
				$__("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$__("#TB_overlay").click(tb_remove);
			}
		}
		if(tb_detectMacXFF()){
			$__("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$__("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}

		if(caption===null){ caption=""; }
		if(!iframe){
			TB_WIDTH = typeof w!='undefined' && w!=null?w:400;
			TB_HEIGHT = typeof h!='undefined' && h!=null?h:250;
		} else {
			windowW = tb_getPageSize();
			TB_WIDTH = typeof w!='undefined' && w!=null?w:windowW[0]-200;
			TB_HEIGHT = typeof h!='undefined' && h!=null?h:windowW[1]-200;
		}
		ajaxContentW = TB_WIDTH - 30;
		ajaxContentH = TB_HEIGHT - 45;
		if(!iframe){
			if($__("#TB_window").css("display") != "block"){
				$__("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>Chiudi</a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'>"+text+"</div>");
			} else {
				$__("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
				$__("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
				$__("#TB_ajaxContent")[0].scrollTop = 0;
				$__("#TB_ajaxWindowTitle").html(caption);
				$__("#TB_ajaxContent").html(text);
			}
			$__("#TB_closeWindowButton").click(tb_remove);

			tb_position();
			$__("#TB_window").css({display:"block"});
		} else {
			src = (iframe!=true)?iframe:'about:blank';
			$__("#TB_iframeContent").remove();
			$__("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>Chiudi</a></div></div><iframe frameborder='0' hspace='0' src=\""+src+"\" id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' >"+text+"</iframe>");
			$__("#TB_closeWindowButton").click(tb_remove);
			tb_position();
			if($__.browser.safari){//safari needs help because it will not fire iframe onload
				$__("#TB_load").remove();
				$__("#TB_window").css({display:"block"});
			}
			if(iframe==true){
				//tb_showIframe();
				$__('#TB_iframeContent').html(text);
			}
		}
		timer = setInterval(function(){ $__('object').each(function(i){ $__(this).css({display:"none"}); }); },50);
		$__("#TB_closeWindowButton").click(tb_remove);

		tb_position();
		//showHideFlash("hidden");
		$__("#TB_window").css({display:"block"});

	} catch(e) {
		//nothing here
	}
}

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

function tb_position() {
jQuery("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && (jQuery.browser.version < 7) && whichIe<7)) { // take away IE6
		jQuery("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function whichIe(){
	myRE = /msie ([0-9]*)/gi;
	results = navigator.userAgent.toLowerCase().match(myRE);
	res = 0;
	for(var i =0; i < results.length; i++){
		_res = results[i].substr(5,results[i].length);
		if(res<_res){ res=_res; }	
	}
	return res;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}

function tb_showIframe(){
  $__("#TB_load").remove();
  $__("#TB_window").css({display:"block"});
}

/*function showHideFlash(s){
	var f_Objects = document.getElementsByTagName("object");
	for (i = 0; i < f_Objects.length; i++) {f_Objects[i].style.visibility = s;}
	var f_Embeds = document.getElementsByTagName("embed");
	for (i = 0; i < f_Embeds.length; i++) {f_Embeds[i].style.visibility = s;}
}*/
