var timeout=0;

function resizeContainer(){
	$("#contenitoreAll").width("auto");
	$("#contenitoreAll1").width("auto");	
	$("#contenitoreAll").height("auto");
	$("#contenitoreAll1").height("auto");	

	$("#contenitoreAll").height(totalHeight);
	$("#contenitoreAll1").height(totalHeight);	

	var totalWidth=Math.max($(window).width(),$(document).width());
	var totalHeight=Math.max($(window).height(),$(document).height());
	totalWidth=totalWidth-(isIE()?21:0);
	totalHeight=totalHeight-(isIE()?21:0);

	$("#contenitoreAll").width(totalWidth);
	$("#contenitoreAll1").width(totalWidth);	

	$("#contenitoreAll").height(totalHeight);
	$("#contenitoreAll1").height(totalHeight);	
}

function caricaFlashHome(lang){
	var flashvars = {
			xml: "public/link_tesori.xml"
		};
	var params = {
			wmode: "transparent",
			quality: "autohigh",
			swliveconnect: "true",
			allowScriptAccess: "always",
			allowFullScreen: "false",
			scale: "exactfit",
			bgcolor: "#ffffff",
			width:"100%",
			height:"100%",
			align: "bottom"
		};
	var attributes = {
			id: "flashHome",
			name: "flashHome"
		};
	swfobject.embedSWF("home.swf", "flashHome", "100%", "100%", "9.0.0","js/flash/expressInstall.swf", flashvars, params, attributes);
}


function ie6Bisol(){
	$('#barPrenota').css("background","none");	
}

function fixPng(){
	$('img').ifixpng();
	$('#contenitoreAll').ifixpng();
	$('#menu a').ifixpng();
	$('.menuSub a').ifixpng();
	$('#logicweb').ifixpng();
	
	if(getIEVersion()<=6){
		ie6Bisol();
	}
	
}

function attivaCufon(idElemento){
	idElemento=(typeof(idElemento)=="undefined")?"":(idElemento+" ");
	Cufon.replace(idElemento+'.constan', { fontFamily: 'constan', hover:'true' });
}

function popNl(){
	TopUp.display("nl_pop.php", {
		width:(getNomeBrowser()=="webkit")?521:504,
		height:(getNomeBrowser()=="webkit")?264:250,
		type:'iframe',
		layout:'dashboard', // 'quicklook','dashboard'
		resizable:0,
		shaded:1,
		noGroup:1,
		ondisplay: function(){
			$(".te_close_link").hide();
		},
		onclose: function(){
			$(".te_close_link").show();
		}
	});
	return(false);
} 

function formNl_act(){
	$("#alertForm").html("");
	$.post("background.php",{
			act: "newsletterIns",
			idAccoglienza:  $("#idAccoglienza").val(),
			nome: $("#nome").val(),
			cognome: $("#cognome").val(),
			email: $("#email").val(),
			privacy: $("#privacy").val(),
			nl: $("#nl").val(),
			time: unixTime()
		}, function(data){
			if(data=="ok"){
				location.href=($("#urlHere").val())+"&act=ok";
			} else {
				if(data=="cognome_missing"){ $("#cognome").focus(); $("#alertForm").html(arrJsTexts['alert_cognome']); return(false); }
				if(data=="nome_missing"){ $("#nome").focus(); $("#alertForm").html(arrJsTexts['alert_nome']); return(false); }
				if(data=="email_missing"){ $("#email").focus(); $("#alertForm").html(arrJsTexts['alert_email']); return(false); }
				if(data=="email_wrong"){ $("#email").focus(); $("#alertForm").html(arrJsTexts['alert_wrongemail']); return(false); }
				if(data=="privacy"){ $("#privacy").focus(); $("#alertForm").html(arrJsTexts['alert_privacy']); return(false); }
				if(data=="err_generic"){ $("#alertForm").html(arrJsTexts['err_generic']); return(false); }
				location.href=($("#urlHere").val())+"&act=ko";
			}
		});
	return(false);
}

function actBottCheckbox(jqObjBott,jqObjInput){
	var valAtt=jqObjInput.val();
	jqObjInput.attr("value",(valAtt==0)?1:0);
	jqObjBott.attr("src",jqObjBott.attr((valAtt==0)?"src_on":"src_off"));
}

function allineaSubMenu(){
	var posX1=0;
	var pos1 = $(".contMenuSub").position();
	try{
		posX1=pos1.left;
	} catch(err){
		
	}
	if(true || posX1>0 || posX1<0){
		// posX1 = posX1+((getIEVersion()<=6)?0:-3);
		var menuUp=$(".aLink");
		$.each(menuUp, function(key, value){
			var idLiv1=$(value).attr("idLiv1");
			var pos = $(value).position();
			var posX = pos.left;
			var posY = pos.top;
			// $('#menuSub'+idLiv1).css("marginLeft",posX-posX1);

			$('#menuSub'+idLiv1).animate({ 
				marginLeft: (posX-posX1+"px")
			}, 100);

		});
	}
}

function attivaMenu(){
	setInterval(function(){ allineaSubMenu() }, 1000);

	$(".aLink").bind("mouseover", function(){
		idLiv1=$(this).attr("idLiv1");
		clearTimeout(timeout);
		$('.menuSub').hide(0,function(){
			$('#menuSub'+idLiv1).show(0,function(){
				
			});
		});
	});
	$(".aLink").bind("mouseout", function(){
		timeout = setTimeout(function(){
			$('.menuSub').hide(0,function(){
				if($('.menuSub.selected')){
					$('.menuSub.selected').show(0,function(){

					});
				} else {
					alert("err");	
				}
			});
		}, 500);
	});

	$(".menuSub").bind("mouseover", function(){
		clearTimeout(timeout);
	});
	$(".menuSub").bind("mouseout", function(){
		timeout = setTimeout(function(){
			$('.menuSub').hide(0,function(){
				$('.menuSub.selected').show(0,function(){
					
				});
			});
		}, 500);
	});

}

