/*
external js file for dynamical positioning of the functional navigation
$Source: /usr/cvs/eMB/Clickstream_DCVD/js/popup_nav5.js,v $
$Revision: 1.1 $
Check-In $Date: 2002/10/08 10:14:32 $
*/
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;

var top_distance = 0;
  
function repositionFuncNav() {
	// 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
		if (IE6 && !OP) // 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-eval(top_distance);
		// recognize horizontal scrolling not needed for IE
	}
	else if (NS || DOM)
	{		
		funcNaviNewYPosition= window.innerHeight - funcNavLayer.getHeight() + window.pageYOffset-eval(top_distance);
		// recognize horizontal scrolling
		//if ((!MAC && NS && window.innerWidth < 770) || (!OP && !NS && window.innerWidth < 784)) funcNaviNewYPosition=funcNaviNewYPosition-14-eval(top_distance);
	}
}
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 (MS){
	window.onscroll=handleScroll; // does not work with NS4.x,NS6 and OP
	window.onresize=handleScroll;
}
// Opera resize-Topnavigaton Fix Check (not used by any other browser)
// Opera resize-Topnavigation Fix START
var origW=window.innerWidth; // just for Opera resize check
var origH=window.innerHeight; // just for Opera resize check
var ResizeTimerForOP;	// TimerObject just for Opera resize check
function checkResizeForOpera() {
		clearTimeout( ResizeTimerForOP );
		if (!OP) return true;
		if ( !(window.innerWidth==origW && window.innerHeight==origH)){
			origW=window.innerWidth;
			origH=window.innerHeight;
			//setTimeout("setMenuLayerPositions(); showMenu(activeSubNavName,activeTab);", 200);
			location.reload();
		}
		ResizeTimerForOP = window.setTimeout("checkResizeForOpera()", 350);
		return true;
}
// Opera resize-Topnavigation Fix Check END	
