/*
external js file for dynamical positioning of the functional navigation

$Source: /usr/cvs/eMB/Clickstream/js/nav5.js,v $
$Revision: 1.1 $
Check-In $Date: 2002/06/27 17:03:01 $
*/
var eventCounter=0; // just for testing purposes
var orgYpos=-1; // holds original y-position of funcnavi
var maxStopperYPosition=-1;
var repositionTimer=null;
var funcNaviNewYPosition;
var funcNavLayer = null;
var DEBUG = false;

function repositionFuncNav() {
  eventCounter++; // just for testing purposes

  var thisYposStopper=0;
  var i=1;
  if (maxStopperYPosition<0){
    while(thisYposStopper>-1) {
      var currentLayer = new eMBLayer("stopper"+i);
      thisYposStopper = currentLayer.getAbsoluteY();
      if(thisYposStopper>maxStopperYPosition) maxStopperYPosition=thisYposStopper;
      i++;
    }
    maxStopperYPosition+=3;
  }
  //window.status=kalle+","+maxStopperYPosition ;
  
  if (funcNaviNewYPosition < maxStopperYPosition) funcNaviNewYPosition = maxStopperYPosition; 
  // just reposition if scrollposition has changed
  if (orgYpos != funcNaviNewYPosition) {
    orgYpos = funcNaviNewYPosition;
    clearTimeout(repositionTimer);
    if (!NS) repositionTimer = setTimeout("funcNavLayer.setY("+funcNaviNewYPosition+")", 30);
    else funcNavLayer.setY( funcNaviNewYPosition );
  } 
}

function setFuncNaviNewYPosition(){
  if(MS || OP) {
    //IE needs an offset of 4 #tbd: test on other platforms
    // FIXME
    if (IE6 && false) // document.body.scrollTop no longer supported in IE6 (now scrollTop is part of html-object)
      var documentBody = document.getElementsByTagName("html")[0];
    else
      var documentBody = document.body;
    funcNaviNewYPosition = documentBody.clientHeight - funcNavLayer.getHeight() + documentBody.scrollTop;
    // recognize horizontal scrolling not needed for IE
  }
  else if (NS || DOM)
  {    
    funcNaviNewYPosition= window.innerHeight - funcNavLayer.getHeight() + window.pageYOffset;
    // recognize horizontal scrolling
    if ((!MAC && NS && window.innerWidth < 770) || (!OP && !NS && window.innerWidth < 784)) funcNaviNewYPosition=funcNaviNewYPosition-14;
  }

  if (MAC){
    if (NS); // ns4.x mac, no correction needed
    else if (MS && !DOM) ; // ie45 mac
  }
}

var funcNaviShowTimer = null;

function handleScroll(nullEv, fNNYP) {
  if (funcNavLayer==null) funcNavLayer = new eMBLayer( "nav5" );
  setFuncNaviNewYPosition();
  var go = (funcNaviNewYPosition!=fNNYP);

  if (MS || go){ 
    clearTimeout(funcNaviShowTimer);  
    if (MAC && MS) { // avoid rendering-errors on Mac IE5
      setTimeout("funcNavLayer.hide()", 1);
      setTimeout("repositionFuncNav()", 1);
    }
    else{
      funcNavLayer.hide();
      repositionFuncNav();
    }
    funcNaviShowTimer=setTimeout("funcNavLayer.show()", ((MS||NS)&&!MAC)?150:350);
  }
  if (!MS || (MAC && !DOM))
    repositionTimer = window.setTimeout("handleScroll("+null+","+funcNaviNewYPosition+")",(NS)?60:150);
  if (DEBUG){
    window.status = " " + window.status;
    if (window.status.length>150) window.status = funcNavLayer.isObject();
  }

}
// initializing the repositioning of the funcnav layer
if (MS) window.offScreenBuffering=true; // to be tested -> couldn't find detailed explanation
window.onload=handleScroll;
if (NS && false){ // don't start handleScroll here AND in the body tag!!
  document.captureEvents(Event.LOAD);
  document.onload=handleScroll;
}
if (MS){
  window.onscroll=handleScroll; // does not work with NS4.x,NS6 and OP
  window.onresize=handleScroll;
}
