var mouseY = 0;
var mouseX = 0;

function clientHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

navHover = function() {

	document.getElementById('neededHeightSpacer').style.height="0px";

	var lis = document.getElementById("navmenu").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {

			try
			{
			mouseY = window.event.clientY;
			} catch(e) {}

			this.className+=" iehover";

			var hasSubMenu=false;

			for(var x=0; x < this.children.length; x++)
			{
				if(this.children[x].tagName=="UL")
				{
					hasSubMenu=true;


					var menuHeight = this.children[x].scrollHeight;
					var pageHeight = clientHeight();

					var neededHeight = mouseY + parseInt(menuHeight);

					if(pageHeight < neededHeight)
					{
						var moreHeight=neededHeight-pageHeight;
						if(moreHeight > parseInt(document.getElementById('neededHeightSpacer').style.height))
						{
							document.getElementById('neededHeightSpacer').style.height=parseInt(document.getElementById('neededHeightSpacer').style.height)+(moreHeight+300)+"px";
						//	} else {
						}

					} else {
						var moreHeight = 0;
					}



				}
			};

			if(hasSubMenu==true)
			{
			for(var x=0; x < this.children.length; x++)
			{
				if(this.children[x].tagName=="A")
				{
					this.children[x].href="javascript: void(0);";
				}
			};
			}			
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
	
    //mouse position
    var allEl = document.getElementsByTagName("*");
    for(var x=0; x < allEl.length; x++)
    {
        allEl[x].onmousemove=(function()
        {
                mouseY = window.event.clientY;
	mouseX = window.event.clientX;
        });
    }
}
if (window.attachEvent) window.attachEvent("onload", navHover);
