//*** Declare constants ***
var MENUSPEED = 35;

//*** Mainmenu colors. ***
var MM_NORMAL  = "#000000";
var MM_HOVER   = "#E44633";

//*** Submenu colors. ***
var SM_NORMAL  = "#000000";
var SM_HOVER   = "#E44633";
var SM_VISITED = "#6EC227";

var activeMenu    = null;
var activeSubmenu = null;
var collSubmenu   = null;


function MenuClick(menu)
{
	var prevMenu = activeMenu;
	
	//*** Set new active menu.
	activeMenu = (menu == activeMenu) ? null : menu;
	
  if (smItems(prevMenu))
	{
		//*** Collapse previous menu (start with first item).
		mmCollapse(1);
  }
  else if (smItems(activeMenu))
  {
  	//*** Expand current menu (start with last item).
    mmExpand(collSubmenu.length - 1);
  }
}


function mmCollapse(curIndex)
{
	//*** Set submenu item status (hide/show).
	if (collSubmenu[curIndex]) collSubmenu[curIndex].style.display = "none";
	
	if (curIndex < (collSubmenu.length - 1))
	{
		//*** Goto next item.
		setTimeout("mmCollapse(" + (curIndex + 1) + ")", MENUSPEED);
	}
	else if (smItems(activeMenu))
  {
  	//*** Expand current menu (start with last item).
    mmExpand(collSubmenu.length - 1);
  }
}


function mmExpand(curIndex)
{
	//*** Set submenu item status (hide/show).
	if (collSubmenu[curIndex]) collSubmenu[curIndex].style.display = "block";
	
	if (curIndex > 1)
	{
		//*** Goto previous item.
		setTimeout("mmExpand(" + (curIndex - 1) + ")", MENUSPEED);
	}
}


function MenuHover(menu, status)
{
  var color = ((status == 1) ? MM_HOVER : MM_NORMAL);
  
  menu.style.borderColor = color;
  menu.style.color       = color;
}


function ItemClick(submenu)
{
	if (activeSubmenu != null && activeSubmenu != submenu)
	{
		//*** Reset last selected item.
		activeSubmenu.style.color = SM_NORMAL;
	}
	
	//*** Remind this submenu as selected.
	submenu.style.color = SM_VISITED;
	activeSubmenu       = submenu;
}


function smItems(menu)
{
	if (menu != null)
	{
		//*** Get submenu collection.
		collSubmenu = menu.parentNode.getElementsByTagName("DIV");
		
		return true;
	}
	
	return false;
}


function ItemHover(submenu, status)
{
  //*** Don't take any action if the menu is active.
  if (submenu == activeSubmenu) return;
  
  //*** Set item properties based on status.
  submenu.style.color = ((status == 1) ? SM_HOVER : SM_NORMAL);
}
