var CurrentID
var ShowingID
   
function Init()
{
	MenuName = 'Item'
	CurrentID = '1'
	ShowingID = '1'
	Down(CurrentID, '')
}

function High(MenuID)
{
	CapStyle=document.getElementById(MenuID).style
	CapStyle.color='#ffff9f'
}

function UnHigh(MenuID)
{
	CapStyle=document.getElementById(MenuID).style
	CapStyle.color='#fff70f'
}

function Down(MenuID)
{
	CapStyle=document.getElementById(MenuID).style
	CapStyle.color='#ffffff'
}

function Up(MenuID)
{
	CapStyle=document.getElementById(MenuID).style
	CapStyle.color='#fff70f'
}

function Click(Btn)
{
	if (Btn != ShowingID)
	{
		NewSubM = document.getElementById(Btn + '-sub')
		if (NewSubM == null)
		{
			Up(ShowingID)
			Down(Btn)
			while (Btn.length < ShowingID.length)
			{
				ShowingID = ShowingID.slice(0, -2)
				UnHigh(ShowingID)
				document.getElementById(ShowingID + '-sub').style.display = 'none'
			}
			if (Btn.search(CurrentID) == -1)
			{
				UnHigh(CurrentID)
				CurSubM = document.getElementById(CurrentID + '-sub')
				if (CurSubM != null)
					CurSubM.style.display = 'none'
			}
			ShowingID = Btn
			CurrentID = Btn
		}
		else
		{
			if (NewSubM.style.display == 'block')
				NewSubM.style.display = 'none'
			else
				NewSubM.style.display = 'block'
			High(Btn)
			if (Btn != CurrentID)
			{
				CurSubM = document.getElementById(CurrentID + '-sub')
				if (CurSubM != null)
				{
					UnHigh(CurrentID)
					CurSubM.style.display = 'none'
				}
				while (Btn.length < CurrentID.length)
				{
					CurrentID = CurrentID.slice(0, -2)
					UnHigh(CurrentID)
					document.getElementById(CurrentID + '-sub').style.display = 'none'
				}
			}
			CurrentID = Btn
		}		
	}
}

function DoRollOver(Btn)
{
	SubM = document.getElementById(Btn + '-sub')
	if (SubM != null)
		SubDown = (SubM.style.display == 'block')
	else
		SubDown = true
	return (((CurrentID.search(Btn) != 0) || ((Btn == CurrentID) && !SubDown)) && (Btn != ShowingID))
}

function RollOn(Btn)
{
	if (DoRollOver(Btn))
		High(Btn)
}

function RollOff(Btn)
{
	if (DoRollOver(Btn))
		UnHigh(Btn)
}

function OpenMenu()
{
}

function SetMenu(NewID)
{
var CurrentPrefix = ''
	if (NewID != CurrentID)
	{
		for (i = 0; i < (CurrentID.length - CurrentID.length % 2) / 2; i++)
			CurrentPrefix = 'sub' + CurrentPrefix
		ParentID = CurrentID.slice(0, -2)
		while ((ParentID != '') && (NewID.search(ParentID) != 0))
		{
			UnHigh(CurrentID, CurrentPrefix)
			SubM = document.getElementById(CurrentID + '-sub')
			if (SubM != null)
				SubM.style.display = 'none'
			else
				Up(CurrentID, CurrentPrefix) 
			CurrentID = ParentID
			ParentID = CurrentID.slice(0, -2)
			CurrentPrefix = CurrentPrefix.slice(3)
		}
		UnHigh(CurrentID, CurrentPrefix)
		SubM = document.getElementById(CurrentID + '-sub')
		if (SubM != null)
			SubM.style.display = 'none'
		if (ParentID == '')
			CurrentID = NewID.slice(0, 1)
		else
			CurrentID = ParentID + NewID.slice(ParentID.length, ParentID.length + 2)
		while (CurrentID != NewID)
		{
			High(CurrentID, CurrentPrefix)
			SubM = document.getElementById(CurrentID + '-sub')
			if (SubM != null)
				SubM.style.display = 'block'
			CurrentPrefix = 'sub' + CurrentPrefix
			ParentID = CurrentID
			CurrentID = ParentID + NewID.slice(ParentID.length, ParentID.length + 2)
		}
		Down(CurrentID, CurrentPrefix)
	}
}
