var MENU = {
	
	init : function() {
		var submenu = document.getElementById('menu').getElementsByTagName('ul');
		for(i=0;i<submenu.length;i++){
			submenu[i].className = 'plegado';
		}
		var enlaceSubmenu = document.getElementById('menu').getElementsByTagName('a');
		for(i=0;i<enlaceSubmenu.length;i++){
			if(enlaceSubmenu[i].className == 'submenu'){
				enlaceSubmenu[i].onclick = function(){
					return MENU.enlace(this);
				}
			}
		}
	},
	
	enlace : function(elEnlace) {
		var submenu = document.getElementById('menu').getElementsByTagName('ul');
		for(i=0;i<submenu.length;i++){
			submenu[i].className = 'plegado';
		}
		if ((elEnlace.nextSibling.nodeType != 3) && (elEnlace.nextSibling.nodeType != 8))
			var definicion = elEnlace.nextSibling;
		else
			var definicion = elEnlace.nextSibling.nextSibling;
		if ((definicion.className == '')||(definicion.className == 'plegado')) {
			definicion.className = 'desplegado';
		} else {
			definicion.className = 'plegado';
		}

		return false;		
	}
	
}
// aņadido de eventos realizado como en http://simon.incutio.com/archive/2004/05/26/addLoadEvent

function addLoadEvent(fn) {
	var old = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = fn;
	} else {
		window.onload = function() {
			old();
			fn();
		}
	}
}

addLoadEvent(function() {
	MENU.init();
});
