/*
 * 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
*/

/* MANUALLY ADDED */
function tb_show_tafaz(caption, text, 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=""; }

		TB_WIDTH = 650;
		TB_HEIGHT = 440;
		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'>close</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 {
			$__("#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='Chiudi'><strong>Chiudi</strong></a></div></div><iframe frameborder='0' hspace='0' src=\""+iframe+"\" 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"});
			}
		}

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


/*
 * 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
*/

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

function tb_remove() {
 	$__("#TB_imageOff").unbind("click");
	$__("#TB_closeWindowButton").unbind("click");
	$__("#TB_window").fadeOut("fast",function(){$__('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$__("#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;
  }
}

