var activeMenu = null;

function showCategoryMenu() {
	 if(activeMenu)
	 {
		  activeMenu.className = "collapsed";
		  getNextSiblingByElement(activeMenu).style.display = "none";
	 }
	 if(this == activeMenu)
	 {
		  activeMenu = null;
	 } 
	 else 
	 {
		  this.className = "expanded";
		  getNextSiblingByElement(this).style.display = "block";
		  activeMenu = this;
	 }
	 return false;
}

function initCategoryMenu() {
	 var menus, menu, text, a, i;
	 menus = getChildrenByElement(document.getElementById("category"));
	 for(i = 0; i < menus.length; i++)
	 {
		  menu = menus[i];
		  text = getFirstChildByText(menu);
                  if(!text){ continue; }
		  a = document.createElement("a");
		  menu.replaceChild(a, text);
		  a.appendChild(text);
		  a.href = "#";
		  a.onclick = showCategoryMenu;
                  if(menu.className == 'currentcategory')
                  {
                    a.className = 'expanded';
                    activeMenu = a;
                  }
                  else
                  {
                    a.className = 'collapsed';
                  }
		  a.onfocus = function(){this.blur()};
	 }
}
