var delay1Dur= 80;    // delay1 after movein   - you can modify here - not less then 50 ms
var delay2Dur= 250;   // delay2 after mouseout - you can modify here - not less then 50 ms
var navMax   = 4; 		// how many menues?
var navMinX  = 246;		// min x submenu position
var navMaxX  = 648;		// max x submenu postion

var aktiv    = true;  // helps mac-nc4 to deal with clearTimeout
var delay1   = null;  // timeout-handle1
var delay2   = null;  // timeout-handle2
var elM      = false; // flag - keeps open submenue

// initialize menue
// register mouseout and mousemove events
function startNavi () {
	// loop through all navi-divs until navMax
	// keep it simpel: use the same names an add "i"
	for(var i = 0; i < navMax; i++) {
		if(nc){
			dRef('drop' + i).captureEvents(Event.MOUSEOUT | Event.MOUSEMOVE);
			dRef('main' + i).captureEvents(Event.MOUSEOUT);
		}
		dRef('drop' + i).onmouseout  =  initHiding;
		dRef('drop' + i).onmousemove =  checkHiding;
		dRef('main' + i).onmouseout =  initHiding;
	}
}

// called when mouseout over div-layer was fired
// starting hiding-process of a submenue
function initHiding (e) {
	// in case of very slow mousemoves nc4 does not notice mousemove within the delay2
	// loop throught all links of the layer to make shure not a link is the target
	if (nc && typeof document.layers[elM] != "undefined") {
		for (var i = 0; i < dRef(elM).document.links.length; i++) {
			if (e.target == dRef(elM).document.links[i]) return;
		}
	}	
	elPast = elM
	if(aktiv) {
		// call off - but wait for a time an check for mousemoves
		clearTimeout(delay1);
		delay2 =  setTimeout('off()', delay2Dur);
		aktiv =  false;
	}
}

// called when mousemove over div-layer was fired
// clearing the hiding-process in case of mousemove within the div-layer
function checkHiding (e) {
	elM =  this.id;     
	if(!aktiv) {
		// stop hiding
		clearTimeout(delay2);
		aktiv = true;
	}
}

// hide dropmenue
function off (){
	if(elPast) dRefS(elPast).visibility = "hidden";
	elementMoveX("he-suche",270);
}

// open dropmenue
function on(num){
	if (top.document.getElementById('tr' + num)) {
		var x = (getAnchorPosition('tr' + num)).x - 2;
		if ( x < navMinX ) { x = navMinX; }
		if ( x > navMaxX ) { x = navMaxX; }
		top.document.getElementById('drop' + num).style.left = x + 'px';
	}
	
	if(!aktiv) {
		clearTimeout(delay2);
		aktiv =  true;
		delay1 =  setTimeout('showMenu(' +  num + ')', delay1Dur);
	}
	else { 
		showMenu(num); 
	}
}


function showMenu(num)
{
	if(elM && elM != "drop" + num) dRefS(elM).visibility =  "hidden";
	dRefS("drop" + num).visibility =  "visible";
	elM = "drop" + num;
	elementMoveX("he-suche", num ? 270 : -500);
}

// some known objects
var nc   =  !!(document.captureEvents  && !document.getElementById);
var nc6  =  !!(document.captureEvents  && document.documentElement);
var op6  =  !!(document.getElementById && !document.documentElement);
var op7  =  !!(window.opera && /Opera( |\/)7/i.exec(navigator.userAgent));
var ie   =  !!document.all;
var ie4  =  !!(document.all           && !document.documentElement);
var ie5  =  !!(document.all           && document.documentElement);
var dom  =  !!document.getElementById;
var mac  =  !!(navigator.userAgent.indexOf("Mac")!=-1);

// div-layer referenzieren
function dRef(num)   {return (nc? document.layers[num]   : (ie4? document.all[num]       : document.getElementById(num)))}
function dRefS(num)  {return (nc? document.layers[num]   : (ie4? document.all[num].style : document.getElementById(num).style))}

// move x element
function elementMoveX(id, x){document.getElementById(id).style.left=x;}
