// JavaScript Document

function loopElements(el,level)
{
	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")
		{
			//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")
					{
						//Adding click event
						if(temp.href.substr(temp.href.length-1, 1)=="#")
						{
							temp.onclick=showHide
						}
						
					}
					else if(temp.tagName.toLowerCase() == "ul")
					{
						//Hide sublevels
						if(level<2 && temp.className!="show")
						{
							temp.style.display = "none"
						}
						//Recursive - calling it self with the new found element
						//to go all the way through the three.
						loopElements(temp,level +1)
					}
				}
			}
		}
	}
}

		//var menu = document.getElementById("myMenu") //Get menu div
		//menu.className="myMenu"+0 //Set class to the top level
		//loopElements(menu,0) //Call the function

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"
			}
		}
	}
	return false;
}
