/*
Ersetzt die Datei aus dem GEW-Header mit zusaetzlich definierter Funktion getElementsByClassName.
Letztere ist aus Prototype, welches wegen Konflikt mit JQuery nicht eingesetzt werden darf
kh, 23-09-2008
*/

// 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 = document.getElementsByClassName("topnav active");
    var ActiveSubItems = document.getElementsByClassName("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.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
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;
}

// getElementsByClassName() in prototype.js von GEW darf nicht verwendet werden wegen JQuery-Konflikt,
// deshalb hier nachgebaut
document.getElementsByClassName = function (className,tag,elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
  return returnElements;
}
