$(document).ready(function(){
		start();
		$('a.cat_81').attr('target','_blank');
		$('a.cat_80').attr('target','_blank');
		$('a.cat_88').attr('target','_blank');
		$('a.cat_88').attr('href','https://fidely.net/v2/adminFNET/users/login.php?codgroup=b7f98ddfca4c5fa3373603509650c19c&lang=ITA');
		$('#main_menu li.prima').hover(
		                  function(){
						  // mostra sottomenu
						  $(this).find('#sub_menu').stop(true, true).delay(50).slideDown(100);
						            },
						  function(){
                          //nascondi sottomenu
						  $(this).find('#sub_menu').stop(true, true).delay(75).slideUp(200);
						            }
     );
		
		// H1 centered
		/*var lungh1 = parseInt($('#heading h1').outerWidth(),10) , lungspan = parseInt($('#heading span').outerWidth(),10);
		padd = (960-(lungh1+lungspan))/2;
		$('#heading h1').css('padding-left',padd+'px');*/
		
});
$(function(){
	$("#bf select").uniform();

	/* */
	$('#single_item a#btn_view_spa').click (function() {
		$('#single_item #list').show(100);
		return false;
	});
	
	
	/* MORE_INFO */
	/*all_hidden: per aprire items senza aver schiacciato view all*/
	$('.all_hidden #list a.more_info').click (function() {		
		var hidden_id = parseInt($(this).attr('id').replace('h_', ''), 10); 									 	
//		alert(hidden_id);
		
		$(this).closest(".all_hidden #list .item").addClass('height_ie6'); 
		// alert(hidden_id);
		$('.all_hidden #list .info #body_' + hidden_id).show(100);
		//for IE
		/*
		$('.all_hidden #list .info #body_' + hidden_id).css('display','block');
		$('.all_hidden #list .info #body_' + hidden_id).css('visibility','visible');
		$('.all_hidden #list .info #h_' + hidden_id).css('display',' none');
		*/
		$('.all_hidden #list .info #h_' + hidden_id).hide(100);
		$('.all_hidden #list .info #book_now_'+ hidden_id).removeClass('hidden');
		$('.all_hidden #list .info #close_'+ hidden_id).removeClass('hidden');
		return false;
	});
	
	// close della lista hidden
	$('.all_hidden #list .close a').click (function() {
		//alert("qui");
		var hidd_id = parseInt($(this).parent('.close').attr('id').replace('close_', ''), 10); 									 	
		//alert(hidd_id);
		$('.all_hidden #list .info #body_' + hidd_id).fadeOut(100);
		$('.all_hidden #list .info #h_' + hidd_id).show(100);
		$('.all_hidden #list .info #book_now_'+ hidd_id).addClass('hidden');
		$('.all_hidden #list .info #close_'+ hidd_id).addClass('hidden');
		return false;
	});

	
	/*featured: per aprire items una volta selezionato view all*/
	$('.featured #list a.more_info').click (function() {
		var hidden_id = parseInt($(this).attr('id').replace('h_', ''), 10); 									 	
		//alert(hidden_id);
		
		// $(this).closest(".featured #list .item").addClass('height_ie6'); 
		//alert(parent_item);
		/*$('.featured #list .info #body_'+hidden_id).show(100);
		
		$('.featured #list .info a#h_'+hidden_id).hide(100);
		$('.featured #list .info #book_now_'+hidden_id).removeClass('hidden');
		$('.featured #list .info #close_'+hidden_id).removeClass('hidden');
		*/
		$(this).closest(".featured #list .item").addClass('height_ie6'); 
		// alert(hidden_id);
	  //	$('.featured #list .info #body_' + hidden_id).show(100);
		$(this).parent().find('.body').show(100);
		//for IE
		/*
		$('.featured #list .info #body_' + hidden_id).css('display','block');
		$('.featured #list .info #body_' + hidden_id).css('visibility','visible');
		$('.featured #list .info #h_' + hidden_id).css('display',' none');
		*/
		$(this).hide(100);
		$(this).parent().find('.booknow').removeClass('hidden');
		$(this).parent().find('.close').removeClass('hidden');
		
		
		return false;
	});
	
	// close della lista featured
	$('.featured #list .close a').click (function() {
		//alert("qui");
		var hidd_id = parseInt($(this).parent('.close').attr('id').replace('close_', ''), 10); 									 	
		//alert(hidd_id);
		$(this).parent().parent().find('.body').fadeOut(100);
		$(this).parent().parent().find('.more_info').show(100);
		$(this).parent().parent().find('.booknow').addClass('hidden');
		$(this).fadeOut(100).addClass('hidden');
		return false;
	});
	
	
	
	
	
	/* VIEW ALL PRESS KIT */
	$('#view_ist').click (function() {
		$('.hidden-box-ist').fadeIn(500);
		$('#view_ist').css("display","none");
		$('#close_ist').css("display","block");
		return false;
	});
	$('#close_ist').click (function() {
		$('.hidden-box-ist').fadeOut(500);
		$('#view_ist').css("display","block");
		$('#close_ist').css("display","none");
		return false;
	});
	
	$('#view_par').click (function() {
		$('.hidden-box-par').fadeIn(500);
		$('#view_par').css("display","none");
		$('#close_par').css("display","block");
		return false;
	});
	$('#close_par').click (function() {
		$('.hidden-box-par').fadeOut(500);
		$('#view_par').css("display","block");
		$('#close_par').css("display","none");
		return false;
	});
	
});


function check_form_work() {
	$("#txtname").css('border','1px solid #999');
	$("#txtsurname").css('border','1px solid #999');
	$("#txtphone").css('border','1px solid #999');
	$("#txtemail").css('border','1px solid #999');
	
	var txtname = document.work_form.txtname.value;
	var txtsurname = document.work_form.txtsurname.value;
	var txtphone = document.work_form.txtphone.value;
	var txtemail = document.work_form.txtemail.value;
	var varcheck = "true";
	
	if (txtname=="") {
		$("#txtname").css('border','1px solid red');
		var varcheck = "false";
	}
	if (txtsurname=="") {
		$("#txtsurname").css('border','1px solid red');
		var varcheck = "false";
	}
	
	if (txtphone=="") {
		$("#txtphone").css('border','1px solid red');	
		var varcheck = "false";
	}
	
	if (txtemail=="") {
		$("#txtemail").css('border','1px solid red');	
		var varcheck = "false";
	}
	
	/* INVIO */
	if (varcheck=="true") {
		//alert("invio email effettuato correttamente!");
		$("#form_work .sending").slideDown();
		return true;
	} else {
		return false;
	}
}



/*Gestione calendario nella booking*/
$(function() {
jQuery(function(){
	
	// initialise the "Select date" link
	jQuery('.date-pick')
		.datePicker(

			/*associate the link with a date picker*/
			{
				createButton:false,
				startDate:'<?php echo date("d/m/Y"); ?>',
				endDate:'<?php echo date("d/m/Y",time() + 63000000); ?>'
			}
		).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);
		jQuery('#d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
		jQuery('#m option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
		jQuery('#y option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', '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()-1,
							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);
}


$(function() {
	$(document).pngFix(); 
});




	// NASCONDO TUUTE LE RISPOSTE DELLE FAQ
	$(".faq_box .answer").each(function() {	
		$(this).css("display","none");
	});
	
	
	// VISUALIZZO LA RISPOSTA DELLA FAQ
	$(".link_faq").click(function(){
									
		
		var hidden_id = parseInt($(this).parent('.moreinfo').attr('id').replace('h_', ''), 10); 
		$(".full_box #risp_" + hidden_id).show(500);
		
		
		
		// nascodo tutte le risposte aperte
		//console.log("qui");
		/*
		$(".faq_box .answer").each(function() {	
			$(this).hide(1000);
		});
		*/		
		
		return false;
	});





// BOOK NOW LINK
$("[class*='cat-id-19']").attr('href', 'javascript:;');
$("[class*='cat-id-19']").click(function(){
	hhotelSearch('ITCORCristallo', '', '', '', '', '', '');
	return false;
});


// GESTIONE DEGLI ITEM DELLE LIST PAGE
$(document).ready(function() {
	$('#listpage_col_dx .list_box').each(function() {
		var linked_page;
		 $(this).find('.titolo').children('a').click(function() {
			linked_page = $(this).attr('href') + ' #offer_content';
			$('#listpage_col_dx .list_box').find('.sfondo_item_preview').removeClass('selected');			
			$(this).parents('.sfondo_item_preview').addClass('selected');
			$('#offer_content').fadeOut(300, function() {				
				$('#offer_content').load(linked_page, function() {					
					$('#offer_content').fadeIn(300);
				});
			});
			return false;
		});
	});	
	
	// VIEW ALL delle pagine eventi / offerte
	$('#view_all').click(function(){
	//alert('test');
		// $('.featured').fadeOut(500);
		$('#single_item .featured').hide();
		//$('.all_hidden').fadeIn(500);
		$('#single_item .all_hidden').show();
		// $(this).css("display","none");
		// return false;
	});
	
});


$(function() {
		   
	$('#hidden_box').click (function() {
		//alert("qui");
		$('#content #offer_content .txt .btn_more').css("display","none");
/*		$('#content #offer_content .txt .body').css("display","block");*/
		$('#content #offer_content .txt .body').show(200);
		return false;
	});
		   
	//start();
	
	
	// VISUALIZZO LA RISPOSTA DELLA FAQ
	$("#faq .story .full_box .moreinfo a").click(function(){
		
		var hidden_id = parseInt($(this).parent('.moreinfo').attr('id').replace('h_', ''), 10); 
		
		$("#faq .story .full_box .moreinfo").each(function() {
			$('.faq_body').hide(800);
			$('#faq .story .full_box .moreinfo a').removeClass('current');
		});
		
		$(this).addClass('current');
		
		$('#risp_'+hidden_id).show(500);
		return false;
	});
	
	
	
	/* POP-UP METEO */
	$('#meteo').click(function() {
		$('#meteo_hidden').fadeIn(500);
		return false;
	});
	$('#meteo_hidden #close').click(function() {
		$('#meteo_hidden').fadeOut(200);
		return false;
	});
	
	
	$('#view_seedling').click(function() {
		//$('#meteo_hidden').fadeIn(500);
		alert("qui");
		return false;
	});
	
	
	
	// PHOTOGALLERY SOTTOMENU
	$('ul.level_0 a.cat_54').click(function() {
		var box_hidden = $('ul.level_1').css("display");
		//alert("qui");
		if (box_hidden=="none") {
			$('ul.level_1').show(400);
		} else {
			$('ul.level_1').hide(400);
			return false;
		}
		
	});

	// GALLERY
	if($('.photogallery').length > 0){
		$('a[rel=group]').fancybox();
	}
	
});

$(document).ready(function(){

	// SLIDESHOW
	if($('#slideshow').length > 0){
		$('#slideshow').cycle();
	}
	// SLIDESHOW HIGHLIGHT
	if($('#slideshow_highlight').length > 0){
		$('#slideshow_highlight ul').cycle({
			prev:   '#hs_prev',
			next:   '#hs_next',
	    cleartype:     !$.support.opacity,
	    cleartypeNoBg: true
		});
	}


	/*Slideshow Homepage*/
	//slideShow();
});

/*SLIDESHOW HOMEPAGE*/
function slideShow() {
	//$('#flash_test .first').css({opacity: 1.0});
	$('#flash_test .caption').css({width: "925px"});
	$('#flash_test .content').html($('#flash_test img.first').attr('rel'));
	setInterval('gallery()',5000);
}

function gallery() {
	var current = ($('#flash_test img.show')?  $('#flash_test img.show') : $('#flash_test img.first'));
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#flash_test img.first') :current.next()) : $('#flash_test img.first'));	
	var caption = next.attr('rel');	
	//Hide the current image
	current.animate({opacity: 0.0}, 2000).removeClass('show');
	next.css('opacity', 0.0)
	.addClass('show')
	.animate({opacity: 1.0}, 2000);


	$('#flash_test .caption').animate({height: '1px'}, { queue:true, duration:500 });
	$('#flash_test .caption .content').animate({height: '1px'}, { queue:true, duration:500 });
	$('#flash_test .caption').animate({height: '80px'},700 );
	$('#flash_test .content').html(caption);	
}
/*FINE SLIDESHOW HOMEPAGE*/
