﻿/*
==========================================================================================
Manejadores de eventos de calendario
==========================================================================================
*/
    var bannerUri;

    $(function() {
        $('#arrivalDate input.Entrada').datePicker({ createButton: false, clickInput: true, verticalOffset: 15 });
        $('#exitDate input.Salida').datePicker({ createButton: false, clickInput: true, verticalOffset: 15 });

        $('#arrivalDate input.Entrada').bind(
		        'dpClosed',
		        function(e, selectedDates) {
		            var d = selectedDates[0];
		            if (d) {
		                $('#exitDate input.Salida').dpSetStartDate(d.addDays(1).asString());
		            }
		        }
	        );
        $('#exitDate input.Salida').bind(
		        'dpClosed',
		        function(e, selectedDates) {
		            var d = selectedDates[0];
		            if (d) {
		                $('#arrivalDate input.Entrada').dpSetEndDate(d.addDays(-1).asString());
		            }
		        }
	        );

        $('#arrivalCalLink').click(function() { $('#arrivalDate input.Entrada').dpDisplay(); });
        $('#departureCalLink').click(function() { $('#exitDate input.Salida').dpDisplay(); });
        $("#content-right p").hide();
        $("#content-right h4").attr('class', 'more');
        $("#content-right h4").click(function() {
            if ($(this).attr('class') == "more") {
                //                $(this).next('p').slideDown();
                $(this).next('p').fadeIn();
                $(this).attr('class', "");
            }
            else {
                //	            $(this).next('p').slideUp();
                $(this).next('p').fadeOut();
                $(this).attr('class', 'more');
            }
        });
        $("#multiple").hide();
        $("#morebooking a").click(function() {
            $("#morebooking").hide();
            $("#header-form #form-search input.Buscar").hide();
            $("#multiple input.Buscar").show();
            $("#multiple").slideDown("slow");
            $('.contact-tooltip').hide();
        });
        $("#multiple #extendedFormFooter #simplebooking a").click(function() {
            $("#multiple").slideUp("slow", function() {
            $("#morebooking").slideDown();
                $('.contact-tooltip:first').show();
                $("#header-form #form-search input.Buscar").show();
                $("#ctl00_Rooms2, #ctl00_Rooms3").val('0');
            });
        });

        $("#multiple #ctl00_Adults2, #multiple #ctl00_Children2").change(function() {
            if ($("#multiple #ctl00_Rooms2").val() == '0')
                $("#multiple #ctl00_Rooms2").val('1')
        });

        $("#multiple #ctl00_Adults3, #multiple #ctl00_Children3").change(function() {
            if ($("#multiple #ctl00_Rooms3").val() == '0')
                $("#multiple #ctl00_Rooms3").val('1')
        });

        //        var bannerWidth = $('#bannerContent img').css("width"); //.attr('width');
        //        var bannerHeight = parseInt($('#bannerContent img').css("height"))+5;  //.attr('height'))+20;
        //        bannerUri = '#TB_inline?height=' + bannerHeight.toString().replace('px','') + '&width=' + bannerWidth.replace('px','') + '&inlineId=bannerContent';
        //        $('.bannerLinkLauncher a').attr('href', bannerUri);
        //tb_show('Bienvenido al Hotel Eurotennis', url, null); 


        $("#contentOffersEvents .content-movies a").click(function(e) {
            e.preventDefault();
            var w = 1024, h = 768;
            if (document.all) {
                w = document.body.clientWidth;
                h = document.body.clientHeight;
            }
            else if (document.layers) {
                w = window.innerWidth;
                h = window.innerHeight;
            }
            var popW = 640, popH = 480;
            var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;
            var videoWin = window.open('/videoLib/default.html', 'videoWin', 'status=0,toolbar=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
            videoWin.focus();
        });

        $('#upperContact a').click(function(e) { e.preventDefault(); }).mouseover(function() { $('#contactTooltip').show(); }).mouseout(function() { $('#contactTooltip').hide(); });

    });
    $(document).ready(function(){
		$(document).pngFix();
 
      // Inicializamos la gestion de banners promocionales y noticias
      Promotions.init();
      Events.init();

    hidePromoModalWindow();
    $("#contentOffersEvents .content-offers ul a").click(function(e){ arrangeElements(e.target); e.preventDefault(); });
    $("#promotionModalWindow #promoWinClose a").click(function(e){ hidePromoModalWindow(); e.preventDefault(); });

	});
  
  Promotions = {
    itemsContainerObject : null,
    itemsArray : null,
    currentItemIndex : null,
    currentTimeOut : 'undefined',
    next : function()
    {
        ++Promotions.currentItemIndex;
        if(Promotions.currentItemIndex >= Promotions.itemsArray.length)
            Promotions.currentItemIndex = 0;
            
        Promotions.display();
    },
    prev : function()
    {
        --Promotions.currentItemIndex;
        if(Promotions.currentItemIndex < 0)
            Promotions.currentItemIndex = Promotions.itemsArray.length-1;

        Promotions.display();
    },
    clear : function()
    {
        Promotions.itemsArray.hide();
    },
    display : function()
    {
        if(Promotions.currentTimeOut != 'undefined')
            clearTimeout(Promotions.currentTimeOut);
        Promotions.clear();
        $(Promotions.itemsContainerObject + " ul li:eq(" + Promotions.currentItemIndex + ")").slideDown("slow");  
        Promotions.currentTimeOut = setTimeout(Promotions.next, 8000);
    },
    init : function()
    {
        Promotions.itemsContainerObject = ".content-offers";
        Promotions.itemsArray = $(Promotions.itemsContainerObject + " ul li");
        
        if(Promotions.itemsArray.length <= 1)
        {
            $(Promotions.itemsContainerObject + " ul li:first").show();
            $(Promotions.itemsContainerObject + " a.feed-nav").hide();
            return;
        }
        else
        {
            $(Promotions.itemsContainerObject + " a.link-prev").click(function(e){
                Promotions.prev();
                e.preventDefault();
            });
            $(Promotions.itemsContainerObject + " a.link-next").click(function(e){
                Promotions.next();
                e.preventDefault();
            });
        }
        
        Promotions.currentItemIndex = -1;
        Promotions.next();
    }
}

Events = {
    itemsContainerObject : null,
    itemsArray : null,
    currentItemIndex : null,
    currentTimeOut : 'undefined',
    next : function()
    {
        ++Events.currentItemIndex;
        if(Events.currentItemIndex >= Events.itemsArray.length)
            Events.currentItemIndex = 0;
            
        Events.display();
        
    },
    prev : function()
    {
        --Events.currentItemIndex;
        if(Events.currentItemIndex < 0)
            Events.currentItemIndex = Events.itemsArray.length-1;

        Events.display();
    },
    clear : function()
    {
        Events.itemsArray.hide();
    },
    display : function()
    {
        if(Events.currentTimeOut != 'undefined')
            clearTimeout(Events.currentTimeOut);
        Events.clear();
        $(Events.itemsContainerObject + " ul li:eq(" + Events.currentItemIndex + ")").slideDown("slow");  
        Events.currentTimeOut = setTimeout(Events.next, 8000);
    },
    init : function()
    {
        Events.itemsContainerObject = ".content-events";
        Events.itemsArray = $(Events.itemsContainerObject + " ul li");
        
        if(Events.itemsArray.length <= 1)
        {
            $(Events.itemsContainerObject + " ul li:first").show();
            $(Events.itemsContainerObject + " a.feed-nav").hide();
            return;
        }
        else
        {
            $(Events.itemsContainerObject + " a.link-prev").click(function(e){
                Events.prev();
                e.preventDefault();
            });
            $(Events.itemsContainerObject + " a.link-next").click(function(e){
                Events.next();
                e.preventDefault();
            });
        }
        
        Events.currentItemIndex = -1;
        Events.next();
    }
}

function arrangeElements(sender)
{   
    var title   = $(sender).get(0);
    var content = $(sender).parent().siblings("p.body-offer").get(0);
    showPromoModalWindow($(title).html(), $(content).html())
}
function showPromoModalWindow(title, content)
{
    $("#promotionModalWindow h2").html(title);
    $("#promotionModalWindow #promoWinContent p").html(content);
    $("#promotionModalWindow").show();
    $("#contentOffersEvents").hide();
}
function hidePromoModalWindow()
{
    $("#promotionModalWindow").hide();
    $("#contentOffersEvents").show();
}