// JavaScript Document
/**/
Cufon.replace('.font-ds', { fontFamily: 'droidserif' });
Cufon.replace('.font-mb', { fontFamily: 'tango' });
$(document).ready(function() {
		
	/*
	 * remove the no_js class so the dropdowns won't be displayed via CSS:
	 */
	$('.dropMenu').css("display","none");
	$('#main_nav li').removeClass("no_js");	
	
	$("#sliderhome").hover(shownav,hidenav);
	$(".shownav").hover(shownav,shownav);

	var hoverconfig = {    
	     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
	     interval: 30, // number = milliseconds for onMouseOver polling interval    
	     over: openMenu, // function = onMouseOver callback (REQUIRED)    
	     timeout: 100, // number = milliseconds delay before onMouseOut    
	     out: closeMenu // function = onMouseOut callback (REQUIRED)    
	};

	$('.subnavWrap').hoverIntent( hoverconfig );

	function openMenu() {
		$(this).children('.dropMenu').slideDown(150);
	//	$(this).children('.tier_arrow').hide();
	}
	
	function closeMenu() {
	//	$(this).children('.tier_arrow').show();
		$(this).children('.dropMenu').slideUp(50);
	}


	function shownav() {
		$('.shownav').css("display","block");
	}
	function hidenav() {
		$('.shownav').css("display","none");
	}
	
//*GALLERY*//
var galleries = $('.ad-gallery').adGallery({
  loader_image: 'img/loader.gif',
  width: false, //338, // Width of the image, set to false and it will read the CSS width
  height: false, //400, // Height of the image, set to false and it will read the CSS height
  thumb_opacity: 0.7, // Opacity that the thumbs fades to/from, (1 removes fade effect)
                      // Note that this effect combined with other effects might be resource intensive
                      // and make animations lag
  start_at_index: 0, // Which image should be displayed at first? 0 is the first image
  description_wrapper: false,//$('#descriptions'), // Either false or a jQuery object, if you want the image descriptions
                                           // to be placed somewhere else than on top of the image
  animate_first_image: false, // Should first image just be displayed, or animated in?
  animation_speed: 400, // Which ever effect is used to switch images, how long should it take?
  display_next_and_prev: true, // Can you navigate by clicking on the left/right on the image?
  display_back_and_forward: true, // Are you allowed to scroll the thumb list?
  scroll_jump: 0, // If 0, it jumps the width of the container
  slideshow: {
    enable: true,
    autostart: true,
    speed: 5000,//
    start_label: '',
    stop_label: '',
    stop_on_scroll: true, // Should the slideshow stop if the user scrolls the thumb list?
    countdown_prefix: '', // Wrap around the countdown
    countdown_sufix: '',
    onStart: function() {
      // Do something wild when the slideshow starts
    },
    onStop: function() {
      // Do something wild when the slideshow stops
    }
  },
  effect: 'fade', // or 'slide-vert', 'resize', 'slide-hori', 'none' or false
  enable_keyboard_move: true, // Move to next/previous image with keyboard arrows?
  cycle: true, // If set to false, you can't go from the last image to the first, and vice versa
  // All callbacks has the AdGallery objects as 'this' reference
  callbacks: {
    // Executes right after the internal init, can be used to choose which images
    // you want to preload
    init: function() {
      // preloadAll uses recursion to preload each image right after one another
      this.preloadAll();
      // Or, just preload the first three
      this.preloadImage(0);
      this.preloadImage(1);
      this.preloadImage(2);
    },
    // This gets fired right after the new_image is fully visible
    afterImageVisible: function() {
      // For example, preload the next image
      var context = this;
      this.loading(true);
      this.preloadImage(this.current_index + 1,
        function() {
          // This function gets executed after the image has been loaded
          context.loading(false);
        }
      );
/*
      // Want slide effect for every other image?
      if(this.current_index % 2 == 0) {
        this.settings.effect = 'slide';
      } else {
        this.settings.effect = 'fade';
      }*/
    },
    // This gets fired right before old_image is about to go away, and new_image
    // is about to come in
    beforeImageVisible: function(new_image, old_image) {
      // Do something wild!
    }
  }

});

//*END GALLERY*//

  $(".cboxiframe").colorbox({width:"80%", height:"80%", iframe:true});
//COMPORTAMENTO LABEL SOPRA INPUT
	$("label.over").click(function() { // bind click event to link
		$(this).addClass("sposta");
		$(this).next().focus();
	});
	$("label.over").next().focus(function() { // bind click event to link
		$(this).prev().addClass("sposta");
	});
	$("label.over").next().blur(function() { // bind click event to link
		if(this.value == "") $(this).prev().removeClass("sposta");
	});	
	$(".row label").each(function() {
		if($(this).next().val()!="") $(this).addClass("sposta");							 
									 });
	
//END  

//TOGGLE E SELECT-BOX
	$(".toggle_hide").hide();
	$(".trigger").click(function(){
		$(this).next(".toggle_c").slideToggle("slow,");
	});	
	$(".trigger_prev").click(function(){
		$(this).prev(".toggle_c").slideToggle("slow,");
	});	
	$(".select-box a").click(function(){
		var selbox =  $(this).attr('rel').split("-");
		var frm = $(this).prevALL('.form-select:first');
		if(selbox!="") {
			$("#sel-"+selbox[0]+" .active").remove();
			$("#sel-"+selbox[0]+" span.first").html($(this).html());
			$("#"+selbox[0]).val(selbox[1]);
			$("#sel-"+selbox[0]+" .toggle_c").slideToggle("fast,");
		}
		if(frm) {
			frm.submit();
		}

	});
//END TOGGLE
	$('.datepicker').datepicker({ dateFormat: 'dd/mm/yy' });

});
$('.cbox').livequery(function(){ 
        $(this).colorbox({maxWidth:"100%",maxHeight:"100%"});
}); 
 function callAjax(obj){
	  linkdest = $(obj).attr("href");
	  result = $(obj).attr("rel");
	  $.ajax({
	  url: linkdest,
	  success: function(data) {
		$('#'+result).html(data);
	  }
	  });
	  return false;
  }
/*PARTE RELATIVA ALLE FORM DEL BOOKING*/
function setDate()
{
	var gg = document.getElementById("id_gg");	
	var mm = document.getElementById("id_mm");	
	var aa = document.getElementById("id_aa");	
	var oggi = new Date();
	
	if(gg && mm && aa)
	{
		gg.options[(oggi.getDate()-1)].selected = true;
		mm.options[(oggi.getMonth())].selected = true;
		for(i=0; i<10; i++)
		{
			if(aa.options[i])
			{
				if(aa.options[i].value == oggi.getFullYear()) aa.options[i].selected = true;
			}
		}
	}	
}

function frmcheck()
{
	frm = document.getElementById("myform");
	if (!(frm)) return false;
	
	var oggi = new Date();

	if (parseInt(frm.aa.value) < oggi.getFullYear())
	{
		alert ("Warning: Specified date is in the past. Please select a date and retry.");
		frm.aa.focus();
		return false;
	}
	if (parseInt(frm.aa.value) == oggi.getFullYear())
	{
		if (parseInt(frm.mm.value) < (parseInt(oggi.getMonth())+1))
		{
			alert ("Warning: Specified date is in the past. Please select a date and retry.");
			frm.mm.focus();
			return false;
		}
		if (parseInt(frm.mm.value) == (parseInt(oggi.getMonth())+1))
		{
			if (parseInt(frm.gg.value) < parseInt(oggi.getDate()))
			{
				alert ("Warning: Specified date is in the past. Please select a date and retry.");
				frm.gg.focus();
				return false;
			}
		}
	}	tot_adulti_pren = 0;
	tot_camere_pren = 0;

	if (parseInt(frm.tot_adulti.value) < 1)
	{
		alert("E' necessario almeno un adulto per continuare la prenotazione");
		frm.tot_adulti.focus();
		return false;
	}
	if ((!(parseInt(frm.notti_1.value) > 0))||(!(parseInt(frm.tot_adulti.value)>0))||(!(parseInt(frm.tot_camere.value)>0)))
	{
		alert("E' necessario specificare numero di notti, di adulti e di camere per iniziare la ricerca");
		frm.notti_1.focus();
		return false;
	}
	tot_adulti_pren = parseInt(frm.tot_adulti.value);
	tot_camere_pren = parseInt(frm.tot_camere.value);
	tot_bambini_pren = parseInt(frm.tot_bambini.value);
	if(!(tot_bambini_pren > 0)) tot_bambini_pren = 0;
	tot_occupanti_pren = tot_adulti_pren + tot_bambini_pren;
	str = "occ = " + tot_occupanti_pren + " cam = " + tot_camere_pren;
	// alert(str);
	if (tot_occupanti_pren < tot_camere_pren)
	{
		alert("E' necessario avere almeno una persona per camera");
		frm.tot_adulti.focus();
		return false;
	}

	frm.submit();
}
/*END BOOKING*/
