/*
    Horizontal Drop-Down Menus
    Jon Parrott, 2010, Eyesore, Inc
    Requires Prototype and Scriptaculous
*/
Event.observe( document, 'dom:loaded', function(){
    var make_menu = function( selector ){
        $$(selector).each( function( elem ){
            
            elem.hide_timer = 0;
            
            elem.up().observe( 'mouseover', function(){
                if( this.hide_timer != 0 ){ clearTimeout( this.hide_timer ); this.hide_timer = 0; }
                
                var parent_layout = new Element.Layout(this.up());
                var layout = new Element.Layout(this);
                
                var position = parent_layout.get('left'); // center of parent
                this.setStyle({ 'left':  position + 'px' });
                
                position = parent_layout.get('top') + parent_layout.get('padding-box-height');
                this.setStyle({ 'top':  position +'px' });
                
                if( elem.getStyle('display') == 'none' ) this.appear({duration: 0.2});
            }.bind( elem ));
            
            elem.up().observe( 'mouseout', function(){
                this.hide_timer = window.setTimeout( function(){ 
                    this.fade({duration: 0.3});
                }.bind( this ), 300 );
            }.bind( elem ));
            
        });
    };
    
    make_menu( '.sub_menu' );
});
