
var MenuDesplegable = Class.create()

MenuDesplegable.prototype = {
    initialize : function() {        
        $$(".menuDesplegable").each(function(item){
            item.setStyle({cursor:'pointer'});
        	item.observe("click", this.desplegar);

            var elemento = item.up('LI');        	
            elemento.observe('plegar',this.plegar);
            elemento.observe('desplegar',this.desplegar);
        	
        }.bind(this));
    },

    desplegar : function(evt){
        var elemento = this.up('LI');
        
        $(elemento).siblings().each(function(item){
            item.fire("plegar");
        });

        elementoMostrar = this.next('ul');
        if (elementoMostrar) 
        {
            if (elementoMostrar.visible())
            {
                this.src = this.readAttribute("plegatsrc");                        
            }
            else
            {
                this.src = this.readAttribute("desplegatsrc");            
            }
            elementoMostrar.toggle();
        }
    },

    plegar : function()
    {
        item = this.down("UL");
        if (item)
        {
            link = item.previous(".menuDesplegable");
            link.src = link.readAttribute("plegatsrc");  
            item.hide();
        }
    },
    
    statusChange : function()
    {
        
    }

};

Event.observe(window,"load", function(){
	Object.extend(window, new MenuDesplegable());
});

