/*// 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>"); }
}


/* CLEAR LOGIN FIELDS  ////////////////////////////////////////////////////////////////////////////////////*/
function clearFormUsername() {
	document.login.username.value = "";
}
function clearFormPassword() {
	document.login.password.value = "";
}



/*// 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();
		
	});

	


	/* start document.ready */
$(document).ready(function() {

	/* VIDEO HOVER ////////////////////////////////////////////////////////////////////////////////////*/
		//$(".video-list strong").css("display", "none");
				$(".video-list a").hover(function() {
					$(this).find("span").stop(false,true).fadeOut("fast");
					$(this).find("img").stop(false,true).fadeTo("fast", 0.7);
					$(this).find("strong").stop(false,true).slideDown(200);
				},function() {
					$(this).find("span").stop(false,true).fadeIn("slow");
					$(this).find("img").stop(false,true).fadeTo("fast", 1);
					$(this).find("strong").stop(false,true).slideUp(600);
				});

	/* APERTURA MAPPA ////////////////////////////////////////////////////////////////////////////////////*/
  $('.mappa').css({height: '0px'});
  $('.dove-siamo button').click(function(){
    var gt = $('.mappa').offset().top;
    var wh = $(window).height();
    var ot = $(document).scrollTop();
    if(ot + wh < gt + 460) {
      $('body').animate({scrollTop: (gt - wh +460)}, 1000);
    }
    $('.mappa').animate({height: '460px'}, 1000);
	$(".mappa").animate({"margin-bottom": '25px'}, 500);
	$(".dove-siamo .btn").css("background", "url('../images/arrow_3.gif') no-repeat scroll 50% 100% ");
	$(".dove-siamo .btn button").css("color", "#454545");
	$(".dove-siamo .btn button").css("background", "url('../images/map-marker.png') scroll no-repeat 7px center #e8e8e8");
	$(".dove-siamo .btn button").css("cursor", "default");
  });
  $('.mappa button').click(function() {
    $('.mappa').animate({height: '0px'}, 1000);
	$(".mappa").animate({"margin-bottom": '0px'}, 500);
	$(".dove-siamo .btn").css("background", "none").fadeTo("fast", 1);
	$(".dove-siamo .btn button").css("color", "#ffffff");
	$(".dove-siamo .btn button").css("background", "url('../images/map-marker-white.png') scroll no-repeat 7px center #bd0069");
	$(".dove-siamo .btn button").css("cursor", "pointer");
  });

  /* APERTURA MAPPA STORE ////////////////////////////////////////////////////////////////////////////////////*/
  $('.mappa-shop').css({height: '0px'});
  $('.mappa-store button').click(function(){
    var gt = $('.mappa-shop').offset().top;
    var wh = $(window).height();
    var ot = $(document).scrollTop();
    if(ot + wh < gt + 460) {
      $('body').animate({scrollTop: (gt - wh +460)}, 1000);
    }
    $('.mappa-shop').animate({height: '460px'}, 1000);
	$(".mappa-shop").animate({"margin-bottom": '25px'}, 500);
	$(".mappa-store .btn").css("background", "url('../images/arrow_3.gif') no-repeat scroll 50% 100% ");
	$(".mappa-store .btn button").css("color", "#454545");
	$(".mappa-store .btn button").css("background", "url('../images/map-marker.png') scroll no-repeat 7px center #e8e8e8");
	$(".mappa-store .btn button").css("cursor", "default");
  });
  $('.mappa-shop button').click(function() {
    $('.mappa-shop').animate({height: '0px'}, 1000);
	$(".mappa-shop").animate({"margin-bottom": '0px'}, 500);
	$(".mappa-store .btn").css("background", "none").fadeTo("fast", 1);
	$(".mappa-store .btn button").css("color", "#ffffff");
	$(".mappa-store .btn button").css("background", "url('../images/map-marker-white.png') scroll no-repeat 7px center #bd0069");
	$(".mappa-store .btn button").css("cursor", "pointer");
  });



	/* APERTURA LOGIN ////////////////////////////////////////////////////////////////////////////////////*/
  $('#login').css({height: '0px'});
  $("#login form").stop(false,true).fadeTo("fast", 0);
	$('#headerTop .btn_login').click(function(){
    var gt = $('#login').offset().top;
    var wh = $(window).height();
    var ot = $(document).scrollTop();
    if(ot + wh < gt + 160) {
      $('body').animate({scrollTop: (gt - wh +160)}, 1000);
    }
	$('#login').animate({height:'45px'},{duration:2000, easing: 'easeOutQuint'});
	$("#login form").stop(false,true).fadeTo("slow", 1);

  });
  $('#login').mouseleave(function() {
	 //$("#login form").stop(false,true).fadeTo("slow", 0);
	$('#login').animate({height:'0px'},{duration:1000, easing: 'easeOutQuint'});
  });



  });
