/*
    Vertical Fly-Out Menus
    Jon Parrott, 2010, Eyseore, 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.absolutize();
            elem.up().observe( 'mouseover', function(){
                if( this.hide_timer != 0 ){ clearTimeout( this.hide_timer ); }
                
                var parent_layout = new Element.Layout(this.up());
                var layout = new Element.Layout(this);
                
                var position = parent_layout.get('left') + parent_layout.get('padding-box-width') - 2; // right side of parent
                this.setStyle({ 'left':  position + 'px' });
                this.setStyle({ 'top': (parent_layout.get('top') ) + 'px'});
                
                this.setStyle({ 'width': parent_layout.get('width') + 'px' });
                
                if( elem.getStyle('display') == 'none' ) this.appear({duration: 0.3});
            }.bind( elem ));
            elem.up().observe( 'mouseout', function(){
                this.hide_timer = window.setTimeout( function(){ 
                    this.fade({duration: 0.5});
                }.bind( this ), 300 );
            }.bind( elem ));
        });
    };
    
    make_menu('.sub_sub_menu');
});
