
/* JavaScript for the new DHTML Dropdownmenus on LH Pre-Homepage */

/* init the objects */
var oCd; // content div (with the selectliste)
var oSd; // littel seperator div to hide white border between content div and the anker div 
var oLd; // link div, wrapps the link.
var oNad;// link div next to the current link div
var oSelLst; // the select list in the content div

var timer = 100; // hides the contentdiv after timer-time (in milliseconds)
var sLstEl = "0"; // needed to avoid js errors, when last 'special tabelrow' is missing;
var sLdRpl ="ll_p1_dX"; // find+relpace string for the link div id names.
var sSdRpl ="ll_p1_dX_sep"; // find+relpace string for the seperator div id names.
var sCdRpl ="ll_p2_cX"; // find+relpace string for the content div id names.
var sSelLstRpl = "ll_p2_cX_sel" // find+relpace string for the selectlist id names.

var actClass = "awrp_act"; // css classname for the activ link div 
var inactClass = "awrp"; // css classname for the inactiv link div 
var nextToClass = "awrp_af_act"; // css classname for the link div next to the activ link div

var currentId = "";

// dedect ie and ie 5.01 browser
var ie=false;
var ie5p0=false;

if (navigator.userAgent.toLowerCase().indexOf("msie")>-1)ie=true;
if (navigator.userAgent.toLowerCase().indexOf("msie 5.0")>-1)ie5p0=true;

// Fade out all old divs.
// Set the css-classnames for the link div's to inactiv.
function objFadeOut(fromHide)
{
	if(oCd) {
		oCd.style.visibility="hidden";
		// fix for graphical problem in firefox 
		if (fromHide && oSelLst)oSelLst.blur();
	}
	if(oSd)oSd.style.visibility="hidden";
	if(oLd)oLd.className = inactClass;
	if(oNad)oNad.className = inactClass;
	currentId = "";
}

// Initiate the objects 
function objInit(strId)
{
	// build the id-strings with the given counter (strId)
	sAdId = sLdRpl.replace(/X/,strId);
	sNadId = sLdRpl.replace(/X/,parseInt(strId)+1);
	sSdId = sSdRpl.replace(/X/,strId);
	sCdId = sCdRpl.replace(/X/,strId);
	sSelLstId = sSelLstRpl.replace(/X/,strId);
	// init the objects. Vars for objects are global (see above)
	oLd = document.getElementById(sAdId);
	oNad = document.getElementById(sNadId);
	oSd = document.getElementById(sSdId);
	oCd = document.getElementById(sCdId);
	oSelLst = document.getElementById(sSelLstId);

}

// Shows the divs
function show(e, strId,notFromSel)
{
	// clear delay
	if (typeof delayhide!="undefined")clearTimeout(delayhide);
	// ensure that old visible divs are hidden
	if((currentId!="")&&(currentId!=strId))objFadeOut(true);
	// route event to next dom element
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()

	objInit(strId);
	
	/* makes the divs visible */
	oCd.style.visibility="visible";
	oSd.style.visibility="visible";
	
	/* switch the classes for the "activ" state of the html */
	oLd.className = actClass;
	oNad.className = nextToClass;
	currentId = strId;
}
// Hides the divs
function hide(e, strId)
{
	// route event to next dom element, important here !
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	objInit(strId);
	if(e.toElement) {
		/* if the element which fired the event is not part of the content div the content div must fade out */
		if (!oCd.contains(e.toElement))delayhide=setTimeout("objFadeOut(true)",timer);
	}
	else if (e.currentTarget!= e.relatedTarget&& !contains_ns(e.currentTarget, e.relatedTarget)) {
		/* same as above, but for the gecko based browser */
		delayhide=setTimeout("objFadeOut(true)",timer);
	}
	return false;
}
// Checks if a given element (rt) is part of an other element (ct)
// Used for browser who don't know the '.toElement'-methode.
function contains_ns(ct, rt)
{
	if(rt){
		while (rt.parentNode)
		if ((rt = rt.parentNode) == ct)
		return true;
		return false;
	}
	else return true;
}
// Init the width and position of the dhtml div container on page load.
// Avoids screen flicker in older Gecko-based browser.
function initDivs()
{
		for(j=1;j<=(sLstEl-1);j++) {
			objInit(j);
			// divs are set to display none via css on page load.
			if(oCd) {
				oCd.style.display="block";
				// ie 5.0 don't like this code. No right alignment possible.
				if(!ie5p0){
					oLd.style.height = "auto";
					oLd.style.width = "auto";
					oCd.style.width = "auto";
					/* position the content div and the seperator div */
					/* seperator div has a higher z-index, so div hides the white border */
					oSd.style.top = oLd.offsetHeight+oLd.offsetTop;
					oCd.style.top = oLd.offsetHeight+oLd.offsetTop;
			
					/* sometimes the content div is to long for left alignment below the link */
					/* so we must check this with the last 'special tabelrow' (see HTML) */
					oLm = document.getElementById("ll_p1_d"+sLstEl);
					iLmLeft = oLm.offsetLeft; // left position of the 'special tabelrow'
					/* Next needed for older mozilla engines because of a wrong calculation of the div-width */
					oCd.style.left = 0; 
					//
					if(oCd.offsetWidth+oLd.offsetLeft > iLmLeft)
					{
						/* content div is to long so we make a right alignment below the same link */
						oCd.style.left = iLmLeft-oCd.offsetWidth+parseInt(1);
						/* ...and also for the seperator div to hide the white border */
						oSd.style.width = oLd.offsetWidth;
						oSd.style.left = oLd.offsetLeft+parseInt(1);
						oSd.style.borderRight = "1px solid #fff";
						oSd.style.borderLeft = "none";
					}
					else
					{
						/* content div isn't to long for a left alignment below the link */
						oCd.style.left = oLd.offsetLeft;
					}
				}
				/* sometimes the content div is smaller than the link above the content div */
				/* so we check that and we make the content div wider */
					if(oLd.offsetWidth>oCd.offsetWidth) {
						oCd.style.width=oLd.offsetWidth+1;
						/* ...and because of the different padding/width - behavior of the ie's:  */
						if((!ie)&&(oCd.offsetWidth>oLd.offsetWidth)) oCd.style.width=oLd.offsetWidth-11;
					}
			
				/* sets the width of the seperator div to hide the white border */
				if(!ie)oSd.style.width = oLd.offsetWidth-1;
				else oSd.style.width = oLd.offsetWidth;
			}
	}
}
//