var Menu;
function initDynamicMenu()
{
	var i;
	Menu = document.getElementById("Menu");
	if(Menu == null) return 0;
	Menu.onmouseout = menuMouseOut;
	Menu.onmouseover = subMenuBlockMouseOver;
	Menu.childItems = new Array();
	for(i=0; i<Menu.childNodes.length; i++)
	{
		if(Menu.childNodes[i].tagName == 'DIV')
		{
		Menu.childItems[Menu.childItems.length] = parseRootMenuItem(Menu.childNodes[i]);
		}
	}
}
function parseRootMenuItem(obj)
{
	var i;
	var itemObj;
	var subItemObj = 0;
	for(i=0; i<obj.childNodes.length; i++)
	{
		if(obj.childNodes[i].tagName == 'A')
		{
			itemObj = obj.childNodes[i];
		}
		if(obj.childNodes[i].tagName == 'DIV')
		{
			subItemObj = obj.childNodes[i];
		}		
	}
	itemObj.onmouseover = test;
	if(itemObj.parentNode.parentNode.className == "Menu")
	{
		if(!subItemObj) 
		{
			itemObj.parentNode.className = "emptyRootItem";
			return itemObj;
		}
		itemObj.parentNode.className = "fullRootItem";
	}
	else
	{
		if(!subItemObj) 
		{
			itemObj.parentNode.className = "emptyItem";
			return itemObj;
		}
		itemObj.parentNode.className = "fullItem";
	}
	itemObj.subMenuBlock = subItemObj;
	itemObj.subMenuBlock.onmouseout = subMenuBlockMouseOut;
	itemObj.subMenuBlock.onmouseover = subMenuBlockMouseOver;
	itemObj.subMenuBlock.childItems = parseSubMenuItem(subItemObj);
	return itemObj;
}

function parseSubMenuItem(obj)
{
	var i;
	var itemObj;
	var subItemObj;
	var itemsArray = new Array;
	if(obj == null) { return 0 }
	for(i=0; i<obj.childNodes.length; i++)
	{
		if(obj.childNodes[i].tagName == 'DIV')
		{
			itemsArray[itemsArray.length] = parseRootMenuItem(obj.childNodes[i]);
		}
	}
	return itemsArray;
}

function test()
{
	closeChildSubItems(this.parentNode.parentNode);
	if(this.subMenuBlock == null) 
	{
		if(this.parentNode.parentNode.className == "Menu")
		{
			this.parentNode.className = "emptyRootItemHover";
		}
		return 0; 
	}
	clearTimeout(this.subMenuBlock.int1);
	if(this.parentNode.parentNode.className == "Menu")
	{
		this.parentNode.className = "fullRootItemHover";
	}
	this.subMenuBlock.style.display = "block";
	this.subMenuBlock.style.borderWidth = "1px";
	pos = findPos(this);
	this.subMenuBlock.style.left = this.parentNode.scrollWidth+0+"px";
	if(this.parentNode.parentNode.className == "Menu")
	{
		this.subMenuBlock.style.top = this.parentNode.offsetTop+"px";
	}
	else
	{
		this.subMenuBlock.style.top = this.parentNode.offsetTop-1+"px";
	}
}
function subMenuBlockMouseOut()
{
	var tempThis;
	tempThis = this;
	this.int1 = setTimeout(function() {closeSubItems(tempThis)},300);
}
function menuMouseOut()
{
	var tempThis;
	tempThis = this;
	
	this.int1 = setTimeout(function() {closeSubItemsRoot(tempThis)},300);
}
function closeSubItems(obj)
{
	if(obj == undefined) return 0;
	obj.style.display = "none";
	obj.style.borderWidth = "0px";
	closeChildSubItems(obj);
}
function closeSubItemsRoot(obj)
{
	closeChildSubItems(obj);
}
function closeChildSubItems(obj)
{
	var i;
	for(i=0; i<obj.childItems.length; i++)
	{
		if(obj.childItems[i]!=0)
		{
			if(obj.childItems[i].parentNode.parentNode.className == "Menu")
			{
				obj.childItems[i].parentNode.className = "fullRootItem";
			}
			closeSubItems(obj.childItems[i].subMenuBlock);
		}
	}
}
function subMenuBlockMouseOver()
{
	clearTimeout(this.int1);
}
function findPos(obj) 
{
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
}