/*

<script type='text/javascript'>     
    Event.observe(window, 'load', init, true);  
    function init(){ 
        slide_menu = new SliderMenu('<?=$_SESSION["alias"]?>');
    };           
</script>  

 */

var SliderMenu = Class.create();
    SliderMenu.prototype = {
          active_item: null,
          active_link: null,
          id:null,
		  enable_first:true,
          initialize: function(id,reference) {
                this.id = id;
                a_menu = $$('#'+id+' dl dt a');
                var found = false;
				var first = false;
                var nothing = false;
                this.reference = '';
                
	
                var child = $('menu_'+reference);
                
                if(this.enable_first && reference.length == 0){
                    //first = true;    
                }
                else{
                    if (child) {
                        var up = child.up('dl');
                        nothing = true;
                        if (up) {
                            var parent = up.down('dt a');
                            nothing = false;
                        }
                        if (parent) {
                            this.reference = parent.id;
                        }
                    }
                    if(this.enable_first && this.reference.length == 0){
                        if (!nothing) {
                            first = true;
                        }
                    }
                }
                
                if(child){
                    child.up(0).addClassName('active');
                }

                a_menu.each(function(el){
                    var dd_el = el.up(0).next(0);


                    if((first || this.reference == el.identify() ) && !found  ){
                        el.up(0).addClassName('active_header');
                        
                        this.active_item = dd_el; 
                        this.active_link = el;
                        
                        dd_el.show();
                        found = true;
                    }
                    else{
                        dd_el.hide();
                    }
                    
                    //click event for each header
                    
                    el.observe('click', this.setItem.bind(this));
                    return false;
       
                }.bind(this));
          },
          setItem: function(event){

                var element = Event.element(event);                        
                var new_el = element.up('dl').down('dd'); 
                   
                if(new_el.visible()){
                    Effect.SlideUp(new_el, {duration: 0.5});
                }
                else{

                    Effect.SlideDown(new_el, {duration: 0.5});
    
                }          
                return false;
          
          }
    };  
