﻿/*
=======================================================================================
 HOTELES RH                                                     Site produced by KOALAB  
                                                                Edited by Humanlevel      
 Copyright 2007                                                   http://www.koalab.com
=======================================================================================
*/
CommentsWidget = {
    itemsContainerObject : null,
    itemsArray : null,
    currentItemIndex : null,
    currentTimeOut : 'undefined',
    next : function()
    {
        ++CommentsWidget.currentItemIndex;
        if(CommentsWidget.currentItemIndex >= CommentsWidget.itemsArray.length)
            CommentsWidget.currentItemIndex = 0;
        CommentsWidget.display();
    },
    prev : function()
    {
        --CommentsWidget.currentItemIndex;
        if(CommentsWidget.currentItemIndex < 0)
            CommentsWidget.currentItemIndex = CommentsWidget.itemsArray.length-1;
        CommentsWidget.display();
    },
    clear : function()
    {
        CommentsWidget.itemsArray.hide();
    },
    display : function()
    {
        if(CommentsWidget.currentTimeOut != 'undefined')
            clearTimeout(CommentsWidget.currentTimeOut);
        CommentsWidget.clear();
        $(CommentsWidget.itemsContainerObject + " ul li:eq(" + CommentsWidget.currentItemIndex + ")").fadeIn("slow");  
        CommentsWidget.currentTimeOut = setTimeout(CommentsWidget.next, 8000);
    },
    init : function()
    {
        CommentsWidget.itemsContainerObject = "div.comments-banner-valuation";
        CommentsWidget.itemsArray = $(CommentsWidget.itemsContainerObject + " ul li");
        if(CommentsWidget.itemsArray.length <= 1)
        {
            $(CommentsWidget.itemsContainerObject + " ul li:first").show();
            $(CommentsWidget.itemsContainerObject + " a.feed-nav").hide();
            return;
        }
        else
        {
            $(CommentsWidget.itemsContainerObject + " a.link-prev").click(function(e){
                CommentsWidget.prev();
                e.preventDefault();
            });
            $(CommentsWidget.itemsContainerObject + " a.link-next").click(function(e){
                CommentsWidget.next();
                e.preventDefault();
            });
        }       
        CommentsWidget.currentItemIndex = -1;
        CommentsWidget.next();
    }
}
function assignHotelBookingEvent()
{
    $('#ctl00_Content_BookingForm_boton').click(function(e) {
        //var destination = $('#ctl00_Content_BookingForm_ddlDestination').val();
        //var hotel = $('#ctl00_Content_BookingForm_ddlHotel').val();
        var checkIn = $('#ctl00_Content_BookingForm_tbArrived').val();
        var checkOut = $('#ctl00_Content_BookingForm_tbExit').val();

        /*
        if (!BookingFormManager.datesValidation(checkIn) || !BookingFormManager.datesValidation(checkOut)) {
            alert('Por favor, introduzca unas fechas válidas de entrada y salida para su reserva');
            e.preventDefault();
            return false;
        }
        */
        if (checkIn!="" && checkOut!=""){
            $('#loadPopup').show(); 
        }
        /*
        else
        BookingFormManager.launchBookingPopUp(destination, hotel, checkIn, checkOut);
        e.preventDefault();
        */
    });
}

function initVideoLauncher() {
    $('#videoBannerLink').fancyZoom({ directory: '/imgLib/fancyZoom', width: 873, height: 525 });
}

$().ready(function() { CommentsWidget.init(); assignHotelBookingEvent(); initVideoLauncher(); numhabs(parseInt($('#ctl00_Content_BookingForm_n_hab').val()) - 1); /*showWidgets();*/ });


//promociones 

$(document).ready(function(){
hidePromoModalWindow();
$("#promotionsContent .promotion-pack a").click(function(e) { arrangeElements(this); e.preventDefault(); });
    $("#promotionModalWindow #promoWinClose a").click(function(e){ hidePromoModalWindow(); e.preventDefault(); });
});
function arrangeElements(sender)
{
    var userLoggedIn = Sys.Services.AuthenticationService.get_isLoggedIn();
    var requiresUserLoggedIn = $(sender).parent().parent().hasClass("exclusive-true");
    
    if(requiresUserLoggedIn && !userLoggedIn)
    {
        if(confirm('Esta es una promoción VIP reservada a usuarios registrados y requiere iniciar sesión. ¿Desea crear gratuitamente una cuenta de usuario o iniciar sesión en una ya existente?\n'))
        {
            document.location = '/content/members/default.aspx';
            return;
        }
        else
            return;
    }
    
    var title = $(sender).attr('title');
    var content = $(sender).parent().siblings("div.link-offer:first");
    var dates   = $(sender).parent().siblings("p.date-box:first");
    var isPack = true;  //$(sender).parent().parent().hasClass("promotion-pack");

    showPromoModalWindow(title, $(dates).html(), $(content).html(), isPack)   
}
function showPromoModalWindow(title, dates, content, isPack) {
    
    $("#promotionModalWindow h3").html(dates);
    $("#promotionModalWindow h2").html(title);
    $("#promotionModalWindow #promoWinDetailedContent").html(content);
    $("#promotionOverLayer, #promotionModalWindow").show();


    $("#promotionModalWindow a.launchBookingForm").click(function(e) {
        if (isPack) {
            e.preventDefault();
            location = "http://hotelesrh.igmssl.com/paquetes_rh/paquetes.php?action=PAQ_lista&idioma=ES";
        }

    });
    
    // KOALAB adjusts vertical offset
    $("#promotionModalWindow").css("margin-top", '-' + $("#promotionModalWindow").height()/2 + 'px');
}
function hidePromoModalWindow()
{
    $("#promotionOverLayer, #promotionModalWindow").hide();
}
