// JavaScript Document
// <![CDATA[
function loopElements(el,level,aIndexId){
	for(var i=0;i<el.childNodes.length;i++){
		//We only want LI nodes:
		if(el.childNodes[i] && el.childNodes[i]["tagName"] && el.childNodes[i].tagName.toLowerCase() == "li"){
			//Ok we have the LI node - let's give it a className
			if ((i==0) && (level == 1)) {
				el.childNodes[i].className = "menuLineTop myMenu"+level;
			} 
			else {
				el.childNodes[i].className = "myMenu"+level;
			}
			//Let's look for the A and if it has child elements (another UL tag)
			childs = el.childNodes[i].childNodes
			for(var j=0;j<childs.length;j++){
				temp = childs[j]
				if(temp && temp["tagName"]){
					if(temp.tagName.toLowerCase() == "a"){
						//We found the A tag - set class
						temp.className = "myMenu"+level
						//Adding click event
						temp.onclick=showHide;
					}else if(temp.tagName.toLowerCase() == "ul"){
						//Hide sublevels
						if (aIndexId[level+1] != i+1) {
							temp.style.display = "none"
							//alert ("Level: " + level + " con aIndexId[level]: " + aIndexId[level]);
						}
						else {
							temp.style.display = ""
							//alert ("encuentra iguales");
							//alert ("Level: " + level + " ||| i-1: " + (i-1) + " ||| aIndexId[level]: " + aIndexId[level]);
						}
						//Set class
						temp.className= "myMenu"+level
						//Recursive - calling it self with the new found element
						//to go all the way through the three.
						loopElements(temp,level +1,aIndexId) 
					}
				}
			}	
		}
	}
}

function showHide(){
	//We have a A tag - need to go to the LI tag to check for UL tags:
	el = this.parentNode
	//Loop for UL tags:
	for(var i=0;i<el.childNodes.length;i++){
		temp = el.childNodes[i]
		if(temp && temp["tagName"] && temp.tagName.toLowerCase() == "ul"){
			//Check status:
			if(temp.style.display=="none"){
				temp.style.display = ""
			}else{
				temp.style.display = "none"	
			}
		}
	}
 //Returning true if there's a link there. Else returns false so it doesn't go to "#"
	if(this.href!="#"){
		return true
	}else return false 
}
// ]]>