$(function() {
	
	// MOUSE OVER - MENU GROUP HOTEL
	$("ul.subcategories li.first-level").mouseout(function(){
		var hidden_id = parseInt($(this).attr('id').replace('menu-', ''), 10); 
		$('#submenu-'+hidden_id).css('display','none');
		/*
		$("ul.subcategory-hidden").mouseout(function(){
			//$('#submenu-'+hidden_id).css('display','none');
		}).mouseover(function(){
			//$('#submenu-'+hidden_id).css('display','block');
		});		
		*/
    }).mouseover(function(){
		var hidden_id = parseInt($(this).attr('id').replace('menu-', ''), 10); 
		var box_hidden = $('#submenu-'+hidden_id).css('display');
		
		/*
		$(".subcategory-hidden").each(function() {	
		//	$(this).css('display','none');								   
		});
		*/
		$('#submenu-'+hidden_id).css('display','block');
    });


	/*	
	$('#submenu-7 li a').click(function() {
		var element_id = parseInt($(this).attr('class').replace('cat_', ''), 10); 
		//alert(element_id);
		//$(".cat_"+element_id).click();
		return false;
	});
	*/


	
	
	//   B O O K I N G   F O R M
	$(".bf_box select, .bf_box_hotel select, #select_zone, #select_hotel").uniform();	
	start();  
	$('#shadow-top, .more').ifixpng(); 
	
	//   HEIGHT SECOND COLUMNS 
	var h_first_two_columns = $('.first-two-columns').height();
	var h_second = $('.second').height();
	if (h_first_two_columns>h_second) {
		$('.second').css("height",h_first_two_columns+30);
	}
	
	
	$('#loading').addClass('hidden');
//	$('#booking_form').removeClass('hidden');
//	$('#select_zone').removeClass('hidden');
//	$('#select_hotel').removeClass('hidden');
	$('#booking_form').fadeIn(100);
	$('.select_zone').fadeIn(2500);
	$('.select_hotel').fadeIn(2500);
	
	
	/* GROUP HOTELS - PROFESSIONAL (SOTTOCATEGORIE) */
	$('#content_box #two-columns #submenu a').click(function() {
		$('#sent_email').css('display','none');
		$("#content_box #two-columns #submenu a").each(function() {	
			$(this).css('color','#666666');	
		});	
		$(this).css('color','#f90');
		
		linked_page = $(this).attr('href') + ' .column-visible';
		$('#hide').load(linked_page, function() {});
		return false;
	});



	$('.home-page a.jq_more').click(function(){									 	
		linked_page = $(this).attr('href');
		location.href = linked_page;
		return false;
	});
	
	/* LIST PAGE DEI SINGOLI HOTEL (SPA) */
	$('a.jq_more').click(function(){
							
		$(".thumbnail").each(function() {	
			$(this).css('background','none');	
		});						  
								  
		var element_id = parseInt($(this).parent('.thumbnail').attr('id').replace('thb_', ''), 10); 
		// alert(element_id);
		
		linked_page = $(this).attr('href') + ' .second-hotel > *';
		$('.second-hotel').load(linked_page, function() {
			$('#gallery a').lightBox();
		});
		
		$('#thb_'+element_id).css('background','#353535');
		
		return false;
	});
	
	
	
	
	/* PAGE (con list-items) DEI SINGOLI HOTEL (SPA) */
	$('a.jq_more_list').live('click', function() {
		var element_id = parseInt($(this).parent('li').attr('id').replace('li_', ''), 10); 									   
		//alert(element_id);
		linked_page = $(this).attr('href') + ' .second-hotel-large > *';
		$('.second-hotel-large').load(linked_page, function() {
			$('#li_'+element_id).css('background','#353535');													
		});
		
		return false;
	});
	
	
	$('a.more-submenu').live('click', function() {
		$(".thumbnail").each(function() {	
			$(this).css('background','none');	
		});				
		var element_id = parseInt($(this).attr('id').replace('submenu_', ''), 10); 
		//alert(element_id);
		linked_page = $(this).attr('href') + ' .second-hotel > *';
		$('.second-hotel').load(linked_page, function() {
			$('#gallery a').lightBox();
		});
		
		$('#thb_'+element_id).css('background','#353535');
		
		return false;
	});

	
	/*******************************************************************************
	********************* 		C A L E N D A R 		****************************
	********************************************************************************/
	/*Gestione calendario nella booking*/
	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]);
				}
			);
			
			// $('.selector').datepicker({ showOptions: {direction: 'up'});
			
		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_form() {
	
	var txt_name 		= document.form_send_email.txt_name.value;
	var area_address 	= document.form_send_email.area_address.value;
	var txt_city 		= document.form_send_email.txt_city.value;
	var txt_state 		= document.form_send_email.txt_state.value;
	var txt_cif 		= document.form_send_email.txt_cif.value;
	
	var txt_zip 		= document.form_send_email.txt_zip.value;
	var sel_country 	= document.form_send_email.sel_country.value;
	var txt_phone 		= document.form_send_email.txt_phone.value;
	var txt_fax 		= document.form_send_email.txt_fax.value;
	var txt_email 		= document.form_send_email.txt_email.value;
	
	var txt_person_name 	= document.form_send_email.txt_person_name.value;
	var txt_person_lastname = document.form_send_email.txt_person_lastname.value;
	var txt_person_depar	= document.form_send_email.txt_person_depar.value;
	var txt_person_contact 	= document.form_send_email.txt_person_contact.value;
	var txt_iata 			= document.form_send_email.txt_iata.value;
	
	if ( (txt_name=="") || (area_address=="")|| (txt_city=="") || (txt_state=="") || (txt_cif=="") || (txt_zip=="") || (sel_country=="") || (txt_phone=="") || (txt_fax=="") || (txt_email=="") || (txt_person_name=="") || (txt_person_lastname=="") || (txt_person_depar=="") || (txt_person_contact=="") || (txt_iata=="") ) {
		var check_fields = false;
		alert("Riempire tutti i campi!");
		return false;	
	} else {
		var check_fields = true;
		return true;		
	}
}



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 check_zone() {
	var selected = document.getElementById('select_zone').value;
	//alert(selected);
	//document.Form_Zone.submit();
	$('#Form_Zone').submit();
}
	

function check_hotel() {
	var selected_hotel = document.getElementById('select_hotel').value;
	location.href = selected_hotel;
}


function check_hotel_guest() {
	//var selected = document.getElementById('select_zone').value;
	//alert(selected);
	//document.Form_Zone.submit();
	$('#Form_Hotel').submit();
}