/*
external js file for dynamical positioning of the functional navigation
$Source: /usr/cvs/eMB/Clickstream_DCVD/js/nav5.js,v $
$Revision: 1.1 $
Check-In $Date: 2002/10/08 10:14:32 $
*/

var orgYpos=-1; // holds original y-position of funcnavi
var maxStopperYPosition=-1;
var repositionTimer=null;
var funcNaviNewYPosition;
var funcNavLayer = null;
function repositionFuncNav() {
	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 );
	}
	return true;
}
function setFuncNaviNewYPosition(){
	if(MS || OP) {
		//IE needs an offset of 4 #tbd: test on other platforms
		if (IE6)
		{ 
			// 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;
		}
		
		var docHeight = documentBody.clientHeight;
		var funcNavHeight = funcNavLayer.getHeight();
		if(OP)
		{
			docHeight = window.innerHeight;
			funcNavHeight = document.all[funcNavLayer.id].offsetHeight;
		}	
		
		var dhtml_intToolbarHeight = 0;
		var dhtml_objToolbar = getLayer("CFCToolBarDiv");
		if(dhtml_objToolbar){
			dhtml_intToolbarHeight = dhtml_objToolbar.offsetHeight + 1;
		}
		
		funcNaviNewYPosition = docHeight - funcNavHeight - dhtml_intToolbarHeight + documentBody.scrollTop-eval(top_distance);
		// recognize horizontal scrolling not needed for IE
	}
	else if (NS || DOM)
	{
		var dhtml_intToolbarHeight = 0;
		var dhtml_objToolbar = getLayer("CFCToolBarDiv");
		if(dhtml_objToolbar){
			dhtml_intToolbarHeight = dhtml_objToolbar.offsetHeight + 1;
		}
		
		funcNaviNewYPosition= window.innerHeight - funcNavLayer.getHeight() - dhtml_intToolbarHeight + window.pageYOffset-eval(top_distance);
		// recognize horizontal scrolling
		if ( !MAC && NS && window.innerWidth < 770 ) funcNaviNewYPosition=funcNaviNewYPosition-14-eval(top_distance);
		else if ( !OP && !NS && window.innerWidth < 784 ) funcNaviNewYPosition=funcNaviNewYPosition-15-eval(top_distance);
	}
}

var funcNaviShowTimer = null;
function handleScroll(nullEv, fNNYP) {
	if (funcNavLayer==null) funcNavLayer = new eMBLayer( "nav5" );
	setFuncNaviNewYPosition();
	var go = (funcNaviNewYPosition!=fNNYP);
	if ((MS && !MAC) || go){ 
		clearTimeout(funcNaviShowTimer);	
		funcNavLayer.hide();
		repositionFuncNav();
		if (!MAC) funcNaviShowTimer=setTimeout("funcNavLayer.show()", (MS||NS)?150:350);
		else funcNaviShowTimer=setTimeout("funcNavLayer.show()", 500);
	}
	if (!MS || (MAC && !DOM)){
		repositionTimer = window.setTimeout("handleScroll("+null+","+funcNaviNewYPosition+")",(NS)?60:150);
	}
	else if (MAC && MS){
		repositionTimer = window.setTimeout("handleScroll("+null+","+funcNaviNewYPosition+")",350);
	}
}

// initializing the repositioning of the funcnav layer
if (MS) window.offScreenBuffering=true; // to be tested -> couldn't find detailed explanation
if (MS && !MAC){
	window.onscroll=handleScroll; // does not work with NS4.x,NS6 and OP
	window.onresize=handleScroll;
}
