﻿$(window).ready(function() { calendars.init(); $('a[rel*=facebox]').facebox(); $(document).pngFix(); var cacheImage1 = new Image(); var cacheImage2 = new Image(); cacheImage1.src = '/imgLib/ajax-wait/bg.jpg'; cacheImage2.src = '/imgLib/ajax-wait/ajax-loader.gif'; $(".wait-unload").click(function(e) { $('#ajaxModalWaitContainer').show().siblings('form').hide(); }); $(".wait-submit").click(function(e) { if (Page_IsValid) $('#ajaxModalWaitContainer').show().siblings('form').hide(); }); newsletter.init(); BannerController.init(); Promotions.init(); frontMap.init(); $('.children select').change(function(e) { childrenUpdater(this); }); $('.rooms-updater:first').change(function() { roomUpdater(); }); roomUpdater(); childrenUpdater($('.children select')); }); Date.prototype.goto = function(n) { this.setTime(this.getTime() + n * 86400000); return this; }; var calendars = { init: function() {
    $('.date-pick').datepicker({ dateFormat: 'dd/mm/yy', firstDay: 1, minDate: +1, monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], dayNames: ['Domingo', 'Lunes', 'Martes', 'M&iacute;ercoles', 'Jueves', 'Viernes', 'S&aacute;bado'], dayNamesMin: ['DO', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], showAnim: 'fadeIn', inline: false, numberOfMonths: [1, 1], onSelect: function(dateText) {
        var newDate = $.datepicker.parseDate('dd/mm/yy', dateText); if ($('.date-pick').index(this) == 0) {
            $('.date-pick:last').datepicker('option', 'minDate', newDate.goto(0)); var checkOut = $('.date-pick:last').datepicker('getDate'); if (newDate > checkOut)
                $('.date-pick:last').datepicker('setDate', newDate.goto(1));
        }
        else {
            $('.date-pick:first').datepicker('option', 'maxDate', newDate.goto(-1)); var checkIn = $('.date-pick:first').datepicker('getDate'); if (newDate < checkIn)
                $('.date-pick:first').datepicker('setDate', newDate.goto(-1));
        } 
    } 
    });
} 
}; var newsletter = { defaultValues: function() {
    var textbox = $('#tbNewsletterEmail'); textbox.focus(function() {
        if (textbox.attr('title') == textbox.val())
            textbox.val('');
    }); textbox.blur(function() {
        if (textbox.val() == '')
            textbox.val(textbox.attr('title'));
    });
}, process: function() {
    $('#newsletter input').hide().siblings('p.newsletter-process').show(); var email = $('#tbNewsletterEmail').val(); $.post("AjaxNewsletter.ashx", { email: email }, function(data) {
        if (data.toString() == '0')
            $('#newsletter p.newsletter-process').hide().siblings('p.newsletter-success').show(); else
            $('#newsletter p.newsletter-process').hide().siblings('p.newsletter-fail').show();
    });
}, init: function() { this.defaultValues(); $('#newsletter #btnNewsletterSubmit').click(function(e) { newsletter.process(); e.preventDefault(); }); $('#newsletter p.newsletter-fail a').click(function(e) { $('#newsletter p').hide().siblings('input').show(); e.preventDefault(); }); } 
}; var bannersArray = new Array(); var BannerController = { init: function() { bannersArray = $('#imgBanner a').get(); BannerController.refreshBanner(); $('.links-promos a.prev, p.navigation-banner a.prev').click(function() { BannerController.prev(); return false; }); $('.links-promos a.next, p.navigation-banner a.next').click(function() { BannerController.next(); return false; }); }, next: function() { BannerController.CurrentBanner = BannerController.CurrentBanner == bannersArray.length - 1 ? 0 : ++BannerController.CurrentBanner; BannerController.refreshBanner(); }, prev: function() { BannerController.CurrentBanner = BannerController.CurrentBanner == 0 ? bannersArray.length - 1 : --BannerController.CurrentBanner; BannerController.refreshBanner(); }, refreshBanner: function() {
    $("#imgBanner").html(''); if (BannerController.CurrentTimeOut != 'undefined') { clearTimeout(BannerController.CurrentTimeOut); clearTimeout(BannerController.CurrentLoadTimeOut); }
    BannerController.CurrentLoadTimeOut = setTimeout(function() { $("#imgBanner").html(bannersArray[BannerController.CurrentBanner]); }, 700); if (bannersArray.length - 2 < 1)
        return; BannerController.CurrentTimeOut = setTimeout(function() { BannerController.next(); }, 30000);
}, CurrentBanner: 0, CurrentTimeOut: 'undefined', CurrentLoadTimeOut: 'undefined'
}
function printPage() { if (window.print) { window.print(); } else { var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(6, 2); } }
var frontMap = { onLoadComplete: function() { loadHotels.init(); }, fillPins: function(mapPart) {
    var visibleMapPart = $(mapPart); if (visibleMapPart.find('.pin').length > 0)
        return; $('#frontMap .map-part:visible ul li a').each(function(index, obj) { var jObj = $(obj); var title = jObj.text(); var link = jObj.attr('href'); var coords = jObj.attr('rel').split('xy'); visibleMapPart.append('<a title="' + title + '" class="pin" href="' + link + '" style="top:' + coords[1] + 'px;left:' + coords[0] + 'px;">' + title + '</a>'); }); this.onLoadComplete();
}, switchMap: function(sender) { var obj = $(sender); obj.addClass('selected').siblings('.map-link').removeClass('selected'); $('.map-part').hide().siblings(obj.attr('href') + ':first').fadeIn(function() { frontMap.fillPins(this); }); }, init: function() { $('#frontMap #mapLinks a.map-link').click(function(e) { frontMap.switchMap(this); e.preventDefault(); }); this.fillPins('#frontMap .map-part:visible'); $('#frontMap .map-part .pin').live('mouseover', function(e) { var rel = $(this).css('left').replace('px', '') + 'xy' + $(this).css('top').replace('px', ''); $('#frontMap .map-part:visible ul li a[rel="' + rel + '"]').toggleClass('hover'); }); $('#frontMap .map-part .pin').live('mouseout', function(e) { $('#frontMap .map-part:visible ul li a').removeClass('hover'); }); $('#frontMap .map-part ul li a').hover(function(e) { $('#frontMap .map-part:visible .pin[title="' + $(this).text() + '"]').css('background-position', 'left bottom'); }, function(e) { $('#frontMap .map-part:visible .pin[title="' + $(this).text() + '"]').css('background-position', 'left top'); }); } 
}
var loadHotels = { onLoadComplete: function() { UpdateHotels.init(20000, 100, true); }, loadContent: function() { $.ajax({ url: "DefaultSelection.aspx", cache: true, async: true, success: function(html) { $("#notreSelection #selectionOnLoad").replaceWith(html); loadHotels.onLoadComplete(); } }); }, init: function() { this.loadContent(); } }
var UpdateHotels = { loop: false, hotelRefreshInterval: 10000, hotelBoxInterval: 300, divLenght: 0, currentOffersIndex: 0, divMainTimeOut: null, divChildrenTimeOut: null, showHotelBox: function() {
    $('.boxes-offers').eq(UpdateHotels.currentOffersIndex).children('div.box-hotels-offers:hidden:first').fadeIn(); var divsRemaining = $('.boxes-offers').eq(UpdateHotels.currentOffersIndex).children('div.box-hotels-offers:hidden:first').length; if (divsRemaining <= 0)
        clearInterval(UpdateHotels.divChildrenTimeOut);
}, refreshDiv: function() {
    clearTimeout(UpdateHotels.divMainTimeOut); $('.boxes-offers').hide(); ++UpdateHotels.currentOffersIndex; if (UpdateHotels.currentOffersIndex == UpdateHotels.divLenght)
        UpdateHotels.currentOffersIndex = 0; $('.boxes-offers').eq(UpdateHotels.currentOffersIndex).show(); if (UpdateHotels.loop)
        UpdateHotels.divMainTimeOut = setTimeout('UpdateHotels.refreshDiv()', UpdateHotels.hotelRefreshInterval); $('.boxes-offers').eq(UpdateHotels.currentOffersIndex).children('div.box-hotels-offers').hide(); UpdateHotels.divChildrenTimeOut = setInterval('UpdateHotels.showHotelBox()', UpdateHotels.hotelBoxInterval);
}, init: function(hotelRefreshInterval, hotelBoxInterval, loop) { UpdateHotels.hotelRefreshInterval = hotelRefreshInterval; UpdateHotels.hotelBoxInterval = hotelBoxInterval; UpdateHotels.loop = loop; UpdateHotels.divLenght = $('.boxes-offers').length; UpdateHotels.currentOffersIndex = UpdateHotels.divLenght - 1; $('#refreshHotels').click(function(e) { UpdateHotels.refreshDiv(); e.preventDefault(); }); UpdateHotels.refreshDiv(); } 
}
var Promotions = { itemsContainerObject: null, itemsArray: null, currentItemIndex: null, currentTimeOut: 'undefined', next: function() {
    ++Promotions.currentItemIndex; if (Promotions.currentItemIndex >= Promotions.itemsArray.length)
        Promotions.currentItemIndex = 0; Promotions.display();
}, clear: function() { Promotions.itemsArray.hide(); }, display: function() {
    if (Promotions.currentTimeOut != 'undefined')
        clearTimeout(Promotions.currentTimeOut); Promotions.clear(); var showPromotions = $(Promotions.itemsContainerObject + " ul li:eq(" + Promotions.currentItemIndex + ")"); if (parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE") + 5)) <= 6)
        showPromotions.fadeIn("slow"); else
        showPromotions.slideDown("slow"); Promotions.currentTimeOut = setTimeout(Promotions.next, 4000);
}, init: function() {
    Promotions.itemsContainerObject = ".last-minute"; Promotions.itemsArray = $(Promotions.itemsContainerObject + " ul li"); if (Promotions.itemsArray.length <= 1) { $(Promotions.itemsContainerObject + " ul li:first").show(); return; }
    $('.more-promos').click(function(e) { Promotions.next(); e.preventDefault(); }); Promotions.currentItemIndex = -1; Promotions.next();
} 
}
function childrenUpdater(sender) {
    var numChildren = $(sender).val(); var ages = $(sender).parent().parent(); if (numChildren != '0')
        $(ages).find('.fieldset-ages').show(); else
        $(ages).find('.fieldset-ages').hide(); $(ages).find('.ages1,.ages2,.ages3').hide(); for (var i = 1; i <= numChildren; i++) { $(ages).find('.ages' + i.toString()).show(); } 
}
function roomUpdater() { var obj = $('#hab' + $('.rooms-updater:first').val()); obj.show(); obj.prevAll().show(); obj.nextAll('.fieldset-occupation').hide(); }
var suggest = { txtInput: null, idInput: null, ajaxUrl: null, ajaxLayer: null, ajaxNodeIndex: 0, filteringData: null, resetAjaxLayer: function() { this.ajaxNodeIndex = null; this.ajaxLayer.hide(); }, selectChild: function() { var selectedValue = this.ajaxLayer.find('div.selected').attr('title'); var selectedId = this.ajaxLayer.find('div.selected').attr('id'); this.txtInput.val(selectedValue); this.idInput.val(selectedId); }, bindMouseEvents: function() { $('#ajaxSuggestions div').live('mouseover', function() { $(this).addClass('selected').siblings().removeClass('selected'); suggest.ajaxNodeIndex = $('#ajaxSuggestions div').index(this); }); $('#ajaxSuggestions div').live('mousedown', function() { suggest.selectChild(); suggest.resetAjaxLayer(); }); }, bindKeyboardEvents: function(event) { switch (event.keyCode) { case 38: --this.ajaxNodeIndex; break; case 40: ++this.ajaxNodeIndex; break; case 13: this.selectChild(); this.ajaxLayer.hide(); return false; break; default: this.updateList(); this.selectChild(); break; }; var childItems = this.ajaxLayer.children('div').length; if (this.ajaxNodeIndex < 0) this.ajaxNodeIndex = childItems - 1; if (this.ajaxNodeIndex >= childItems) this.ajaxNodeIndex = 0; $('#ajaxSuggestions div:eq(' + this.ajaxNodeIndex + ')').addClass('selected').siblings().removeClass('selected'); this.selectChild(); return true; }, updateList: function() {
    this.idInput.val(''); this.ajaxLayer.html(''); if (this.txtInput.val().length < 2) { this.resetAjaxLayer(); return; }
    this.ajaxLayer.show().html('<span class="loading">Buscando destinos...</span>'); var newHtmlNodes = ''; $.getJSON(this.ajaxUrl, { query: this.txtInput.val(), filter: this.filteringData }, function(json) { $.each(json.items, function(i, item) { newHtmlNodes += '<div id="' + item.id + '" title="' + item.inputValue + '">' + item.name + '</div>'; }); suggest.ajaxLayer.html(newHtmlNodes).children('div:first').addClass('selected'); });
}, adjustAjaxLayerOffset: function() { var offset = this.txtInput.offset(); this.ajaxLayer.css('top', offset.top + 'px'); this.ajaxLayer.css('left', offset.left + 'px'); this.ajaxLayer.css('width', this.txtInput.outerWidth() + 'px'); this.ajaxLayer.css('margin-top', this.txtInput.outerHeight() + 'px'); }, init: function(textBox, idTextBox, ajaxController, filter, defaultText) {
    this.txtInput = $('#' + textBox); this.idInput = $('#' + idTextBox); this.ajaxUrl = ajaxController; this.filteringData = filter; if (defaultText == null)
        defaultText = 'Introduzca un destino'; this.txtInput.attr('autocomplete', 'off'); $('body').append('<div id="ajaxSuggestions"></div>'); this.ajaxLayer = $('#ajaxSuggestions'); if (!jQuery.support.boxModel)
        this.ajaxLayer.bgiframe(); this.adjustAjaxLayerOffset(); $(window).bind('resize', function() { suggest.adjustAjaxLayerOffset(); }); this.resetAjaxLayer(); this.txtInput.keydown(function(e) { return suggest.bindKeyboardEvents(e); }).blur(function() { suggest.selectChild(); suggest.ajaxLayer.hide(); }); this.txtInput.focus(function() { suggest.updateList(); suggest.adjustAjaxLayerOffset(); }); this.bindMouseEvents(); this.txtInput.val(defaultText); this.txtInput.focus(function() { if ($(this).val() == defaultText) $(this).val(''); }); this.txtInput.blur(function() { if ($(this).val() == '') $(this).val(defaultText); suggest.adjustAjaxLayerOffset(); }); $('.ajax-suggest-submit').click(function(e) {
            if (suggest.idInput.val() == '') { Page_IsValid = false; alert('Elija uno de los destinos propuestos.'); e.preventDefault(); }
            else
                if (Page_IsValid)
                $('#ajaxModalWaitContainer').show().siblings('form').hide(); else
                e.preventDefault();
        });
} 
};
