var Navigation = function() {
    this.ACTIVATION_DELAY = 300;
    this.DEACTIVATION_DELAY = 200;

    this.activeTab;
    this.lastActiveTab;
    this.activationTimer;
    this.deactivationTimer;

    this.showTab = function(tabObj) {
        if (this.activeTab === tabObj.index()) {
            this.lastActiveTab = tabObj.index();

            tabObj.find('.spacer').attr('style', 'display:none;');
            tabObj.prev().find('.spacer').attr('style', 'display:none;');
            tabObj.addClass('active');
        }
    };

    this.hideTab = function(tabObj) {
        if (this.activeTab !== tabObj.index()) {
            tabObj.find('.spacer').attr('style', 'display:block;');
            tabObj.prev().find('.spacer').attr('style', 'display:block;');
            tabObj.removeClass('active');
        }
    }

    this.setup = function() {
        var instance = this;

        $('.navigation2 .menu-item').hover(
            function() {
                instance.activeTab = $(this).index();

                if (instance.lastActiveTab === $(this).index()) {
                    clearTimeout(instance.deactivationTimer);
                }

                var tabObj = $(this);

                var closure = function() {
                    instance.showTab(tabObj);
                };

                instance.activationTimer = setTimeout(closure, instance.ACTIVATION_DELAY);
            },
            function() {
                instance.activeTab = null;
                clearTimeout(instance.activationTimer);

                var tabObj = $(this);

                var closure = function() {
                    instance.hideTab(tabObj);
                };

                instance.deactivationTimer = setTimeout(closure, instance.DEACTIVATION_DELAY);
            }
        );
    }

    this.setup();
};

$(function() {
    var nav = new Navigation();
});

$(document).ready(function(){
    $('#navigation>ul>li').hover(function(){
        $(this).addClass('hover');
        if($.browser.msie && $.browser.version == '6.0') {
            $('select').css('visibility', 'hidden');
        }
    }, function(){
        $(this).removeClass('hover');
        if($.browser.msie && $.browser.version == '6.0') {
            $('select').css('visibility', 'visible');
        }
    });
    $('.category-dropdown, #category-dropdown-new, #category-dropdown').change(function(){
        if($(this).val() != 1) {
            window.location.href = $(this).val();
        }
    });
});

