// holds the currently enabled submenu
var oldElement = null;

// This function is used as a workaround for the missing li:hover in IE
// first parameter = (String)id of the outermost <ul>
activateMenu = function(sNav)
{

    // currentStyle restricts the Javascript to IE only
    if (document.all && document.getElementById(sNav).currentStyle) {

        var navroot = document.getElementById(sNav);

        // Get all the list items within the menu
        var lis = navroot.getElementsByTagName('LI');

        for (i=0; i<lis.length; i++) {

			lisSub = lis[i].getElementsByTagName('LI');

            // If the LI has another menu level
            if ((lis[i].className != 'actifsub') && (lis[i].lastChild.tagName == 'UL')) {

                // assign the function to the LI to display the inner (sub) menu
                lis[i].onmouseover = function()
                {
                    if (this.parentNode.parentNode.parentNode.tagName != 'UL') {
	                    hideOldSubMenu();
	                    oldElement = this.lastChild;
	                    this.lastChild.style.display = 'block';
                	}
                }

                // assign the function to the LI to hide the inner (sub) menu
                lis[i].onmouseout = function()
                {
                	var dim = new Dimension(oldElement);
                	//alert(oldElement.outerHTML + ' // x = ' + dim.x + ' / y = ' + dim.y + '/ w = ' + dim.w + ' / h = ' + dim.h);

                	if ((event.clientX < dim.x) || (event.clientX > (dim.x + dim.w)) ||
                	    (event.clientY < dim.y) || (event.clientY > (dim.y + dim.h))) {
                	    this.lastChild.style.display = 'none';
                	}
                }

            }

        }

    }

}


hideOldSubMenu = function()
{
    if (oldElement) {
        oldElement.style.display = 'none';
    }
}


window.onload = function()
{
    activateMenu('navTop');
}


/**
 * get the absolute position and the dimensions of an dom element
 */
function Dimension(element)
{
     this.x = -1;
     this.y = -1;
     this.w =  0;
     this.h =  0;

     if (element == document) {
          this.x = element.body.scrollLeft;
          this.y = element.body.scrollTop;
          this.w = element.body.clientWidth;
          this.h = element.body.clientHeight;
     }

     else if (element != null) {

          var e = element;
          var left = e.offsetLeft;
          while ((e = e.offsetParent) != null) {
               left += e.offsetLeft;
          }

          var e = element;
          var top = e.offsetTop;
          while ((e = e.offsetParent) != null) {
               top += e.offsetTop;
          }

          this.x = left;
          this.y = top;
          this.w = element.offsetWidth;
          this.h = element.offsetHeight;

     }

}
