




/*// BROWSER UPDATE ////////////////////////////////////////////////////////////////////////////////////*/
$(document).ready(function(){	/* Lo script viene eseguito solo quando la pagina è stata caricata completamente */

	if($.browser.msie && $.browser.version<'7.0')	/* Se è internet explorer v.6 o inferiore */
		$('#browser_update','html body')
			.fadeIn('slow')						/* fai comparire la barra */

	$('#browser_update_close','html body #browser_update').click(function(){	/* Se l'utente clicca sul tasto di chiusura */
		$('#browser_update','html body')							/* La barra */
			.fadeOut('slow')										/* e ritorna invisibile */
	})

	/* E' più pratico far aprire la pagina di download in un'altra finestra,
	   ma dato che l'attributo target non è più considerato valido dal w3c
	   è meglio impostarlo via javascript */
	$('.browser_download','html body #browser_update').attr('target','_blank')
})






/*// APRI POPUP ////////////////////////////////////////////////////////////////////////////////////*/
var pagina=null;
function apriPopup(url,w,h){
	x=screen.width/2-w/2;
	y=screen.height/2-h/2;
	if (pagina != null)
		pagina.close();
	pagina=window.open(url,"","fullscreen=no,status=no,toolbar=no,scrollbars=yes,width="+w+",height="+h+",top="+y+",left="+x);
}





/*// CONTROLLO EMAIL ////////////////////////////////////////////////////////////////////////////////////*/
var whitespace = " \t\n\r";
function isEmail (s)
{
	if (isEmpty(s)) 
	   if (isEmail.arguments.length == 1) return defaultEmptyOK;
	   else return (isEmail.arguments[1] == true);
	if (isWhitespace(s)) return false;
	var i = 1;
	var sLength = s.length;
	while ((i < sLength) && (s.charAt(i) != "@")){ 
		i++
	}
	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;
	while ((i < sLength) && (s.charAt(i) != ".")){ 
		i++
	}
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}
function isEmpty(s){
	return ((s == null) || (s.length == 0))
}
function isWhitespace (s){
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}





/*// ANTI-SPAM ////////////////////////////////////////////////////////////////////////////////////*/
function DisplayMail(Server, Login, Display){
if ((Display.length == 0) || (Display.indexOf('@')+1)) {
document.write("<a href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Login + "@" + Server + "</a>"); }
else {
document.write("<a href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Display + "</a>"); }
}




/*// CAMPI FORM ////////////////////////////////////////////////////////////////////////////////////*/
	$(document).ready(function(){
		
		// REPLACE SELECT
		$("select").live("change",function () {
			var str_select_option = "";
			$(this).find("option:selected").each(function () {
				str_select_option += $(this).text() + " ";
			});
			$(this).prev("span.select_replace").text(str_select_option);
		})
		.change();
		$("select").live("keyup",function () {
			var str_select_option = "";
			$(this).find("option:selected").each(function () {
				str_select_option += $(this).text() + " ";
			});
			$(this).prev("span.select_replace").text(str_select_option);
		});
		$("select").live("focus",function () {
			$(this).prev("span.select_replace").addClass("selected");
		});
		$("select").live("blur",function () {
			$(this).prev("span.select_replace").removeClass("selected");
		});
		
		// REPLACE INPUT FILE
		$("input[type='file']").live("change",function () {
			var str_inputfile = $(this).val();
			var tmp = str_inputfile.split("\\");
			$(this).prev("span.inputfile_replace").text(tmp[tmp.length-1]);
		})
		.change();
		
	});
	
	
	
	

/*// EFFETTO ROLLOVER NAV ////////////////////////////////////////////////////////////////////////////////////*/
	$(document).ready(function(){
			$("#nav ul > li:not(.attivo) a").css( {backgroundPosition: "0 0", color: "#103b6d"} );
			$("#nav ul > li:not(.attivo)").hover(function() {
					$(this).find("> a").stop().animate({
						backgroundPosition:"(-305 0)",
						color: "#ffffff"
					}, 400);
				},function() {
					$(this).find("> a").stop().animate({
						backgroundPosition:"(0 0)",
						color: "#103b6d"
					}, 400);
				});
			$("#nav ul > li").hover(function() {
					$(this).find("ul").stop(false,true).slideDown("fast");
				},function() {
					$(this).find("ul").stop(false,true).slideUp("fast");
				});
	});
	
	
	
	
	
/*// APRI/CHIUDI LANGUAGE ////////////////////////////////////////////////////////////////////////////////////*/
	$(document).ready(function(){
		$("#top_language").hover(function() {
			$(this).find("ul").stop(false,true).slideDown("fast");
		},function() {
			$(this).find("ul").stop(false,true).slideUp("fast");
		});
	});
	
	
	
	
	
/*// APRI/CHIUDI LOGIN ////////////////////////////////////////////////////////////////////////////////////*/
	$(document).ready(function(){
		$("#top_login span").click(function() {
			$(this).parent().find("form").stop(false,true).slideToggle("fast");
		});
		/*$('#top_login').bind({
		  mouseleave: function() {
			$(this).find("form").stop(false,true).slideUp("fast");
		  }
		});*/
	});




/*// APRI/CHIUDI COL DX ////////////////////////////////////////////////////////////////////////////////////*/
	$(document).ready(function() {
		$("#col_dx_freccia_dx").click(
			function () {
				chiudiColDx();
			}
		);
		$("#col_dx_freccia_sx").click(
			function () {
				apriColDx();
			}
		);
		$("#col_dx_tab_1").click(
			function () {
				apriColDx();
				$("#col_dx_tab .tab").removeClass("attivo");
				$(this).addClass("attivo");
				$('#col_dx div[id*="col_dx_"]').hide();
				$("#col_dx_caratteristiche").fadeToggle();
				$('#col_dx div[id*="col_dx_"]').removeClass("attivo");
				$("#col_dx_caratteristiche").addClass("attivo");
				$("#col_dx_link_utili").show();
			}
		);
		$("#col_dx_tab_2").click(
			function () {
				apriColDx();
				$("#col_dx_tab .tab").removeClass("attivo");
				$(this).addClass("attivo");
				$('#col_dx div[id*="col_dx_"]').hide();
				$("#col_dx_art_correlati").fadeToggle();
				$('#col_dx div[id*="col_dx_"]').removeClass("attivo");
				$("#col_dx_art_correlati").addClass("attivo");
				$("#col_dx_link_utili").show();
			}
		);
		$("#col_dx_tab_3").click(
			function () {
				apriColDx();
				$("#col_dx_tab .tab").removeClass("attivo");
				$(this).addClass("attivo");
				$('#col_dx div[id*="col_dx_"]').hide();
				$("#col_dx_carrello").fadeToggle();
				$('#col_dx div[id*="col_dx_"]').removeClass("attivo");
				$("#col_dx_carrello").addClass("attivo");
				$("#col_dx_link_utili").show();
			}
		);
		//autoclose
		
		//alert($(window).width());
		if(attivo=='home' || (prodotti_dettaglio=='si' && $(window).width()<1200)){
			setTimeout(function(){
				chiudiColDx();			  
			},1500);
		}
		else if($(window).width()>=1200){}
		else if($(window).width()<1200){
			$("#col_dx").width('26');
			$("#col_dx_freccia_dx").css("display", "none");
			$("#col_dx_freccia_sx").css("display", "block");
			//$("#content_main").css("marginRight","26");	
			//$("#content_main").css("display", "block");
			$("#content_main").css("margin-right",26);	
			box_id_tmp = $('#col_dx div.attivo').attr("id");
			$('#col_dx div[id*="col_dx_"]').hide();
			
		}
	});
	function chiudiColDx(){
		$("#col_dx").animate({width: '26'}, 500, function () {
			box_id_tmp = $('#col_dx div.attivo').attr("id");
			//alert(box_id_tmp);
			$('#col_dx div[id*="col_dx_"]').hide();
		});
		$("#col_dx_freccia_dx").css("display", "none");
		$("#col_dx_freccia_sx").css("display", "block");
		$("#content_main").animate({"margin-right": '26'}, 500);
		setTimeout(function(){
			$("body").trigger("init_mappa");	  
		},500);
	}
	function apriColDx(){
		if($("#col_dx").width()=='26'){
			$("#col_dx").animate({width: '299'}, 500);
			$("#col_dx_freccia_dx").css("display", "block");
			$("#col_dx_freccia_sx").css("display", "none");
			if(box_id_tmp){
				$("#"+box_id_tmp+"").show();
			} else {
				$("#col_dx div").show();
			}
			$("#col_dx_link_utili").show();
			$("#content_main").animate({"margin-right": 299}, 500);
			setTimeout(function(){
				$("body").trigger("init_mappa");	  
			},500);
		}
	}
	
	
	
	
/*// EFFETTO ROLLOVER BOX HOME ////////////////////////////////////////////////////////////////////////////////////*/
	$(document).ready(function(){
			$(".fx_box_hover a").find("span").hide();
			$(".fx_box_hover a").find("strong").hide();
			$(".fx_box_hover a:not(.attivo)").hover(function() {
					$(this).find("span").show();
					$(this).find("strong").show();
					$(this).find("img").stop().animate({
						opacity: 0.30
					}, 200);
				},function() {
					$(this).find("span").hide();
					$(this).find("strong").hide();
					$(this).find("img").stop().animate({
						opacity: 1.00
					}, 200);
				});
	});
