// tree-menu , tymon

function menu_countChildren(index)
{
	if( menuList[index] == NULL )
	{
		alert(1);
		return 0;
	}

	if( menulist[index].length == 2)
	{
		var childlist = menutree
			[ menulist[index][0]*2+1 ]
			[ menulist[index][1]*2+1 ];
		return childlist.length/2;
	}
	if( menulist[index].length == 3)
	{
		var childlist = menutree
			[ menulist[index][0]*2+1 ]
			[ menulist[index][1]*2+1 ]
			[ menulist[index][2]*2+1 ];
		return childlist.length/2;
	}
	return 0;
}

function menu_addChildren(index)
{
	if( menulist[index].length == 2)
	{
		var childlist = menutree
			[ menulist[index][0]*2+1 ]
			[ menulist[index][1]*2+1 ];
		for(var i=0;i<childlist.length/2;i++)
			menu_add( childlist[i*2] );
	}
	
	if( menulist[index].length == 3)
	{
		var childlist = menutree
			[ menulist[index][0]*2+1 ]
			[ menulist[index][1]*2+1 ]
			[ menulist[index][2]*2+1 ];
		for(var i=0;i<childlist.length/2;i++)
			menu_add( childlist[i*2] );
	}
}

function menu_add(index)
{
	var blokje = document.getElementById("menu_item"+index);
	if( blokje != null )
		blokje.style.display="inline";
}


//cascading
function menu_remove(index)
{
	document.getElementById("menu_item"+index).style.display="none";
}


function menu_removeChildren(index)
{
	var childlist;
	if( menulist[index].length == 1)
	{
		childlist = menutree
			[ menulist[index][0]*2+1 ]
	}
	else
	if( menulist[index].length == 2)
	{
		childlist = menutree
			[ menulist[index][0]*2+1 ]
			[ menulist[index][1]*2+1 ];
	}
	else
	if( menulist[index].length == 3)
	{
		childlist = menutree
			[ menulist[index][0]*2+1 ]
			[ menulist[index][1]*2+1 ]
			[ menulist[index][2]*2+1 ];
	}
	else
	{
		//window.status = "menu "+index+" length ="+ menulist[index].length ;
		return;
	}
		
	for(var i=0;i<childlist.length/2;i++)
	{
		menu_remove( childlist[i*2] );
		menu_removeChildren( childlist[i*2] );
	}
	
}

function menu_removeBrothersChildren(index)
{
	if( menulist[index].length == 2)
	{
		var childlist = menutree
			[ menulist[index][0]*2+1 ]
		for(var i=0;i<childlist.length/2;i++)
		{
			if( childlist[i*2] != index )
				menu_removeChildren( childlist[i*2] );
		}
	}
	if( menulist[index].length == 3)
	{
		var childlist = menutree
			[ menulist[index][0]*2+1 ]
			[ menulist[index][1]*2+1 ]
		for(var i=0;i<childlist.length/2;i++)
		{
			if( childlist[i*2] != index )
				menu_removeChildren( childlist[i*2] );
		}
	}
}


function callback_mousehover(focus,menu)
{
	//setTimeOut(

	if(focus)
	{
		//set active style
		document.getElementById("menu_item"+menu).style.color="white";
		document.getElementById("menu_item"+menu).style.backgroundColor="black";

		if(menu<8)
		{
			menu_removeChildren(0);
			menu_add(menu);
		}
		
		menu_removeChildren(menu);
		menu_removeBrothersChildren(menu);
		menu_addChildren(menu);
	}
	else
	{
		//set inactive style
		document.getElementById("menu_item"+menu).style.color="white";
		document.getElementById("menu_item"+menu).style.backgroundColor="gray";
	}

}


function callback_mouseup(index)
{
//if( menu_countChildren(index) == 0)
//		document.getElementById("koe").src= "test.php?page="+index;
	document.location = menuRef[index];
}



