var hideTimer;

function showsubmenu(element, filename)
{
	killtimer();
	document.getElementById('subMenu').style.display = 'none';
	
	xhr.sendRequest(element, buildnavigation, '/navigation.get.aspx', "file=" + filename, xhr.requestTypes.POST);
	
	//sendRequest("/navigation.get.aspx", "filename=" + filename + "&lang=" + lang, buildnavigation);
}

function buildnavigation(xmlHttpRequest, element)
{
	if (xmlHttpRequest == null)
		return;
	
	if (xmlHttpRequest.status == 0)
		return;
		
	if (xmlHttpRequest.status != 200 && xmlHttpRequest.status != 304)
		alert("AJAX error " + xmlHttpRequest.status);
		
	var data = xmlHttpRequest.responseXML;
	
	if (data && data.getElementsByTagName("Item")[0])
	{
		var subMenu = document.getElementById('subMenu');
		var left = element.parentNode.offsetWidth + 5;
		var top =  0//;element.offsetHeight - element.offsetParent.offsetHeight;
		var parent = element.parentNode;
		
		while (parent)
		{
			if (parent.offsetTop)
				top += parent.offsetTop;
			if (parent.offsetLeft)
				left += parent.offsetLeft;
				
			parent = parent.offsetParent;
		}

		element.onmouseout = new Function("hidesubmenu()");
	
		while (subMenu.firstChild)
			subMenu.removeChild(subMenu.firstChild);
	
		subMenu.style.left = left + 'px';
		subMenu.style.top = top + 'px';

		var childArray = data.getElementsByTagName("Item");

		var height = 0;
		for (var i = 0; i < childArray.length; ++i)
		{
			var child = subMenu.appendChild(document.createElement('p'));
			
			child = subMenu.appendChild(document.createElement(childArray[i].getAttribute("Disabled") == "false" ? 'a' : 'span'));
			child.innerHTML = childArray[i].getAttribute("Title");
			
			if (childArray[i].getAttribute("Href").match(/^http/))
			{
				child.href = childArray[i].getAttribute("Href").replace('{amp}', '&');
				child.target = '_blank';
			}
			else
				child.href = childArray[i].getAttribute("Href");
			
			if (childArray[i].getAttribute("Class"))
				child.className = childArray[i].getAttribute("Class");
				
			height = child.offsetHeight;
		}
						
		subMenu.style.display = 'block';
	}
	else
	{
		
	}
}

function hidesubmenu()
{
	hideTimer = window.setInterval("removesubmenu();", 1000);
}

function removesubmenu()
{
	killtimer();
	document.getElementById('subMenu').style.display = 'none';
}

function killtimer()
{
	if (hideTimer) window.clearTimeout(hideTimer);
	hideTimer = null;
}