(function($){
        
    var frs = this;

    frs.xhr = {
        reportError: function(url, t) {
            if (this.reportErrors) {
                $.ajax({
                    url: frs.xhr.errorUrl,
                    type: 'POST',
                    data: {
                        ajaxUrl: encodeURI(url),
                        elapsedTime: t
                    },
                    error:function() {
                        return true;
                    }
                });
            }
        }
    };

    frs.App = Class.extend({
        init: function(options) {
            this.options = $.extend({}, this.options, options);
            
            // Template initialisation
            ich.grabTemplates();
            
            // Add print link
            new PrintLink(ich.printLink({ isIE: function() { return ($.browser.msie && $.browser.version <= 8); }})).$el.appendTo('#footer p');

            this.infoLink = new InfoLink($('#sub-nav #info a'));

            frs.loader = $('<img>').attr('src', this.options.mediaDir+'/img/'+this.options.loader).css({
                'margin': '0 auto',
                'display': 'block'
            });

            // Add support for :before and :after replacement for IE < 8
            if (frs.isIE7) {
                this.prependSelectors = [
                    '#full-search a',
                    '#info a',
                    '.country-name',
                    '#footer-links a',
                    'a.button.lms',
                    '#lms a.button.lms',
                    '.close',
                    '#expanded-nav.extras .description',
                    '.promotion h3',
                    '#breadcrumbs li:first-child a',
                    '#sungolf', '#sunski',
                    '#secondary-nav a.active',
                    '#search .flight.compact #group-info',
                    '.booking .search h1',
                    '#ostopolku-form h1',
                    '.search .checkbox', '.search .radio',
                    '.theme-box li ul a',
                    '#holiday-options-list .resorts a',
                    '#holiday-options-list .resorts span',
                    '.resort-info h3 a.top',
                    '.anchorlinks a'
                ];
                this.appendSelectors = ['button.next span', 'a.button.next', '#lms a.button.lms', '#search .flight.compact #group-info'];
                $(this.prependSelectors.join(',')).prepend('<b />');
                $(this.appendSelectors.join(',')).append('<b />');
                $('#breadcrumbs li').not(':first-child').prepend('<b>» </b>');
            }
            if (frs.isIE8) {
                this.prependSelectors = [
                    '.search .checkbox', '.search .radio'
                ];
                $(this.prependSelectors.join(',')).prepend('<b />');
            }
        },
        reloadSearchForms: function() {
            if (frs.searchForms) delete frs.searchForms;
            frs.searchForms = new frs.Collection($('form.search'), frs.Form, { nodeOptions: { mediaDir: this.options.mediaDir } });
        }
    });

    var PrintLink = frs.Node.extend({
        events: { click: function() { window.print(); } }
    });

    var InfoLink = frs.Node.extend({
        init: function(el, options) {
            this.options = $.extend(true, {}, this.options, options);
            this._super(el, this.options);
            this.infoList = new InfoList($('#info-nav'), { trigger: this });
        },
        events: {
            mouseenter: function() { this.infoList.show(); },
            mouseleave: function() { this.infoList.hide(); },
            click: function(e) { e.preventDefault(); e.stopPropagation(); }
        }
    });
    var InfoList = frs.Overlay.extend({
        events: {
            onShow: function() {
                this.trigger.$el.addClass('hover');
                this.$el.slideDown('fast');
            },
            onHide: function() {
                this.$el.hide();
                this.trigger.$el.removeClass('hover');
            }
        }
    });

}).call(frs, jQuery);
