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

		if(caption===null){ caption=""; }
		if(!iframe || iframe==null){
			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;
		ajaxContentH = TB_HEIGHT;
		if(!iframe || iframe==null){
			if(jQuery("#TB_window").css("display") != "block"){
				jQuery("#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 {
				jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
				jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
				jQuery("#TB_ajaxContent")[0].scrollTop = 0;
				jQuery("#TB_ajaxWindowTitle").html(caption);
				jQuery("#TB_ajaxContent").html(text);
			}
			jQuery("#TB_closeWindowButton").click(tb_remove);

			tb_position();
			jQuery("#TB_window").css({display:"block"});
		} else {
			src = (iframe!=true)?iframe:'about:blank';
			jQuery("#TB_iframeContent").remove();
			jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='"+close+"'>"+close+"</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)+"px;height:"+(ajaxContentH)+"px;' >"+text+"</iframe>");
			TB_WIDTH = TB_WIDTH;
			jQuery("#TB_closeWindowButton").click(tb_remove);
			tb_position();
			if(jQuery.browser.safari){//safari needs help because it will not fire iframe onload
				jQuery("#TB_load").remove();
				jQuery("#TB_window").css({display:"block"});
			}
			if(iframe==true){
				//tb_showIframe();
				jQuery('#TB_iframeContent').html(text);
			}
		}
		jQuery("#TB_closeWindowButton").click(tb_remove);

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

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

function tb_remove() {
	clearInterval(timer);
	jQuery("#TB_imageOff").unbind("click");
	jQuery("#TB_closeWindowButton").unbind("click");
	jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();
	jQuery('object').each(function(i){ jQuery(this).css({display:""}); });});
	jQuery("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		jQuery("body","html").css({height: "auto", width: "auto"});
		jQuery("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(){
  jQuery("#TB_load").remove();
  jQuery("#TB_window").css({display:"block"});
}

