    var delay = 1500;
    var lastClick = new Date();
    lastClick = lastClick.getTime();

$(document).ready(function(){
	
	//============================================================================//
	//----------------------------------- VER MAS --------------------------------//
	//============================================================================// 
	
	$('.header').height($('.head').height()+$('.breadcrumb').height()+$('.slider').height()+31)
	
	var contentHeight
	
	if($('.sidebar').height() < $('.main-content').height()) {
		contentHeight = $('.header').height() + $('.footer').height() + $('.main-content').height()	+ 10
		$('.main-container').height(contentHeight)
	} else if($('.sidebar').height() > $('.main-content').height()) {
		contentHeight = $('.header').height() + $('.footer').height() + $('.sidebar').height() + 10
		$('.main-container').height(contentHeight) + 550
	}
	
	if ($('.main-container #content').is('.full')) {
		contentHeight = $('.header').height() + $('.footer').height() + $('.main-container #content').height() + 10
		$('.main-container').height(contentHeight)
	}
	
	$('.main-content, .sidebar').css({top:$('.header').height()})
	
	$('p.description a#mas-info').click(function(e){
	if($(this).hasClass("MainResults")){
		e.preventDefault()
			enlace = $(this)
			if($(this).attr('id') == 'mas-info') {
			var DESCLARGA = enlace.parent().parent().find(".DescriptionOculta").text();				
			  enlace.attr('id', 'mas-info-open')
			  enlace.closest('.description').find('span:not(.ellipsis)').html(' '+DESCLARGA).slideToggle()
			  enlace.closest('.description').find('.ellipsis').fadeOut()
			  contentHeight = $('.header').height() + $('.footer').height() + $('.main-content').height()	+ 10
		$('.main-container').height(contentHeight)

			} else if($(this).attr('id') == 'mas-info-open') {
				enlace.attr('id', 'mas-info')
				enlace.closest('.description').find('span:not(.ellipsis)').slideToggle().html('')
				enlace.closest('.description').find('.ellipsis').fadeIn()
				contentHeight = $('.header').height() + $('.footer').height() + $('.main-content').height()	+ 10
			    $('.main-container').height(contentHeight)
			}	

	}else{
		e.preventDefault()
		enlace = $(this)
		if($(this).attr('id') == 'mas-info') {
		$.ajax({
		  url: 'http://www.click2travel.com/?r=Basic&GetDescription='+enlace.attr('class'),
		  success: function(data){
			  enlace.attr('id', 'mas-info-open')
			  enlace.closest('.description').find('span:not(.ellipsis)').html(' '+data).slideToggle()
			  enlace.closest('.description').find('.ellipsis').fadeOut()
			  contentHeight = $('.header').height() + $('.footer').height() + $('.main-content').height()	+ 10
			  $('.main-container').height(contentHeight)
		  }
		})
		} 
		
		if($(this).attr('id') == 'mas-info-open') {
			enlace.attr('id', 'mas-info')
			enlace.closest('.description').find('span:not(.ellipsis)').slideToggle().html('')
			enlace.closest('.description').find('.ellipsis').fadeIn()
			contentHeight = $('.header').height() + $('.footer').height() + $('.main-content').height()	+ 10
		    $('.main-container').height(contentHeight)
		}	
	}

	})
	$('p.description a#mas-infoHd').click(function(e){
	
		e.preventDefault()
		enlace = $(this)
		
		if($(this).attr('id') == 'mas-infoHd') {
		$.ajax({
		   //url: 'http://www.click2travel.com/?r=Basic&GetDescription='+enlace.attr('class'),
		  success: function(data){//data=document.getElementById('hdmasInfo'+enlace.attr('class')).value;
			  enlace.attr('id', 'mas-info-open')
			  enlace.closest('.description').find('span:not(.ellipsis)').html(' '+document.getElementById('hdmasInfo'+enlace.attr('class')).value).slideToggle()
			  enlace.closest('.description').find('.ellipsis').fadeOut()
			  contentHeight = $('.header').height() + $('.footer').height() + $('.main-content').height()	+ 10
			  $('.main-container').height(contentHeight)
		  }
		  
		})
		//alert(document.getElementById('hdmasInfo'+enlace.attr('class')).value);
		
		} 
		
		if($(this).attr('id') == 'mas-info-open') {
			enlace.attr('id', 'mas-infoHd')
			enlace.closest('.description').find('span:not(.ellipsis)').slideToggle().html('')
			enlace.closest('.description').find('.ellipsis').fadeIn()
			contentHeight = $('.header').height() + $('.footer').height() + $('.main-content').height()	+ 10
		    $('.main-container').height(contentHeight)
		}	
	

	})
	
	for(var i=0; i < $('.modules li').size(); i++) {
		objeto = $('.modules li').eq(i).find('.description')
		
		if(objeto.height() < 50) {
			objeto.find('a').css({display:'none'})
			objeto.find('.ellipsis').css({display:'none'})
		}
	}
	
	
	
	/*
	Código JS Buscador
	*/
	
	/*
	Query String Example
	r=Searcher
	&location=447
	&checkin=2011-09-16
	&checkout=2011-09-19
	&rooms=1
	&nights=3
X
	&children1=0
	&adults1=2
	&age1-1=
	&age1-2=
	
	&children2=0
	&adults2=
	&age2-1=
	&age2-1=
	
	&children3=0
	&adults3=
	&age3-1=
	&age3-2=
	---------------------

	
	*/

	//============================================================================//
	//----------------------------------- BUSCADOR -------------------------------//
	//============================================================================//    
        $('.datepicker').attr("readonly", true); 
        
        
		//URL Single:
	//http://www.click2travel.com/index.php?r=Searcher&hotel=65484&checkin=2011-10-24&checkout=2011-10-27&rooms=1&nights=3&children1=0&adults1=2&age1-1=&age1-2=&children2=0&adults2=&age2-1=&age2-1=&children3=0&adults3=&age3-1=&age3-2=&buscar=
	$("div.reservation form").prepend("<input type='hidden' value='Searcher' name='r'/>");
	if($('div.reservation form#FormBusqueda').hasClass('singleSearch')){
		
	}else{
            if (!$('#location').length) {
                $("div.reservation form").prepend("<input type='hidden' value='' name='location'/>");
            }		
	}
	
	$("div.reservation form").prepend("<input type='hidden' value='"+$("#noches").val()+"' name='nights'/>");
	$("div.reservation form").prepend("<input type='hidden' value='1' name='rooms'/>");

	$("div.reservation form").append("<input type='hidden' value='2' name='adults1'/>");
	$("div.reservation form").append("<input type='hidden' value='' name='adults2'/>");
	$("div.reservation form").append("<input type='hidden' value='' name='adults3'/>");
	$("div.reservation form").append("<input type='hidden' value='' name='adults4'/>");
	
	$("div.reservation form").append("<input type='hidden' value='0' name='children1'/>");
	$("div.reservation form").append("<input type='hidden' value='0' name='children2'/>");
	$("div.reservation form").append("<input type='hidden' value='0' name='children3'/>");
	$("div.reservation form").append("<input type='hidden' value='0' name='children4'/>");

	$("div.reservation form").append("<input type='hidden' value='' name='age1-1'/>");
	$("div.reservation form").append("<input type='hidden' value='' name='age1-2'/>");

	$("div.reservation form").append("<input type='hidden' value='' name='age2-1'/>");
	$("div.reservation form").append("<input type='hidden' value='' name='age2-2'/>");

	$("div.reservation form").append("<input type='hidden' value='' name='age3-1'/>");
	$("div.reservation form").append("<input type='hidden' value='' name='age3-2'/>");

	$("div.reservation form").append("<input type='hidden' value='' name='age4-1'/>");
	$("div.reservation form").append("<input type='hidden' value='' name='age4-2'/>");
	
	$('input[name="buscar"]').click(buscarClick);
	$('input[name="buscarCoast"]').click(buscarCoastClick);
	
	$('.reservation-input').focus(function(){
		if($(this).val() == "Introduce tu destino")
			$(this).val("");
	});
	
	$("#noches").change(function(){
		$("input[name='nights']").val($(this).val());
	});
	
	$("#habitaciones").change(function(){
		$("input[name='rooms']").val($(this).val());
		
		if($("#habitaciones").val() == "1"){
			$("input[name='adults1']").val(2);
			$("input[name='adults2'],input[name='children2'],input[name='age2-1'],input[name='age2-2']").val("");
			$("input[name='adults3'],input[name='children3'],input[name='age3-1'],input[name='age3-2']").val("");
			$("input[name='adults4'],input[name='children4'],input[name='age4-1'],input[name='age4-2']").val("");
		}
		if($("#habitaciones").val() == "2"){
			$("input[name='adults1']").val(2);
			$("input[name='adults2']").val(2);
			$("input[name='adults3'],input[name='children3'],input[name='age3-1'],input[name='age3-2']").val("");
			$("input[name='adults4'],input[name='children4'],input[name='age4-1'],input[name='age4-2']").val("");
		}
		if($("#habitaciones").val() == "3"){
			$("input[name='adults2']").val(2);
			$("input[name='adults3']").val(2);
			$("input[name='adults4'],input[name='children4'],input[name='age4-1'],input[name='age4-2']").val("");
		}
		if($("#habitaciones").val() == "4"){
			$("input[name='adults2']").val(2);
			$("input[name='adults3']").val(2);
			$("input[name='adults4']").val(2);
		}
		
	});
	
	$('#salida').change(function(){
		$("input[name='checkout']").val($(this).val());
	});
	
	$(".selectChildren").change(function(){
		var id = $(this).attr("id");
		var value = $(this).next().text();

		if(id == "children1")
			$('input[name="age1-1"]').val(value);
		if(id == "children2")
			$('input[name="age1-2"]').val(value);
		if(id == "children3")
			$('input[name="age2-1"]').val(value);
		if(id == "children4")
			$('input[name="age2-2"]').val(value);
		if(id == "children5")
			$('input[name="age3-1"]').val(value);
		if(id == "children6")
			$('input[name="age3-2"]').val(value);
			
	});
	
	$("#adultos1").change(function(){
				if($(this).val() == '1'){
					$('input[name="adults1"]').val("1");
				}else if($(this).val() == '2'){
					$('input[name="adults1"]').val("2");
				}else if($(this).val() == '3'){
					$('input[name="adults1"]').val("3");
				}else if($(this).val() == '1-1'){
					$('input[name="adults1"]').val("1");
					$('input[name="children1"]').val("1");
				}else if($(this).val() == '2-1'){
					$('input[name="adults1"]').val("2");
					$('input[name="children1"]').val("1");
				}else if($(this).val() == '2-2'){
					$('input[name="adults1"]').val("2");
					$('input[name="children1"]').val("2");
				}else if($(this).val() == '4'){
					$('input[name="adults1"]').val("4");
				}else if($(this).val() == '5'){
					$('input[name="adults1"]').val("5");
				}
			});
			
			
		$("#adultos2").change(function(){
			if($(this).val() == '1'){
				$('input[name="adults2"]').val("1");
			}else if($(this).val() == '2'){
				$('input[name="adults2"]').val("2");
			}else if($(this).val() == '3'){
				$('input[name="adults2"]').val("3");
			}else if($(this).val() == '1-1'){
				$('input[name="adults2"]').val("1");
				$('input[name="children2"]').val("1");
			}else if($(this).val() == '2-1'){
				$('input[name="adults2"]').val("2");
				$('input[name="children2"]').val("1");
			}else if($(this).val() == '2-2'){
				$('input[name="adults2"]').val("2");
				$('input[name="children2"]').val("2");
			}else if($(this).val() == '4'){
				$('input[name="adults2"]').val("4");
			}else if($(this).val() == '5'){
				$('input[name="adults2"]').val("4");
			}
		});
			
		$("#adultos3").change(function(){
			if($(this).val() == '1'){
				$('input[name="adults3"]').val("1");
			}else if($(this).val() == '2'){
				$('input[name="adults3"]').val("2");
			}else if($(this).val() == '3'){
				$('input[name="adults3"]').val("3");
			}else if($(this).val() == '1-1'){
				$('input[name="adults3"]').val("1");
				$('input[name="children3"]').val("1");
			}else if($(this).val() == '2-1'){
				$('input[name="adults3"]').val("2");
				$('input[name="children3"]').val("1");
			}else if($(this).val() == '2-2'){
				$('input[name="adults3"]').val("2");
				$('input[name="children3"]').val("2");
			}else if($(this).val() == '4'){
				$('input[name="adults3"]').val("4");
			}else if($(this).val() == '5'){
				$('input[name="adults3"]').val("4");
			}
		});
	
		$("#adultos4").change(function(){
			if($(this).val() == '1'){
				$('input[name="adults4"]').val("1");
			}else if($(this).val() == '2'){
				$('input[name="adults4"]').val("2");
			}else if($(this).val() == '3'){
				$('input[name="adults4"]').val("3");
			}else if($(this).val() == '1-1'){
				$('input[name="adults4"]').val("1");
				$('input[name="children4"]').val("1");
			}else if($(this).val() == '2-1'){
				$('input[name="adults4"]').val("2");
				$('input[name="children4"]').val("1");
			}else if($(this).val() == '2-2'){
				$('input[name="adults4"]').val("2");
				$('input[name="children4"]').val("2");
			}else if($(this).val() == '4'){
				$('input[name="adults4"]').val("4");
			}else if($(this).val() == '5'){
				$('input[name="adults4"]').val("4");
			}
		});
	
				function buscarCoastClick () {
				//alert(document.getElementById('ddlcoast-input').value);
				if(document.getElementById('ddlcoast-input').value == "-1" || document.getElementById('ddlcoast-input').value == ""){
						alert("Debe seleccionar una población.");
						document.getElementById('ddlcoast-input').value.focus();
				}else{
										
						var id =document.getElementById('ddlcoast-input').value.replace("coast","").replace("city","").replace("#","");
						if(document.getElementById('ddlcoast-input').value.indexOf("coast")!=-1)
						{
						
							var section = "&coast=";
							section += id;
						}
						else
						{
							
							var section = "&location=";
							
								section += id;
							
								//var section = "&location="+$("input[name='location']").val()
								//var section = "&location="+$("#location").val();
						}
						var url = "http://www.click2travel.com/?r=Searcher"+section+"&checkin="+$("input[name='checkin']").val()+"&checkout="+$("input[name='checkout']").val()+"&rooms="+$("input[name='rooms']").val()+"&nights="+$("input[name='nights']").val()+"&children1="+$("input[name='children1']").val()+"&adults1="+$("input[name='adults1']").val()+"&age1-1="+$("input[name='age1-1']").val()+"&age1-2="+$("input[name='age1-2']").val()+"&children2="+$("input[name='children2']").val()+"&adults2="+$("input[name='adults2']").val()+"&age2-1="+$("input[name='age2-1']").val()+"&age2-1="+$("input[name='age2-1']").val()+"&children3="+$("input[name='children3']").val()+"&adults3="+$("input[name='adults3']").val()+"&age3-1="+$("input[name='age3-1']").val()+"&age3-2="+$("input[name='age3-2']").val()+"";
						//alert(url);
						
						//$('#waiter').style.visibility="visible";
						//$('#waiter').style.display="inline";				
						$('#waiter').fadeIn('slow', function () {
						   window.location=url; 
						});                        
					}
				}
		  
                function buscarClick () {
				
                    if($('.reservation-input').val() == "Introduce tu destino" || $('.reservation-input').val() == ""){
                            alert("Debes seleccionar tu destino.");
                            $('.reservation-input').focus();
                    }else{
					
                            if($('div.reservation form#FormBusqueda').hasClass('singleSearch')){
                                    var section = "&hotel="+$("input[name='hotel']").val()
                            }else{
                                var section = "&location=";
                                if ($("input[name='location']").val()!='') {
                                    section += $("input[name='location']").val();
                                } else {//reservation-input
                                    //section += $('.').val();
									section+=$('.reservation-input').val() ;
                                }
                                    //var section = "&location="+$("input[name='location']").val()
                                    //var section = "&location="+$("#location").val();
                            }
							//alert(section);
                            var url = "http://www.click2travel.com/?r=Searcher"+section+"&checkin="+$("input[name='checkin']").val()+"&checkout="+$("input[name='checkout']").val()+"&rooms="+$("input[name='rooms']").val()+"&nights="+$("input[name='nights']").val()+"&children1="+$("input[name='children1']").val()+"&adults1="+$("input[name='adults1']").val()+"&age1-1="+$("input[name='age1-1']").val()+"&age1-2="+$("input[name='age1-2']").val()+"&children2="+$("input[name='children2']").val()+"&adults2="+$("input[name='adults2']").val()+"&age2-1="+$("input[name='age2-1']").val()+"&age2-1="+$("input[name='age2-1']").val()+"&children3="+$("input[name='children3']").val()+"&adults3="+$("input[name='adults3']").val()+"&age3-1="+$("input[name='age3-1']").val()+"&age3-2="+$("input[name='age3-2']").val()+"";
                            //alert(url);
							$('#waiter').fadeIn('slow', function () {
                               window.location=url; 
                            });                        
                    }
                }
                
                function nuevaBusquedaClick () {
                    //$(this).fadeOut();
                    $('.reservation').fadeIn()
                    $('.reservation-info').css({'border-bottom':'1px dotted #999'})
                    $('.main-container').height($('.main-container').height()+100)
                    $('.selectors').css({margin:'170px 0 0 0'})
                }
        
        
        
	/*
	EO Código JS Buscador
	*/
       
    if ($('#min-price').length) {
    var minPrice = parseInt($('#min-price').val());
    var maxPrice = parseInt($('#max-price').val());

    $( "#slider-range" ).slider({
        range: true,
        min: minPrice,
        max: maxPrice,
        values: [ minPrice, maxPrice ],
        slide: function( event, ui ) {
            $( "#amount" ).val( ui.values[ 0 ] + " €" + " - " + ui.values[ 1 ] + " €");
            $( "#min-price" ).val( ui.values[0] );
            $( "#max-price" ).val( ui.values[1] );
            refreshResults();
        }
    });
    $( "#amount" ).val( $( "#slider-range" ).slider( "values", 0 ) + " €" +
        " - " + $( "#slider-range" ).slider( "values", 1 ) + " €");

    $('.check-filter').change(refreshResults);
    }
       
});




//============================================================================//
//--------------------- DISPONIBILIDAD (functions.js) ------------------------//
//============================================================================//

    function refreshResults() {
        lastClick = (new Date()).getTime();
        setTimeout(function () {
            var now = new Date();
            if ((lastClick + delay) < now.getTime()) {
//                alert('ejecutar');
                var url = "http://www.click2travel.com/?r=Results&ajax=true&sid";
                if(typeof(sid) != "undefined"){url = url + '&sid=' + sid;}
                $.ajax({
                    type: 'GET',
                    url: url,
                    data: $('#filters').serialize(),
                    success: function (data) {
                        //$('.main-content result').fadeOut('slow');
                        $('#intro').fadeOut('slow');
                        var ddata = $(data);
                        //data = data.replace(/"abcdeabcdeabcde".replace(/bcd/g, "234");/g, "");
                        $('#intro').html(ddata.html());
                        //Cufon.replace('.sidebar .reservation .title, .main-content .col-top .title, .main-content .newsletter .title, .footer .hoteles .title, .footer .footer-data ul li, .head .phone span.number, .main-content .intro .title, .main-content ul.modules li .vcard a, .main-content ul.modules li .rating span.rate-number, .main-content ul.modules li .price-reservation span:not(.euro), .main-content .next a, .sidebar .selectors .title, .sidebar .content .title, .sidebar .gmaps .title');
                        $('#intro').fadeIn('slow');

                    }
                });
            } else {
//                alert('no ejecutar');
            }
        }, delay + 10);        
    }
    
//============================================================================//
//------------------------ RESERVA (main-booking.php) ------------------------//
//============================================================================//    
    
        $('.main-content').css("width","auto");
        $(document).ready(function(){
           // $(".main-container").css("height","1300px");

          

            $("#form-booking").validate({
                rules: {
                    firstName: "required",
                    lastName: "required",
                    docValue: {
                        required: true,
                        minlength: 6,
                        maxlength: 9
                    },
                    email: {
                        required: true,
                        email: true
                    },
                    phone: {
                        required: true,
                        digits: true,
                        minlength: 6
                    },
                    zipCode: {
                        required: true,
                        minlength: 5,
                        maxlength: 5
                    },
                    cardHolder: {
                        required: true
                    },
                    cardNumber: {
                        required: true,
                        creditcard: true,
                        minlength: 16,
                        maxlength: 16
                    },
                    cardCVV: {
                        required: true,
                        digits: true,
                        minlength: 3,
                        maxlength: 3
                    },
                    accept: {
                        required: true
                    }
                },
                messages: {
                    accept: "Debe aceptar las condiciones de compra"
                },
submitHandler: function() {$('.pagar').attr("disabled", true);form.submit();}
         //$('#waiterReservation').fadeIn('slow');       
            });      
			
			$('#form-booking').bind('change keyup', function() {
				if($(this).validate().checkForm()) {
					$('.pagar').css({opacity:1}).attr('disabled', false);
				} else {
					$('.pagar').css({opacity:0.5}).attr('disabled', true);
				}
			});      
            
//============================================================================//
//----------------------- RESERVA (functions-seba.js) ------------------------//
//============================================================================//    

	$('#bill').change(function() {
		if($('#bill').is(':checked')) {
			$('#detalleFactura').fadeTo(800,1);
			contentHeight = $('.header').height() + $('.footer').height() + $('.main-content').height()	+ 10
		$('.main-container').height(contentHeight)
		} else if(!$('#bill').is(':checked')) {
			$('#detalleFactura').fadeTo(800,0, function() {
				$('#detalleFactura').hide();
				contentHeight = $('.header').height() + $('.footer').height() + $('.main-content').height()	+ 10
		$('.main-container').height(contentHeight)
			});
		}
	});
            
        }); //ready      



