﻿/*
* Javascript for last minute trips page
* @requires jQuery
* @requires Highslide
*/

// Create NetR namespace if it doesn't exist
if (typeof (NetR) === 'undefined') {
    var NetR = {};
}

NetR.LastMinute = function() {
    var self = this;
    $('#last-minute input[name=season]').click(function() {
        $('#last-minute').submit();
    });
    self.hotelInfo();
    self.flightInfo();
};

NetR.LastMinute.prototype = {
    addSpinner: function(parentId) {
        var parentElement = document.getElementById(parentId);
        var spinnerId = parentId + '-spinner';
        if ($('#' + parentId + '~img').length == 0) {
            var spinner = document.createElement('img');
            spinner.setAttribute('id', spinnerId);
            spinner.setAttribute('class', 'spinner');
            spinner.setAttribute('alt', _('loading'));
            spinner.setAttribute('src', '/i/ajax-loader.gif');
            parentElement.parentNode.appendChild(spinner);
        }
    },
    removeSpinner: function(parentId) {
        $('#' + parentId + '~img').remove();
    },
    hotelInfo: function() {
        $('.last-minute-hotel a').each(function(i) {
            var href = $(this).attr('href');
            $(this).attr('href', href + '?ajax=1');
            $(this).click(function() {
                return hs.htmlExpand(this, { objectType: 'iframe', outlineType: 'rounded-white', wrapperClassName: 'highslide-wrapper', outlineWhileAnimating: true, preserveContent: false, width: 620, height: 670 });
            });
        });
    },
    flightInfo: function() {
        $('.last-minute-destination').each(function(i) {
            var dest = this.childNodes[0].textContent;
            var highslideContent = this.childNodes[1];
            if (highslideContent != null) {
                var close = document.createElement('a');
                close.href = '#';
                close.textContent = 'Close';
                $(close).click(function() { return hs.close(this); })
                highslideContent.insertBefore(close, highslideContent.childNodes[0]);
                var link = document.createElement('a');
                link.textContent = dest;
                link.href = "#";
                $(link).click(function() {
                    return hs.htmlExpand(this, { contentId: highslideContent.id, outlineType: 'rounded-white', width: 250, height: 100 });
                });
                this.replaceChild(link, this.childNodes[0]);
                $(highslideContent).hide();
            }
        });
    }
};
