//////////////////////////
// Super menu version 0.002
// desarrollado por Carlo Perez (Buzu)
// http://imbuzu.wordpress.com/
//////////////////////////

		function Desplegable(esqueleto, direccion, contenedor){
			(function(este){
				var cont = contenedor || document.getElementsByTagName('body')[0];
				if((typeof cont).toLowerCase() == 'object'){
					cont.setAttribute('id', 'body');
					cont = 'body';
				}
				
				var esq = esqueleto || null;
				
				if(esq == null){
					alert('Desplegable.error: No hay estructura para mostrar');
					return;
				};
				if((typeof esqueleto).toLowerCase() != 'object'){
					alert('Desplegable.error: el primer parametro debe ser un array con la estructura de tu menu.');
					return;
				}
				
				var dir = direccion || 'vertical';
				if(dir != 'vertical' && dir != 'horizontal'){
					alert('Desplegable.error: Los valores validos para direccion son "vertical" y "horizontal" \n "' + dir + '" No es un valor valido');
					return;
				}
				
				
				var contenedorRef = null;
				if(contenedorRef = document.getElementById(cont)){
					ul = document.createElement('ul');
					ul.className = 'desplegableTop';
					crearListas(esq, ul);
					contenedorRef.appendChild(ul);
				}else{
					alert('Desplegable.error: No se pudo encontrar el elemento '+cont);
				}
				este.aggCSS = function(){
					if(dir == 'vertical'){
						var cabeza = document.getElementsByTagName('head')[0];
						var cssEnlace = document.createElement('link');
						cssEnlace.setAttribute('rel', 'stylesheet');
						cssEnlace.setAttribute('href','vertical.css');
						cabeza.appendChild(cssEnlace);
					}
				}
			})(this)
			
			
			function crearListas(arr, ul){
				for(item in arr){
					if((typeof arr[item]).toLowerCase() == 'string'){
						var cadenas = arr[item].split("->");
						if(cadenas[1]){
							li = document.createElement('li');
							enlace = document.createElement('a');
							enlace.setAttribute('href', cadenas[1]);
							enlace.appendChild(document.createTextNode(cadenas[0]));
							li.appendChild(enlace);
							ul.appendChild(li);
						}
					}else{
						li = document.createElement('li');
						enlace = document.createElement('a');
						enlace.appendChild(document.createTextNode(arr[item][0]));
						li.appendChild(enlace);
						ul2 = document.createElement('ul');
						li.appendChild(ul2);
						ul.appendChild(li);
						crearListas(arr[item], ul2);
					}
				}
			}
		}
		
		
	//*******
function addEvent(obj, evType, func, useCapture){
	if(obj.addEventListener){
		obj.addEventListener(evType, func, useCapture);
		return true;
	}else if(obj.attachEvent){
		var r = obj.attachEvent('on' + evType, func);
		EventCache.add(obj, evType, func)
		return r;
	}else{
		obj['on' + evType] = func;
	}
}


sM = {
	menuRef: null,
	init: function(){
		sM.menuRef.aggCSS();
		var uls = document.getElementsByTagName('ul');
		for(var i=0; i<uls.length; i++){
			if(uls[i].className.search(/\bdesplegableTop\b/) == -1){
				continue;
			}
			var lis = document.getElementsByTagName('li');
			for (var l=0; l<lis.length; l++){
				var node = lis[l];
				if(node.nodeName.toLowerCase() == 'li' && node.getElementsByTagName('ul').length > 0){
					addEvent(node, 'mouseover', sM.getMoverFor(node), false);
					addEvent(node, 'mouseout', sM.getMoutFor(node), false);
					node.getElementsByTagName('a')[0].className += ' subheader';
				}
			}
		}
	},

	mover: function(e, targetElement){
		var el = window.event ? targetElement : e ? e.currentTarget : null;
		if(!el){
			return;
		}
		clearTimeout(el.outTimeout)
		if(!el.isIn){
			for(var i=0; i<el.childNodes.length; i++){
				var node = el.childNodes[i];
				if(node.nodeName.toLowerCase() == 'ul'){
					clearInterval(node.intervalID);
					node.clippingRectangle = [0, 0, 4, 0];
					node.style.clip = 'rect(0 0 0 0)';
					node.style.display = 'block'
					node.savedOH = node.offsetHeight;
					node.savedOW = node.offsetWidth;
					node.style.display = 'none';
					if(document.all && !window.opera){
						el.style.clip = 'rec(auto)';
					}else{
						el.style.clip = '';
					}
					node.intervalID = setInterval(function(){ sM.showMenu(node); }, 10);
					break;
				}
			}
		}
		el.isIn = true;
	},

	mout: function(e, targetElement){
		var el = window.event ? targetElement : e ? e.currentTarget : null;
		if(!el){
			return;
		}
		el.outTimeout = setTimeout(function(){sM.mout2(el);}, 300);
	},
	
	mout2: function(el){
		for(var i=0; i<el.childNodes.length; i++){
			var node = el.childNodes[i];
			if(node.nodeName.toLowerCase() == 'ul'){
				clearInterval(node.intervalID);
				node.intervalID = setInterval(function(){ sM.hideMenu(node); }, 10);
				break;
			}
		}
		el.isIn = false;
	},
	
	getMoverFor: function(node){
		return function(e){
			sM.mover(e, node)
		}
	},
	
	getMoutFor: function(node){
		return function(e){
			sM.mout(e, node)
		}
	},
	
	showMenu: function(el){
		el.clippingRectangle[1] += 20;
		if(el.clippingRectangle[1] >= el.savedOW){
			el.clippingRectangle[1] = el.savedOW;
			el.clippingRectangle[2] += 20;
			if(el.clippingRectangle[2] >= el.savedOH){
				el.clippingRectangle[2] = el.savedOH;
				clearInterval(el.intervalID);
				//reset the clip: browser-specific
				if(document.all && !window.opera){
					el.style.clip = 'rec(auto)';
				}else{
					el.style.clip = "";
				}
				return;
			}
		}
		el.style.clip = 'rect('+el.clippingRectangle.join('px ') + 'px)';
		el.style.display = 'block';
	},
	
	hideMenu: function(el){
		el.clippingRectangle[2] -= 20;
		if(el.clippingRectangle[2] <= 4){
			el.clippingRectangle[2] = 4;
			el.clippingRectangle[1] -= 20;
			if(el.clippingRectangle[1] <= 0){
				clearInterval(el.intervalID);
				//reset the clip: borser-specific
				if(document.all && !window.opera){
					el.style.clip = 'rec(auto)';
				}else{
					el.style.clip = '';
				}
				el.style.display = 'none';
				return;
			}
		}
		el.style.clip = 'rect('+el.clippingRectangle.join('px ') + 'px)';
	}
}	
	//******