(function($){
        
    var frs = this;

    frs.Resorts = Class.extend({
        init: function(options) {
            this.options = $.extend({}, this.options, options);

            this.quickJump = new frs.Form($('#quick-jump-form'), { widgets: { tq: DestSelect, theme: ThemeSelect }, mode: this.options.mode });

            if (this.options.listing) {
                this.listTabs = new frs.Tabs($('#secondary-nav .nav-tabs li a'), frs.Tab, $('#resort-list-container'));
                this.resortListCollection = new frs.Collection($('.resort-list'), ResortList);
            }
        }
    });

    var ResortList = frs.Node.extend({
        init: function(el, options) {
            this._super(el, options);

            this.resorts = this.$el.children('ul');

            if (this.resorts.height() > 155) {
                this.$el.children('a.up').show();
                this.$el.children('a.down').show();
                this.$el.scrollable(this.options);
            }
        },
        options: {
            next: '.down',
            prev: '.up',
            vertical: true
        }
    });

    var ThemeSelect = frs.Dropdown.extend({
        init: function(el, form, field, options) {
            this._super(el, form, field, options);

            if (this.form.options.mode == 'resort') {
                this.list.options.scrollToSelected = false;
                this.list.items.items[0].disable();
                this.getItemByVal('DIVIDER').disable();
                for (var i in this.list.items.items) {
                    if (this.list.items.items[i].$el.hasClass('theme-group')) this.list.items.items[i].disable();
                    if (this.list.items.items[i].$el.hasClass('divider')) break;
                }
            }
        },
        events: {
            change: function() {
                window.location = this.list.items.items[this.selectedIndex].$el.attr('data-url');
            }
        }
    });

    var DestSelect = frs.Dropdown.extend({
        events: {
            change: function() {
                var url = this.list.items.items[this.selectedIndex].$el.attr('data-url');

                if (this.val() == 'NULL') {
                    var th = this.form.fields.items.theme_drp.widget;
                    url = (this.form.options.mode === "resort") ? th.getItemByVal(th.val().split("-").slice(1).join("-")).$el.attr("data-url") : th.list.items.items[th.selectedIndex].$el.attr('data-url');
                }

                window.location = url;
            }
        }
    });

}).call(frs, jQuery);
