/*
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 truebody()
    {
        return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }

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;
		}	

		funcNaviNewYPosition = docHeight - funcNavHeight + 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 ) funcNaviNewYPosition=funcNaviNewYPosition-14-eval(top_distance);
		else if ( !OP && !NS && window.innerWidth < 784 ) funcNaviNewYPosition=funcNaviNewYPosition-15-eval(top_distance);
	}
}

document.open(); 

if ( location.href.indexOf('spain') > -1 && ( location.href.indexOf('passenger_cars') > -1 || location.href.indexOf('mpvs') > -1 || location.href.indexOf('camper_vans') > -1) )
{ 
		 document.write ("<script type=\"text/javascript\" src=\"http://www4.mercedes-benz.com/emb/psyma/230_mercedes_es.js\"></script>");
} 
else if ( location.href.indexOf('unitedkingdom') > -1 && ( location.href.indexOf('passenger_cars') > -1 || location.href.indexOf('vans') > -1) )
{
		 document.write ("<script type=\"text/javascript\" src=\"http://www4.mercedes-benz.com/emb/psyma/230_mercedes_uk.js\"></script>");
}
else { 
		 function set_event_handler(){} 
} 



document.close(); 

var funcNaviShowTimer = null;
function handleScroll(nullEv, fNNYP) {
        var scrollLeft = window.scrollMaxX;
        var scrollTop = window.scrollMaxY;
        
        if (isNaN(scrollLeft) || isNaN(scrollTop))
        {
            scrollLeft = truebody().scrollLeft;
            scrollTop = truebody().scrollTop;
        }
        
        var width = truebody().clientWidth + window.scrollMaxX;
        var height = truebody().clientHeight + window.scrollMaxY;
        
        if (isNaN(width) || isNaN(height))
        {
            width = truebody().scrollWidth;
            height = truebody().scrollHeight;
        }

        document.getElementById("nav5").style.top = parseInt(truebody().clientHeight) + scrollTop;
		document.getElementById("nav5").style.position = 'absolute';
}

// 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;
}

