// DATE PICKER FOR BOOKING FORM
	/*Fancybox*/
	$(".group").fancybox({
		titlePosition: 'over'
	});
	
	/*Gestione calendario nella booking*/
	$(function() {
	jQuery(function(){	
		// initialise the "Select date" link
		var tdy = new Date();
		//$("#debug .line1").html("tdy.asString="+tdy.asString());
		var enddate= new Date(tdy.gettime+63000000);
		jQuery('.date-pick')
			.datePicker(
	
				//associate the link with a date picker
				{
					createButton:false,
					startDate:tdy.asString(),
					endDate:enddate.asString()
				}
			).bind(
				// when the link is clicked display the date picker
				'click',
				function()
				{	
					updateSelects(jQuery(this).dpGetSelected()[0]);
					jQuery(this).dpDisplay();
					return false;
				}
			).bind(
				// when a date is selected update the SELECTs
				'dateSelected',
				function(e, selectedDate, $td, state)
				{
					updateSelects(selectedDate);
				}
			).bind(
				'dpClosed',
				function(e, selected)
				{
					updateSelects(selected[0]);
				}
			);
			
		var updateSelects = function (selectedDate)
		{
			var selectedDate = new Date(selectedDate);
			//alert(selectedDate.asString());
			jQuery('#d option[value=' + (selectedDate.getDate()) + ']').attr('selected', 'selected');
			jQuery('#m option[value=' + (selectedDate.getMonth())+ ']').attr('selected', 'selected');
			jQuery('#y option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
			
			/*
			$("#debug .line2").html("#d = "+jQuery('#d option[value=' + (selectedDate.getDate()) + ']').val()+" = "+jQuery('#d option[value=' + (selectedDate.getDate()) + ']').attr('selected'));
			$("#debug .line3").html("#m = "+jQuery('#m option[value=' + (selectedDate.getMonth()) + ']').val()+" = "+jQuery('#m option[value=' + (selectedDate.getMonth()) + ']').attr('selected'));
			$("#debug .line4").html("#y = "+jQuery('#y option[value=' + (selectedDate.getFullYear()) + ']').val()+" = "+jQuery('#y option[value=' + (selectedDate.getFullYear()) + ']').attr('selected')); */
		}
		// listen for when the selects are changed and update the picker
		jQuery('#d, #m, #y')
			.bind(
				'change',
				function()
				{
					var d = new Date(
								jQuery('#y').val(),
								jQuery('#m').val(),
								jQuery('#d').val()
								);
					jQuery('#date-pick').dpSetSelected(d.asString());
				}
			);
		
		// default the position of the selects to today
		var today = new Date();
		updateSelects(today.getTime());
		
		// and update the datePicker to reflect it...
		jQuery('#d').trigger('change');
		});
	});
	
	
	function check_date() {	
		//var date_input = document.input_date.value;
		var date_input = document.idForm.input_date.value
		var dd = date_input.substring(0,2);
		var mm = date_input.substring(3,5);
		var yy = date_input.substring(6,10);
		document.idForm.fromday.value = dd;
		document.idForm.frommonth.value = mm;
		document.idForm.fromyear.value = yy;	
		//alert(dd + "/" + mm + "/" + yy);
	}
	
	
	/*Personalizzazione select booking form*/
	$('.my-dropdown').sSelect();	
	
	// BOOK NOW LINK
	$(function() {	
		$("a[class='cat_12']").click(function(){											 
			hhotelSearchGroup('mozart', '', '', '', '');
			return false;
		});
	});
	
	$("li.cat-id-12 a").click(function(){
		hhotelSearchGroup('mozart', '', '', '', '');
		return false;
	});
	
	/*Effetto Carousel offerte a destra*/	
	jQuery('#mycarousel').jcarousel({
        scroll: 1
    });
	 
	/*Effetto Carousel offerte a destra*/	
	jQuery('#mycarousel_photo').jcarousel({
        scroll: 1
    });
		
	
	// EFFETTO FADE OFFERS / EVENTS
	$('#list_items .image_box a').each(function() {
		var linked_listpage;
		 $(this).click(function() {			
			linked_listpage = $(this).attr('href') + ' #offevent_detail';
			$('#offevent_detail').fadeOut(300, function() {
				$('#offevent_detail').load(linked_listpage, function() {
					$('#offevent_detail').fadeIn(300);
				});
			});			
			return false;
		});
	});
	
	$('#list_items .txt_preview .more a').each(function() {
		var linked_listpage;
		 $(this).click(function() {			
			linked_listpage = $(this).attr('href') + ' #offevent_detail';			
			$('#offevent_detail').fadeOut(300, function() {
				$('#offevent_detail').load(linked_listpage, function() {
					$('#offevent_detail').fadeIn(300);
				});
			});			
			return false;
		});
	});
	
		
	// VIEW ALL delle pagine eventi / offerte
	$('#view_all').click(function(){
		$('.featured').fadeOut(500);
		$('.all_hidden').fadeIn(500);
		$(this).css("display","none");
		return false;
	});
	
	
	// Guest comments pager
	$('#guestcomments .paging').find('a').live('click', function () {
		var that = $(this);
		$('#guestcomments').height($('#guestcomments-container').height()).addClass('loading');
		$('#guestcomments').fadeOut(200, function () {
			$(this).load(that.attr('href') + ' #guestcomments > *', function  () {
				$(this).fadeIn(200);
				$('#guestcomments-container').height('auto').removeClass('loading');
			});
		});
		return false;
	});
	
	
	// VISUALIZZO LA RISPOSTA DELLA FAQ E L'EVENTO IN HOMEPAGE
	$(".story .full_box .title a").click(function(){
		var hidden_id = parseInt($(this).parent('.title').attr('id').replace('h_', ''), 10);
		// nascodo tutte le risposte aperte
		$(".story .full_box .body").each(function() {	
			$(this).hide(1000);	
			//console.log(hidden_id);
			$(".full_box .title").removeClass("link_open");
			$(".full_box .title").addClass("link_close");
		});	
		
		$(".story .full_box #risp_" + hidden_id).show(1000);	
		$(".full_box #h_" + hidden_id).removeClass("link_close");
		$(".full_box #h_" + hidden_id).addClass("link_open");
		/*$(".story .full_box #freccia_" + hidden_id).hide(1000);*/	
		return false;	
	});


	$(function() {
		start();
	});