﻿    var MenuDesplegable = Class.create()
    
    MenuDesplegable.prototype = { 
        
       initialize : function() {
            var opciones = $$("a.menuDesplegable");
            for(cont = 0; cont < opciones.length; cont++){
		        Event.observe(opciones[cont], 'click', this.desplegar.bind(this))
        	}
        },
        
        desplegar : function(evt){
            var elemento = Event.findElement(evt, 'DIV');
            $(elemento).siblings().each(function(item){
                this.plegar(item);
            }.bind(this));
            hijos = elemento.immediateDescendants();
            $(hijos).each(function(item){
                if (item.hasClassName('optMenuDesplegable')){
                    if(item.visible()){
                        item.hide();
                    }else{
                        item.show();
                    }
                }
            });            
        },
        
        plegar : function(item){
            item.immediateDescendants().each(function(item) {
                this.plegar(item);
                if (item.hasClassName('optMenuDesplegable')){
                    item.hide();
                }
            }.bind(this));                
        }                    
	}
		
	Event.observe(window,"load", function(){ new MenuDesplegable(); });