$(document).ready(function() {

// Datepicker
	var partenzamax;
	var ritornomin;
	$("#ritorno").change(function() {
	  partenzamax = $("#ritorno").val();
	  $("#partenza").datepicker("destroy");
	  $("#partenza").datepicker({maxDate: partenzamax});
	});
	$("#partenza").change(function() {
	  ritornomin = $("#partenza").val();
	  $("#ritorno").datepicker("destroy");
  	  $("#ritorno").datepicker({minDate: ritornomin});
	});
	$("#partenza").datepicker({maxDate: partenzamax});
	$("#ritorno").datepicker({minDate: ritornomin});
	
	
// Form
	$("#username").focus(function() {
	  if ($("#username").val() == "Username") {
	    $("#username").val("");
	  }
	});
	$("#username").blur(function() {
	  if (!$("#username").val()) {
		$("#username").val("Username");
	  }
	});

	$("#password").focus(function() {
	  if ($("#password").val() == "Password") {
	    $("#password").replaceWith("<input type=\"password\" id=\"password_pwd\" value=\"\" />");
	  }
	});

	$("#email").focus(function() {
	  if ($("#email").val() == "Inserisci il tuo indirizzo e-mail") {
	    $("#email").val("");
	  }
	});
	$("#email").blur(function() {
	  if (!$("#email").val()) {
		$("#email").val("Inserisci il tuo indirizzo e-mail");
	  }
	});

	$("#map_sondrio,#map_morbegno,#map_chiavenna").click(
      function(e) {
        var cx;
        var cy;
        $("#popup").show();
        if (e.currentTarget.id == 'map_sondrio') {
         cx = 46.16772;
         cy = 9.872546;
        }
        if (e.currentTarget.id == 'map_morbegno') {
         cx = 46.131954;
         cy = 9.535253;
        }
        if (e.currentTarget.id == 'map_chiavenna') {
         cx = 46.321075;
         cy = 9.398675;
        }
        if (GBrowserIsCompatible()) {
      	var map = new GMap2(document.getElementById("popup-content"));
      	map.setCenter(new GLatLng(cx,cy), 12);
      	map.setMapType(G_NORMAL_MAP);
      	map.setUIToDefault();
      	var point = new GLatLng(cx,cy);
      	map.addOverlay(new GMarker(point));
      	map.disableScrollWheelZoom();
        }
      }
   );

   $("#popup-close").click(
      function() {
         $("#popup").hide();
      }
   );


// Stelle hotel
    $('p.hotel').each(function(i) {
        var text = $(this).html();
        var stars = text.replace(/\*/g, "<img src=\"images/static/star.png\" />");
		$(this).html(stars);
	});

	flashembed("header-video",
		{ src: '/flash/video.swf',
		  width: 746,
		  height: 281,
		  wmode: 'transparent'
	   }
	);

	if ($("#tabella_prezzi").width() > 660) {
      $("#tabella_prezzi").hover(
         function () {
            $("#prezzi").animate({
               width: $("#tabella_prezzi").width(),
               left: 910 - $("#tabella_prezzi").width() - 250
            });
         },
         function () {
            $("#prezzi").animate({
               width: 660,
               left: 0
            });
         }
      );
   }

   $('.popup').click( function() {
      window.open( $(this).attr('href'), 'popup', 'width=500, height=300' );
      return false;
   });
   
   $('.unsubscribe').click( function() {
      window.open( $(this).attr('href'), 'unsubscribe', 'width=500, height=300' );
      return false;
   });
   
   $('.inviaamico').click( function() {
      window.open( $(this).attr('href'), 'unsubscribe', 'width=500, height=300' );
      return false;
   });

   $('.lightbox').lightBox();
});

function Cerca() {
   $("#cerca-vacanza").submit();
}

function Iscriviti() {
   $("#mailinglist").submit();
}
