var navHover = Class.create();

navHover.prototype = {
	
	initialize: function(){
	   var els = $('nav').select('.top');
	   els.invoke('observe', 'mouseenter', this.mouseEnter.bindAsEventListener(this));
	   els.invoke('observe', 'mouseleave', this.mouseLeave.bindAsEventListener(this));
	},
    
    getHoverNav: function(e){
        var hovEl = e.element();
        if(!hovEl.hasClassName('top')){
            hovEl = hovEl.up('.top');
        }
        if(hovEl.down('.sub')){
            return false;
        }
        hovEl.down(0).toggleClassName('topHover');
        return hovEl.down('.navHover');
    },
	
    mouseEnter: function(e){
        var hover = this.getHoverNav(e);
        if(hover === false){
            return true;
        }
        hover.show();
    },
	
    mouseLeave: function(e){
        var hover = this.getHoverNav(e);
        if(hover === false){
            return true;
        }
        hover.hide();
    }
};


var catTypes = Class.create();

catTypes.prototype = {

    inTransition: false,

    initialize: function(){
        $$('#byCategoryType > div > a').invoke('observe', 'click', this.onClick.bindAsEventListener(this));
        $('byCategoryType').select('.silverTab').invoke('observe', 'mouseleave', this.onMouseOut.bindAsEventListener(this));
    }, 
    
    open: function(e){
        if(this.inTransition == 1){
            return false;
        }
        this.inTransition = 1;
        new Effect.SlideDown(e, {
            duration:0.3,
            queue:{scope:'content',position:'end'},
            beforeSetup:function(effect) {
                //the height gets set up on the Effect function call, make it use the height before the effect starts
                effect.options.scaleMode.originalHeight=effect.element.getHeight();
            },
            afterFinish: function(){
                this.inTransition = 0;
            }.bind(this)
        });
        return false;
    },
    
    close: function(e){
        if(this.inTransition == 2){
            return false;
        }
        this.inTransition = 2;
        new Effect.SlideUp(e, {
            duration:0.3,
            queue:{scope:'content',position:'end'},
            beforeSetup:function(effect) {
                //the height gets set up on the Effect function call, make it use the height before the effect starts
                effect.options.scaleMode.originalHeight=effect.element.getHeight();
            },
            afterFinish: function(){
                this.inTransition = 0;
            }.bind(this)
        });
        return false;
    },
    
    
    onClick: function(e){
        var el = e.findElement('div.silverTab').childElements()[1];
        e.stop();
        if(el.visible()){
            this.close(el);
        }else{
            this.open(el);
        }
    },
    
    onMouseOut: function(e){
        var el = e.findElement('div.silverTab').childElements()[1];
        e.stop();
        if(el.visible()){
            this.close(el);
        }
    }

};


/*
CSS Browser Selector v0.2.7
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
var css_browser_selector = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();

