/*
 * code for flyout menus
 */


/****************************** flyout menus ***************************/
// global variable for counting down flyout menu time
var menutimeout;

function initmenu()
{
	var xpos, ypos, link, submenu;
	/* grab any flyout divs */
	var flyOutNav = document.getElementsByTagName("div");

	for (var i=0;i<flyOutNav.length;i++) {
		if (flyOutNav[i].className && flyOutNav[i].className.indexOf("FLYOUTNAV") != -1) {
			/* should be the first ul in flyOutNav div */
			var navLinks = flyOutNav[i].getElementsByTagName("ul").item(0);
			/* now get the list of links */
			var linkList = navLinks.getElementsByTagName("li");
			/* find out where the main menu is */
			var menuypos = findPosY(flyOutNav[i]);
			/* now loop through all flyoutnav links and add onmouseovers */
			for (var k=0;k<linkList.length;k++) {
				link = linkList[k];
				/* make sure we only add mouseovers to the main list items 
				not the submenu items */
				if (link.parentNode == navLinks) {
					xpos = findPosX(link);
					// ypos = findPosX(link);
					submenu = link.getElementsByTagName("ul").item(0);
					link.onmouseover=showsubmenu;
					link.onmouseout=hidesubmenu;
					if (submenu) {
						browser = navigator.appName;

						if (browser == "Microsoft Internet Explorer") {
							submenu.style.left = xpos;
							submenu.style.top = menuypos - 20;
						} else {
							submenu.style.left = xpos;
							submenu.style.top = menuypos - 30;
						}

						submenu.style.display="none";
					}

				}
			}
		} // end if FLYOUTNAV
	} // end for div
}

/* make the selected submenu visible */
function showsubmenu(e)
{
  if (menutimeout) {
    window.clearTimeout(menutimeout);
  }
  submenu = this.getElementsByTagName("ul").item(0);
  opensubmenu(submenu);
}

/* make the selected submenu invisible */
function hidesubmenu(e)
{
  if (menutimeout) {
    window.clearTimeout(menutimeout);
  }
  menutimeout = window.setTimeout('closeall()',100);
}

function findPosX(obj)
{
  var curleft = 0;
  var hack=0;
  if (obj.offsetParent) {
//Disabling proper lookup of actual position because the (Select another player)
//link is inside a relative div so you want the position relative to that div
//not relative to the main body.
//now it only gets the first offset
    while ((document.all || curleft == 0) && obj.offsetParent) {
if (document.all && curleft != 0 && !obj.offsetParent.id) {
  //okay this hack is to get around IE, it should set the value twice
// and thats it, man is this ever ugly
  if (hack) {
    break;
  } else {
    hack++;
  }
}
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
   }
  } else if (obj.x) {
    curleft += obj.x;
  }
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  var hack=0;

  if (obj.offsetParent) {
//Disabling proper lookup of actual position because the (Select another player)
//link is inside a relative div so you want the position relative to that div
//not relative to the main body.
//now it only gets the first offset
    while ((document.all || curtop == 0) && obj.offsetParent) {
if (document.all && curtop != 0 && !obj.offsetParent.id) {
  //okay this hack is to get around IE, it should set the value twice
// and thats it, man is this ever ugly
  if (hack) {
    break;
  } else {
    hack++;
  }
}
      curtop += obj.offsetTop;
      obj = obj.offsetParent;
    }
  } else if (obj.y) {
    curtop += obj.y;
  }
  return curtop;
}

function closeall()
{
  /* grab any flyout divs */
  var flyOutNav = document.getElementsByTagName("div");

  for (var i=0;i<flyOutNav.length;i++) {
    if (flyOutNav[i].className &&
        flyOutNav[i].className.indexOf("FLYOUTNAV") != -1) {
      /* we want the first ul in flyout div */
      var navLinks = flyOutNav[i].getElementsByTagName("ul").item(0);
      /* now get the list of links */
      var linkList = navLinks.getElementsByTagName("li");

      for (var k=0;k<linkList.length;k++) {
        link = linkList[k];
        submenu = link.getElementsByTagName("ul").item(0);
        if (submenu) {
          submenu.style.display="none";
        }
      }
    }
  }
}

function opensubmenu(submenu)
{
  if (submenu && submenu.style.display == "none") {
    closeall();
    if (submenu) {
      submenu.style.display="block";
    }
  }
}

function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}

addOnloadEvent(initmenu);


