$(document).ready(function(){
		$(".tool-tip-texto").hide();
		$('.col-iz .mas').click(function() {
			  $('.tool-tip-texto').fadeIn();
				return false;
			});
			$('.tool-tip-texto .btn-cerrar').click(function() {
			  $('.tool-tip-texto').fadeOut();
				return false;
			});
			
	/* Funcion que permite la seleccion de pais */
		$("#pais ul").addClass("min");
		$("#pais ul").wrap('<div class="ccbx"></div>');
		$("#pais ul").parent().css({'position':'relative','height':'20px','zIndex':'50'});
		$("#pais ul").css({'position':'absolute','overflow':'hidden','height':'20px','zIndex':'51'});
		$("#pais ul").after('<input type="hidden" name="country" id="country" value=""/>');
		$("#pais ul").find(":first").attr('id','flag');
		$("#pais ul").click(function(){
				if( $(this).hasClass('min')){
					$(this).removeClass("min");
					$(this).animate({height:'130px'},300);
				}else{
					$(this).addClass("min");
					$(this).animate({height:'20px'},100);
				}
			});	
			$("#pais ul").mouseleave(function(){
				$(this).animate({height:'20px'},100);
				$(this).addClass("min");
			});
			$("#pais ul").find("li a").click(function(){
				var deep = $(this).attr("href");
				var flag = $(this).attr("class");
				$(this).parent().parent().animate({height:'20px'},100);
				$(this).parent().parent().find("#flag").removeClass();
				$(this).parent().parent().find("#flag").addClass(flag);
				$("#country").val(deep);
				$(this).parent().parent().addClass("min");
				return false;
			});
			$('.ciudad').hover(function() {
			  $(this).find('.info-oferta').animate({
				left: '0'
			  }, 500, function() {
			  });
			},function() {
			  $(this).find('.info-oferta').animate({
				left: '-115'
			  }, 500, function() {
			  });
			});
			
			
			//Login
			$("#header .login").hide();
			$('#header .btn-ingresa').click(function() {
			  $(this).parent().parent().find('.login').fadeIn();
				return false;
			});
			$('#header .login .cerrar').click(function() {
			$(this).parent().parent().find('.login').hide();
				return false;
			});
			
			//Ver mas preferencial			
			$("#con-quebuscas .panes .pan-dos p.preferencias,#con-quebuscas .panes .pan-uno p.preferencias").hide();
			$("#con-quebuscas .panes .pan-dos .ocultar-preferencias,#con-quebuscas .panes .pan-uno .ocultar-preferencias").hide();
			$('#con-quebuscas .panes .pan-dos .ver-preferencias,#con-quebuscas .panes .pan-uno .ver-preferencias').click(function() {
			  $(this).parent().parent().find('.preferencias').fadeIn();
			  $(this).hide();
			  $(this).parent().parent().find('.ocultar-preferencias').show();
				return false;
			});
			$('#con-quebuscas .panes .pan-dos .ocultar-preferencias,#con-quebuscas .panes .pan-uno .ocultar-preferencias').click(function() {
			  $(this).parent().parent().find('.preferencias').fadeOut();
			  $(this).hide();
			 $(this).parent().parent().find('.ver-preferencias').show();
				return false;
			});

			$(".filtrar").show();
			$(".btn-ocultarfiltro.hide").hide();
			
			$('.btn-ocultarfiltro.show').click(function() {
				$(this).hide();
				$(".btn-ocultarfiltro.hide").show();
				$(".filtrar").slideDown();
				return false;
			});
			$('.btn-ocultarfiltro.hide').click(function() {
				$(this).hide();
				$(".btn-ocultarfiltro.show").show();
				$(".filtrar").slideUp();
				return false;
			});

			
			$('.oferta').hover(function() {
			  $(this).find('.info-oferta').animate({
				left: '0'
			  }, 500, function() {
			  });
			},function() {
			  $(this).find('.info-oferta').animate({
				left: '-115'
			  }, 500, function() {
			  });
			});
			
			$(".tool-tip-precio").hide();
			$('.precio .price').hover(function() {
			  $(this).parent().find('.tool-tip-precio').show();
			},function() {
			  $(this).parent().find('.tool-tip-precio').hide();
			});
			
			$(".tool-tip-incluye").hide();
			$(' .btn-que-incluye').click(function() {
			  $(this).parent().parent().find('.tool-tip-incluye').fadeIn();
				return false;
			});
			$(' .tool-tip-incluye .btn-cerrar').click(function() {
			  $(this).parent().parent().find('.tool-tip-incluye').hide();
				return false;
			});
			
			$(".tool-tip-upsell").hide();
			$('.cambiar-habitacion').click(function() {
			  $('.tool-tip-upsell').fadeIn();
				return false;
			});
			$('.tool-tip-upsell .btn-cerrar').click(function() {
			  $('.tool-tip-upsell').fadeOut();
				return false;
			});
			
			
			/*este script levanta el div de condiciones*/
			$(".tool-tip-condiciones").hide();
			$('.btn-que-condiciones').click(function() {
			  $(this).parent().parent().find('.tool-tip-condiciones').fadeIn();
				return false;
			});
			$(' .tool-tip-condiciones .btn-cerrar').click(function() {
			  $(this).parent().parent().find('.tool-tip-condiciones').hide();
				return false;
			});
			
			
			
			$(".tool-tip-itinerario").hide();
			$('.duracion .btn-itinerario').click(function() {
			  $(this).parent().parent().find('.tool-tip-itinerario').fadeIn();
				return false;
			});
			$('.tool-tip-itinerario .btn-cerrar').click(function() {
			  $(this).parent().parent().parent().find('.tool-tip-itinerario').hide();
				return false;
			});
			
			$(".tool-tip-vuelo").hide();
			$('.tabla input').focus(function() {
				$(".tool-tip-vuelo").hide();
			  $(this).parent().find('.tool-tip-vuelo').fadeIn();
			},function() {
			  $(this).parent().find('.tool-tip-vuelo').hide();
			});
			$(".categoria-habitacion input").click(function(){
			if( $(this).attr('checked') ){
			$('tr').removeClass('color');
			$(this).parent().parent().addClass('color');
			}
			});
			//*** Calendar Shopping ***
			//Mostrar Div para los calendarios (Ida y Vuelta y solo Ida) de vuelos flexibles			
			$(".tool-tip-vuelo-cal").hide();
			$('.tabla td').hover(function() 
			{
				var elemento = $(this);
				var t = setTimeout(function() 
				{
					$(".tool-tip-vuelo-cal").hide();
					$(elemento).find('.tool-tip-vuelo-cal').fadeIn();	
				 }, 300);
				 
             $(this).data('timeout', t);
			},function() 
			{
				 clearTimeout($(this).data('timeout'));
			  $(this).find('.tool-tip-vuelo-cal').hide();
			});
			//*** Fin Calendar Shopping ***
			
			
			
			$("#con-reserva").hide();
			$('.btn_quebuscas').click(function() {
			$(this).addClass("activo");
			 $(".btn-reserva").removeClass("activo");
			 $("#con-reserva").hide();
			 $("#con-quebuscas").show();
			 return false;
			});
			$('.btn-reserva').click(function() {
				$(this).addClass("activo");
			 $(".btn_quebuscas").removeClass("activo");
			 $("#con-quebuscas").hide();
			 $("#con-reserva").show();
			 return false;
			});

			$(".sidebar").scrollable({
				items: ".franja",
				item: ".item",
				loop: true,
				size: 1,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage",
				prevPage: ".prevPage",
				speed:800
			}).circular().navigator({
				navi:".pages-highlights",
				indexed:true
				}).autoscroll({ 
				autoplay: true, interval: 10000 
			});
			
			
			$(".foto-seleccion").scrollable({
				items: ".franja",
				item: "img",
				loop: true,
				size: 1,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage",
				prevPage: ".prevPage",
				speed:700
			});
			
			$(".ingles").scrollable({
				items: ".franja",
				item: ".pais",
				loop: true,
				size: 2,
				clickable:false,
				keyboard:false,
				nextPage: ".btn-siguiente",
				prevPage: ".btn-anterior",
				speed:700
			});
			
			$(".jovenes").scrollable({
				items: ".franja-j",
				item: "a",
				loop: true,
				size: 1,
				clickable:false,
				keyboard:false,
				nextPage: ".btn-siguiente-j",
				prevPage: ".btn-anterior-j",
				speed:700
			});

			$("#baratas").scrollable({
				items: ".franja",
				item: ".oferta",
				loop: true,
				size: 2,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage-oferta",
				prevPage: ".prevPage-oferta",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".mas-paquetes").scrollable({
				items: ".franja",
				item: ".destino",
				loop: true,
				size: 4,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage-oferta",
				prevPage: ".prevPage-oferta",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".paquetes-verano").scrollable({
				items: ".franja",
				item: ".destino",
				loop: true,
				size: 3,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage-oferta",
				prevPage: ".prevPage-oferta",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".mas-hoteles").scrollable({
				items: ".franja",
				item: ".pag",
				loop: true,
				size: 1,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage",
				prevPage: ".prevPage",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".vuelos-varios.vuelos").scrollable({
				items: ".franja.vuelos",
				item: ".item.vuelos",
				loop: true,
				size: 3,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage.vuelos",
				prevPage: ".prevPage.vuelos",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".vuelos-varios.hotel").scrollable({
				items: ".franja.hotel",
				item: ".item.hotel",
				loop: true,
				size: 3,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage.hotel",
				prevPage: ".prevPage.hotel",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".vuelos-varios.paquete").scrollable({
				items: ".franja.paquete",
				item: ".item.paquete",
				loop: true,
				size: 3,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage.paquete",
				prevPage: ".prevPage.paquete",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".vuelos-varios.actividad").scrollable({
				items: ".franja.actividad",
				item: ".item.actividad",
				loop: true,
				size: 3,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage.actividad",
				prevPage: ".prevPage.actividad",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".varios-cruceros").scrollable({
				items: ".franja",
				item: ".tientate",
				loop: true,
				size: 4,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage-cruceros",
				prevPage: ".prevPage-cruceros",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".varios-hoteles").scrollable({
				items: ".franja",
				item: ".tientate",
				loop: true,
				size: 4,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage-hoteles",
				prevPage: ".prevPage-hoteles",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".varios-paquetes").scrollable({
				items: ".franja",
				item: ".tientate",
				loop: true,
				size: 2,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage-hoteles",
				prevPage: ".prevPage-hoteles",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			
			$(".dest-cruceros").scrollable({
				items: ".franja",
				item: ".item",
				loop: true,
				size: 1,
				clickable:false,
				keyboard:false,
				nextPage: ".nextPage-destcruceros",
				prevPage: ".prevPage-destcruceros",
				speed:700
			}).circular().navigator({
				navi:".pages-cruceros",
				indexed:true
				}).autoscroll({ 
				autoplay: true, interval: 5000 
			});					
			
			$(".varios-cruceros-b ").scrollable({
				items: " .franja-b",
				item: " .tientate-b",
				loop: true,
				size: 4,
				clickable:false,
				keyboard:false,
				nextPage: " .nextPage-cruceros-b",
				prevPage: " .prevPage-cruceros-b",
				speed:700
			}).circular().navigator({
				indexed:true
			});
			// mega drop down
			$(".drop").hide();
			$('li.mega').hover(
				function(){
						$(this).addClass("presion");
						$(this).find('.drop').slideDown(10);
						$(this).find('a').addClass("sel_a");
					},
				function(){
					$(this).removeClass("presion");
					$(this).find('.drop').slideUp(1);
					$(this).find('a').removeClass("sel_a");
					}
			);
			
			
		$("#slider").slider({
			value:100,
			min: 0,
			max: 500,
			step: 50,
			slide: function(event, ui) {
				$("#amount").val('$' + ui.value);
			}
		});
		$("#amount").val('$' + $("#slider").slider("value"));
	
	$(function() { 
    $("ul.tabs").tabs("div.panes > div"); 
	});
	
	$(".ui-slider-handle").append('<input type="text" class="" id="amount" style="border:0; color:#f6931f; font-weight:bold;" />');
	
	$("#menu .mega").hover(function(){
		$(this).addClass("sel");
	},function(){
		$(this).removeClass("sel");
	});
	
	
	$("#menu .mega:first").addClass("primero");
	$("#menu .mega:last").addClass("ultimo");
       
        
	$(".checkout .detalles .box .mbox .meta a").click(function(){
		$(this).toggleClass('open');
		var open = $(this).attr('class');
		if( open == 'open'){
			$(this).html('Ocultar Detalles');
		}else{
			$(this).html('Mostrar Detalles');	
		};

		$(this).parent().parent().find('.info').toggle();
		return false;
	});
	
	$(".checkout .detalles .opciones .opcion").click(function(){
		$(".checkout .detalles .opciones .opcion").removeClass('sel');
		$(this).addClass('sel');
		var box = '#box_' + $(this).attr('id');
		$('.checkout .detalles .box').hide();
		$(this).parent().parent().find(box).show();
	});
	$('#con-quebuscas .panes .pan-dos .ida input').attr('readonly', true);
	$('#con-quebuscas .panes .pan-dos .vuelta input').attr('readonly', true);
	$(".info .ejemplo").hide();
        $(".bene-premium .bene-elite .info .ejemplo").css('z-index','99');
        $('.e-puntos').click(function() {
			$('.info .ejemplo').fadeIn();
            $('.bene-premium').hide();
			$('.bene-elite').hide();
			return false;
    });
});

function verificarFechas(date){

	var feriados=[];
	if($("#feriados").val()){
		feriados=$("#feriados").val().split(",");
	}
	var fechaActual = $.datepicker.formatDate('mm/dd/yy', new Date());
	var events = [fechaActual];
	var current = $.datepicker.formatDate('dd/mm/yy', date);
	/*el true que devuelve en el return corresponde a si es que esta activo o no el dia en el calendario,
	el siguiente argumento es el estilo y el siguiente es el titulo para el dia
	*/
	if(jQuery.inArray(current, feriados) != -1){
		return jQuery.inArray(current, feriados) == -1 ? [true, ''] : [true, 'ui-state-highlight', 'Feriado'];
	}else if(date.getDay()==0){
		return [true, 'ui-state-highlight', ''];
	}
    return [true, ''];
}

jQuery(function($) {

    if (jQuery().datepicker) {
		if($('#con-quebuscas .panes .pan-dos .ida input').length==0)
		{
		return;}
        $.datepicker.regional['es'] = {
            closeText: 'Cerrar',
            prevText: 'â€¹',
            nextText: 'â€º',
			showButtonPanel: true,
            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',
            numberOfMonths: 2,
            dateFormat: 'mm/dd/yy',
            minDate: $('#con-quebuscas .panes .pan-dos .ida input')[0].value,
            firstDay: 1,
            isRTL: false,
            showMonthAfterYear: false,
            dateFormat: "dd/mm/yy",
			beforeShowDay: verificarFechas,
            yearSuffix: ''
 
        };
        $.datepicker.setDefaults($.datepicker.regional['es']);

    };


    
    var setBounds;
    var dates = $("#con-quebuscas .panes .pan-dos .ida input, #con-quebuscas .panes .pan-dos .vuelta input" ).datepicker
    ({ onSelect: setBounds,
    onSelect: function( selectedDate ) {
                var vueltas=$("#con-quebuscas .panes .pan-dos .vuelta input");
                var i;

				var inputs=$("#con-quebuscas .panes .pan-dos .ida input");
                
                for(i=0;i<inputs.length;i++){
                    if(this.id==$(inputs[i]).attr("id")){
                                    var option = this.id == selectedDate==$("#con-quebuscas .panes .pan-dos .ida input").val() ?  "maxDate":"minDate" ,
                                        instance = $( this ).data( "datepicker" ),
                                        date = $.datepicker.parseDate(
                                            instance.settings.dateFormat ||
                                            $.datepicker._defaults.dateFormat,
                                            selectedDate, instance.settings );
                                            $(vueltas[i]).datepicker("option", option, date );
											return;
                                            
                   }
                }
				
            }
    });
	
        Shadowbox.init({ language: "es", players: ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv'] });
        
});











