$('document').ready(function(){
	
// Paso imagenes				
	$('ul#contImg').cycle({
        fx: 'fade',
		speed: 1000,
		timeout: 5000,
		height: '530'
	});

// Campos formulario
	$("input").click(function(){if($(this).attr("title")==$(this).val())$(this).val("");});
	$("input").blur(function(){if(!$(this).val())$(this).val($(this).attr("title"));});
	$(".comment").click(function(){if($(this).attr("title")==$(this).val())$(this).val("");});
	$(".comment").blur(function(){if(!$(this).val())$(this).val($(this).attr("title"));});

// Datepicker
	$('#checkin').datepicker({
	    numberOfMonths: 2,
	    defaultDate: +1,
        firstDay: 1,
        dateFormat: 'dd/mm/y',
        //minDate: +0,
        minDate: '01/04/12',
        maxDate: '+11M',
        defaultDate: +1,
        firstDay: 1,
        onSelect: function(dateText, inst){
            min_date = $.datepicker.parseDate('dd/mm/y', dateText,  {shortYearCutoff:50});
            min_date.setDate(min_date.getDate()+1);
            $("#checkout").datepicker('option', 'minDate', min_date);
            $("#checkout").datepicker('setDate', min_date);
        }
	});
	$('#checkout').datepicker({
	    numberOfMonths: 2,
        defaultDate: +2,
        firstDay: 1,
        dateFormat: 'dd/mm/y',
        maxDate: '+12M',
        //minDate:+0,
        minDate: '02/04/12',
        defaultDate: +3,
        firstDay: 1
	});

// Efecto target _blank en enlaces
	$('.externalLink').live('click',function(e){
		e.preventDefault();
		window.open($(this).attr("href"));
		return false;
	});

// Efecto mostrar contenido
    jQuery('.thumb').hide();
	$('#mostrarInfo[title!=index]').animate({left:'0px'},1500, 'swing', function() {
        var viewport_height = jQuery('.viewport').css('height');
        jQuery('#contenido').css('height', viewport_height);
        jQuery('.thumb').show();
        jQuery('#contenido').tinyscrollbar();
        jQuery('#f_desde').datepicker("refresh");
        jQuery('#f_hasta').datepicker("refresh");
    });
    /* Excepcion para index */
    $('#mostrarInfo[title=index]').animate({left:'-320px'},0, 'swing', function() {
        jQuery(".moreInfo").removeClass('abierto').addClass('cerrado');
        var viewport_height = jQuery('.viewport').css('height');
        jQuery('#contenido').css('height', viewport_height);
        jQuery('.thumb').show();
        jQuery('#contenido').tinyscrollbar();
    });
    
    $(".moreInfo").click(function () {
        if ( $(this).hasClass('abierto') ){
            // Esta abierto y lo cierro
            $(this).removeClass('abierto').addClass('cerrado');
            $("#mostrarInfo").not('.showGallery').animate({left:'-320px'},1000);         
		    $("#mostrarInfo.showGallery").animate({left:'-680px'},1000);
        }
        else {
            // Esta cerrado y lo abro
            $(this).removeClass('cerrado').addClass('abierto');
            $('#mostrarInfo').animate({left:'0px'},1000);
        }
	});

// Colorbox
    $('.viewGallery').colorbox();

// Formatea la peticion de disponiblidad
    $('#dispo_form').submit(function(e){
        var adultos = $('#adultos', this)
        adultos.val(adultos.val() + '@');
        return true;
    });
	
	$('#adultos').val('2');
    
});

