﻿// holds the item that
// was originally active
var OriginalNavItem;
var CurrentNavigationTimeout = 0;
var CurrentMousePosX=0;
var CurrentMousePosY=0;
var LastMousePosX=0;
var LastMousePosY=0;
/*
Name: HoverNavigationItem
Param: HTML object with the hovered item 
Desc: this function activates the menu item
      on which the user currently hovers on.
*/
function HoverNavigationItem(thisItem){
    // Fix: the reset to the original menu
    // is usually done when the timeout expires.
    // When the curosr remains on the current item
    // and won't move, the menu is reset, but the
    // current item still remains highlighted as
    // the cursor is still over it.
    thisItem.onmousemove = thisItem.onmouseover;
    if(!IsCursorMoved(CurrentMousePosX,CurrentMousePosY,
                      LastMousePosX,LastMousePosY)){
      // the cursor is still on the last item
      return false; // aborts this function
    }else{
      // sets the new postion as the last one
      LastMousePosX = CurrentMousePosX;
      LastMousePosY = CurrentMousePosY;
    }
    
    // reset the navigation timeout
    if(CurrentNavigationTimeout!=0){
        clearTimeout(CurrentNavigationTimeout);
    }
    // reset the active items first
    var ActiveTopItems = null;
    var ActiveSubItems = null;
    if ( Prototype.Version == "1.4.0" ) {
      ActiveTopItems = document.getElementsByClassName( "topnav active" );
      ActiveSubItems = document.getElementsByClassName( "subnav active" );
    } else {
      var ActiveTopItems = $$(".topnav.active");
      var ActiveSubItems = $$(".subnav.active");
    }
    // verify that it really is an instance and revert it
    if(ActiveTopItems.length>0){
        for(var ati=0; ati<ActiveTopItems.length; ati++){    
            ActiveTopItems[ati].className = "topnav";
        }
    }
    if(ActiveSubItems.length>0){
        for(var asi=0; asi<ActiveSubItems.length; asi++){    
            ActiveSubItems[asi].className = "subnav";
        }
    }
    // now set the active item to be shown
    // with its sub navigation items
    thisItem.className = "subnav active";
    if(document.getElementById(thisItem.id+"-subnav")){
        document.getElementById(thisItem.id+"-subnav")
                    .className = "subnav active";
    }
    // verify if the original menu item
    // is set on this page and then move
    // back to it after a short period
    if(typeof(DefaultActiveNavItem)!="undefined"){
        if(DefaultActiveNavItem.length>0){
            OriginalNavItem = document.getElementById(DefaultActiveNavItem);
            CurrentNavigationTimeout = setTimeout("HoverNavigationItem(OriginalNavItem)",3000);
        }
    }
}
function IsCursorMoved(NewX, NewY, OldX, OldY){
  var Moved = false;
  if((NewX-OldX>10)||(OldX-NewX>10)||
      (NewY-OldY>10)||(OldY-NewY>10)){
    Moved = true;
  }
  return Moved;
}
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + ( document.body != null ? document.body.scrollLeft : 0 );
tempY = event.clientY + ( document.body != null ? document.body.scrollTop : 0 );
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}  
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}  
CurrentMousePosX = tempX;
CurrentMousePosY = tempY;
return true;
}