// JavaScript Document

$(document).ready(function(){

    /// Paneles moviles ////////////////////////////////////////////////////////////////////////////////////////////////////
    /* Izquierdo */
    $("#panel_izda").mouseover(function(){
        $("#panel_izda").animate({"width":"380px"},100,function(){
            $("#panel_izda h2").css("color","#cca218");
        });
        $("#panel_cntr").animate({"width":"305px"},100,function(){});
        $("#panel_dcha").animate({"width":"305px"},100,function(){});
    });
    $("#panel_izda").mouseout(function(){
        $("#panel_izda").animate({"width":"330px"},100,function(){
            $("#panel_izda h2").css("color","#FFF");
        });
        $("#panel_cntr").animate({"width":"330px"},100,function(){});
        $("#panel_dcha").animate({"width":"330px"},100,function(){});
    });
    
    /* Central */
    $("#panel_cntr").mouseover(function(){
        $("#panel_izda").animate({"width":"305px"},100,function(){});
        $("#panel_cntr").animate({"width":"380px"},100,function(){
            $("#panel_cntr h2").css("color","#cca218");
        });
        $("#panel_dcha").animate({"width":"305px"},100,function(){});
    });
    $("#panel_cntr").mouseout(function(){
        $("#panel_izda").animate({"width":"330px"},100,function(){});
        $("#panel_cntr").animate({"width":"330px"},100,function(){
            $("#panel_cntr h2").css("color","#FFF");
        });
        $("#panel_dcha").animate({"width":"330px"},100,function(){});
    });
    
    /* Derecho */
    $("#panel_dcha").mouseover(function(){
        $("#panel_izda").animate({"width":"305px"},100,function(){});
        $("#panel_cntr").animate({"width":"305px"},100,function(){});
        $("#panel_dcha").animate({"width":"380px"},100,function(){
            $("#panel_dcha h2").css("color","#cca218");
        });
    });
    $("#panel_dcha").mouseout(function(){
        $("#panel_izda").animate({"width":"330px"},100,function(){});
        $("#panel_cntr").animate({"width":"330px"},100,function(){});
        $("#panel_dcha").animate({"width":"330px"},100,function(){
            $("#panel_dcha h2").css("color","#FFF");
        });
    });
    
    /// Calendario ////////////////////////////////////////////////////////////////////////////////////////////////////
    /* Inicializacion en castellano */
            $.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,
    		showMonthAfterYear: false,
    		yearSuffix: ''};
    	$.datepicker.setDefaults($.datepicker.regional['es']);
    /* Mes y aņo seleccionable o no */
            $('#entrada').datepicker();
            $('#salida').datepicker();

	/// FancyBox ////////////////////////////////////////////////////////////////////////////////////////////////////
    /* Fechas de entrada y salida */
    function entrada() {
        var entrada = $("#entrada").val();
        if(entrada != '') {
            return entrada;
        } else {
            return '';
        }
    }
    
    function salida() {
        var salida = $("#salida").val();
        if(salida != '') {
            return salida;
        } else {
            return '';
        }
    }
    
    function nHab() {
        var nHab = $("#nHab").val();
        if(nHab != '') {
            return nHab;
        } else {
            return '';
        }
    }
    
    $("#entrada").change(function(){
        $("#btnConsultar").attr('href','pago/frmPago.php?entrada=' + entrada() + '&salida=' + salida() + '&habRes=' + nHab());
    });
    $("#salida").change(function(){
        $("#btnConsultar").attr('href','pago/frmPago.php?entrada=' + entrada() + '&salida=' + salida() + '&habRes=' + nHab());
    });
    
    $("#btnConsultar").click(function (){
        $("#btnConsultar").attr('href','pago/frmPago.php?entrada=' + entrada() + '&salida=' + salida() + '&habRes=' + nHab());
    });
    
    $("#btnConsultar").fancybox({
            'type': 'iframe',
            'hideOnOverlayClick': false,
            'margin': 0,
            'padding': 5,
            'width': 620,
            'height': 580,
            'overlayOpacity': 0.7,
            'overlayColor': '#777'
        });
    
    /* Habitaciones */
    $("#contDchaHabImg a").fancybox({
        'overlayOpacity': 0.7,
        'overlayColor': '#777'
    });
    
    $(".habReservaDet").fancybox({
        'overlayOpacity': 0.7,
        'overlayColor': '#777',
        'margin': 2,
        'padding': 2,
        'titleShow': false,
        'hideOnContentClick': true,
        'showCloseButton': false
        
    });
    
    /* Promociones */
    $(".promo").fancybox({
        'overlayOpacity': 0.7,
        'overlayColor': '#777'
    });

    /// Informacion Navegador ////////////////////////////////////////////////////////////////////////////////////////////////////
    function navInfo(){
        this.nombre = navigator.appName;
        this.codigo_nobre = navigator.appCodeName;
        this.version = navigator.appVersion.substring(0,4);
        this.plataforma = navigator.platform;
        this.javaEnabled = navigator.javaEnabled();
        this.pantalla_ancho = screen.width;
        this.pantalla_alto = screen.height;
        }
    
    /// Paginacion ////////////////////////////////////////////////////////////////////////////////////////////////////
    initPagination();
        
});


/**
 * Callback function that displays the content.
 *
 * Gets called every time the user clicks on a pagination link.
 *
 * @param {int} page_index New Page index
 * @param {jQuery} jq the container with the pagination links as a jQuery object
 */
function pageselectCallback(page_index, jq){
    var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
    $('#Searchresult').empty().append(new_content);
    return false;
}

/** 
 * Initialisation function for pagination
 */
function initPagination() {
    // count entries inside the hidden content
    var num_entries = jQuery('#hiddenresult div.result').length;
    // Create content inside pagination element
    $("#Pagination").pagination(num_entries, {
        callback: pageselectCallback,
        items_per_page: 1, //Show only one item per page
        next_text: '>>',
        prev_text: '<<'
    });
 }
