$(document).ready(function(){
	// destinazioni a colonne
	$('#wrap-coloumns').masonry();
	
	// DATEPICKER
	// impostazione la localizzazione
	$.datepicker.setDefaults($.datepicker.regional['it']);
	// inizializzo il calendario
	var dates = $( "#data_inizio, #data_fine" ).datepicker({
	        showOn: 'both',
	        changeMonth: true,
			changeYear: true,
	        numberOfMonths: 1,
			buttonImage: './layout/icone/calendar.png',
			buttonImageOnly: true,
	        onSelect: function( selectedDate ) {
	                var option = this.id == "data_inizio" ? "minDate" : "maxDate",
	                        instance = $( this ).data( "datepicker" ),
	                        date = $.datepicker.parseDate(
	                                instance.settings.dateFormat ||
	                                $.datepicker._defaults.dateFormat,
	                                selectedDate, instance.settings );
	                dates.not( this ).datepicker( "option", option, date );
	        }
	});
	
	
	// increase the default animation speed to exaggerate the effect
	$.fx.speeds._default = 300;
	
	$("#multi-dest").dialog({
		closeOnEscape: true,
		width: 850,
		height: 550,
		autoOpen: false,
		show: "slide",
		hide: "drop"
	});

	$("#txt_destinazioni").click(function() {
		$("#multi-dest").dialog("open");
		return false;
	});
	
	$(".gruppo input:checkbox").live("click", function(){
		var dests = "";
		$("#multi-dest input").each(function() {
			if($(this).is(':checked')) {
				dests += $(this).next().text()+", ";				
			}
		});
		
		if(dests != "")
			$("#txt_destinazioni").val(dests);
		else $("#txt_destinazioni").val("Destinazioni");
		
		if($(this).is(':checked'))
			$("#all_destinazioni").append("<input type='hidden' id='dst-"+$(this).val()+"' name='destinazioni[]' value='"+$(this).val()+"' />");
		else $("#all_destinazioni").find("#dst-"+$(this).val()).remove();
	});
	
	$("#multi-dest .avanti a").live("click", function () {
		$("#multi-dest").dialog("close");
	});
});
