$(document).ready(function()
{
	// MENÚ
	//get the default top value
	var top_val = $('#menu li a').css('top');

	//animate the selected menu item
	$('#menu li.selected').children('a').stop().animate({top:0}, {easing: 'easeOutQuad', duration:500});		

	$('#menu li').hover(
		function () {
				
			//animate the menu item with 0 top value
			$(this).children('a').stop().animate({top:0}, {easing: 'easeOutQuad', duration:500});		
		},
		function () {

			//set the position to default
			$(this).children('a').stop().animate({top:top_val}, {easing: 'easeOutQuad', duration:500});		

			//always keep the previously selected item in fixed position			
			$('#menu li.selected').children('a').stop().animate({top:0}, {easing: 'easeOutQuad', duration:500});		
		}		
	);
	
	// Formularios de disponibilidad
	$('#form_dispo_hotel,#form_dispo_vielha').submit(function() {
		var opcion=$(this).find('[name=opcion]').val();
		if (opcion=='dispo_hotel' || opcion=='dispo_hoteles') $("#ajax_dispo").html('cargando datos...');
		else if (opcion=='dispo_vielha') $("#contenido").html('cargando datos...');
		$.post("/disponibilidad.php", $(this).serialize(),
		   function(e){
				if (opcion=='dispo_hotel' || opcion=='dispo_hoteles') $("#ajax_dispo").html(e);
				else if (opcion=='dispo_vielha') $("#contenido").html(e);
	   });
		return false;
	});
	
	// Calendario jquery para seleccionar fechas
   $("#datepicker,#datepicker2,#datepickerb,#datepickerb2").datepicker();
	jQuery(function($){
		fecha=new Date();
		var dia=fecha.getDate();
		var mes=fecha.getMonth();
		var ano=fecha.getFullYear();
		$.datepicker.regional['es'] = {
			closeText: 'Cerrar',
			prevText: '&#x3c;Ant',
			nextText: 'Sig&#x3e;',
			currentText: 'Hoy',
			monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
			'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
			monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
			'Jul','Ago','Sep','Oct','Nov','Dic'],
			dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
			dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
			dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
			weekHeader: 'Sm',
			dateFormat: 'dd/mm/yy',
			firstDay: 1,
			isRTL: false,
			hideIfNoPrevNext: true,
			minDate: new Date(ano, mes, dia),
			showMonthAfterYear: false,
			yearSuffix: ''};
		$.datepicker.setDefaults($.datepicker.regional['es']);
	});
	
	$("#datepicker,#datepicker2").change(
		function () {
			var fecha_seleccionada=$("#datepicker").datepicker("getDate");
			var fecha_seleccionada2=$("#datepicker2").datepicker("getDate");
			var milisegundos=parseInt(1*24*60*60*1000);
			var tiempo=fecha_seleccionada.getTime();
			if (fecha_seleccionada>=fecha_seleccionada2)
			{
				fecha_seleccionada2=fecha_seleccionada; // Inicializamos la variable
				fecha_seleccionada2.setTime(parseInt(tiempo+milisegundos));
				$("#datepicker2").datepicker("setDate",fecha_seleccionada2);
			}
		});
	$("#datepickerb,#datepickerb2").change(
		function () {
			var fecha_seleccionada=$("#datepickerb").datepicker("getDate");
			var fecha_seleccionada2=$("#datepickerb2").datepicker("getDate");
			var milisegundos=parseInt(1*24*60*60*1000);
			var tiempo=fecha_seleccionada.getTime();
			if (fecha_seleccionada>=fecha_seleccionada2)
			{
				fecha_seleccionada2=fecha_seleccionada; // Inicializamos la variable
				fecha_seleccionada2.setTime(parseInt(tiempo+milisegundos));
				$("#datepickerb2").datepicker("setDate",fecha_seleccionada2);
			}
		});
});
