var hoverparent=null;

function getparent(item)
{
	if (hoverParent)
	{
		for (i=0; i<hoverParent.childNodes.length; i++)
		{
			for (j=0; j<hoverParent.childNodes[i].childNodes.length; j++)
			{
				if (hoverParent.childNodes[i].childNodes[j]==item)
				{
					return hoverParent.childNodes[i];
				}
			}
		}
	}
	return null;
}

function simulate_hover(idname)
{
	var hoverParent = document.getElementById(idname);
	if (hoverParent)
	{
		for (i=0; i<hoverParent.childNodes.length; i++)
		{
			currentNode = hoverParent.childNodes[i];
			currentNode.hoveradd=0;
			currentNode.hoversub=0;
			currentNode.lockhovername="node"+i;

			currentNode.onmouseover = function ()
			{
				if (this.className.indexOf("hover")==-1)
				{
					this.className += " hover";
				}
				if (this.childNodes.length==2)
				{
					// first is heading, second is submenu
					if (this.childNodes[1].onmouseover!=null)
					{
					
						this.childNodes[1].onmouseover=function()
						{
							var i=getparent(this);
//							alert('add to '+i.lockhovername+'='+i.hoveradd+','+i.hoversub);
							if (i != null)
							i.hoveradd++;
						}
						this.childNodes[1].onmouseout=function()
						{
							var i=getparent(this);
//							alert('sub from '+i.lockhovername+'='+i.hoveradd+','+i.hoversub);
							if (i != null)
								i.hoversub++;
						}
					}

				}
			}

			currentNode.onmouseout = function ()
			{
				if ((this.hoveradd - this.hoversub)<=0)
 				{
					this.hoveradd=0;
					this.hoversub=0;
					this.className=this.className.replace(" hover", "");
					if (this.className=="hover")
					{
						this.className="";
					}
					if (this.childNodes.length==2)
					{
						if (this.childNodes[1].onmouseover!=null)
						{
							this.childNodes[1].onmouseover=function(){};
							this.childNodes[1].onmouseout=function(){};
						}
					}
				}
			}
		}
	}
}

function simulatehover(idname)
{
	simulate_hover(idname);
}
