
 /**
* LI-Menu-Functions
* (c)2005 TIMETOACT Software & Consulting, Cologne, Germany
* author: Michael Gollmick (MGO)
* requires a DOM compatible browser!
*/

var menuwidth="180"; // describes the width of the pulldowns
var generalHoffset=0; // a general horizontal offset for all pulldowns
var inactiveCSSText="";
var activeCSSText="color:#009899;background-color:#ADDFDE;";

if (language != "DE" && language != "EN") {
   activeCSSText="color:#FFFFFF;background-color:#EF574B;";
}

var timetohide=300; // the time for hiding a menu in mili seconds - should only be adjusted when experiencing problems
var loopmax=1000; // safety var for breaking loops if they run wild for whatever reason, only modify if you think loops are really running all this loops and your app is too slow

var openmainmenu=null; // objectstore for function dPD()
var openparent=null; // objectstore for submenus in function dPD()

var timeoutstore=null; // the object that can be killed by clearTimeout()
var timeoutobject=null; // the object that shall be worked with by setTimeout()

function setActiveStyle(style,active){
	if(style){
//		alert("Setting style");
		(active)?style.cssText=activeCSSText+style.cssText:style.cssText=inactiveCSSText;
	}
}

function getULandStyleFromHere(o){
	// returns a style subobject form a links parent LI if available
	if(!o)return null;
	if(!o.parentNode)return null;
	var navroot=o.parentNode.getElementsByTagName("ul");
	if(!navroot.length)return null;
     if(navroot[0].className=="L1")return null;
	if(navroot[0].style)return(navroot[0].style);
	return null;
}

function getLeftPos(o){
	if(!o) return null;
	var leftpos=(getRealOffsetH(o.parentNode)+generalHoffset);
	var minleft=getLeftMostPosition()+generalHoffset;
	var minright=(getRightMostPosition()-menuwidth-generalHoffset);
	if(leftpos<minleft){
		leftpos=minleft;
	}else if(leftpos>minright){
		leftpos=minright;
	}
//alert("minleft: "+minleft+ "\nminright: "+minright+ "\nrealOffset: "+(getRealOffsetH(o.parentNode)+generalHoffset)+ "\ngetLeftMostPosition(): "+getLeftMostPosition()+"\ngetRightMostPosition(): "+getRightMostPosition()+"\nleftpos: "+leftpos);
	return leftpos;
}

function dPD(o){
	// shows the first sublevel and registers the menu in the object storage, so it is called only from the uppermost entries in the whole UL/LI bunch
	// ->ususally var o is only a HTML A, so we have to work with its parentNode if possible, which should be the surrounding LI

	// if there has been a mouseoutevent before, a call to hideSub is in the pipe, we should kill it right now!
	if(timeoutstore){
		window.clearTimeout(timeoutstore);
		timeoutstore=null;
	}

	// if there's another main menu open, we should kill it right now - looks very strange if this two possible menus are open
	// we need to get the current li and have to compare it with the one stored in the objectstore (openmainmenu)
	var thismenu=(o.parentNode); // get the LI to our A tag
	if(thismenu!=openmainmenu){
		// so now we are sure, the current object is another than the one opened
		// we should now hide the other menu without the time lap
		if(openmainmenu)hideSub(openmainmenu.firstChild);
		// now we look for the first UL below ou LI - since getULandStyleFromHere(o) searches for parentNode itself, we need our o var
		var pd=getULandStyleFromHere(o);
		if(pd){
                 // hide the comboboxes for work around IE bug
			sDDv(0);
             		pd.left=getLeftPos(o);
			pd.top=getRealOffsetV(o.parentNode);
         		pd.width=menuwidth;
			pd.display="block";
			setActiveStyle(o.style, true);
	}
		// now set this menu as the active one
		openmainmenu=thismenu;
	}
}

function dPDs(o){
	// like in dPD(o) we get just a HTML A
	window.clearTimeout(timeoutstore);
var thismenu=(o.parentNode); // get the parent object
openparent=thismenu;
if(!isChildOf(thismenu,openmainmenu)){
		hideSub(openmainmenu);
	}
}


function hPD(o){
	// starts to hide the menu as a timed process (which can be killed by other mouseovers)
	timeoutobject=o;
 	 timeoutstore=window.setTimeout("hideSub(timeoutobject);",timetohide);
}

function isChildOf(child, parent){
//sucht, ob ein Object zum gleichen Baum geh&ouml;rt

var cob=child;
var a=0;
	while (cob&&a<loopmax){
		if(cob==parent) return(true);
		cob=cob.parentNode;
	}
	return false;
}

function hideSub(o){
	// this is the real point of hiding a menu
	var pd=null; // the pulldown(=pd)
	var pdp=o; // the pulldowns parent(=pdp)
	if (o){
		pd=getULandStyleFromHere(o);
	}
	if(!pd){
		// we are possibly in a submenu now
		// pd is an A in an LI in an UL in an LI -> we need the UL
		if(o){
			if(o.parentNode){
				pd=getULandStyleFromHere(o.parentNode.parentNode);
				pdp=o.parentNode.parentNode.parentNode.firstChild; //  the a we are redefining is in the first child of the parental LI element
			}
		}
	}
	if(pd){
		pd.display="none";
		openmainmenu=null;
		openparent=null;
		setActiveStyle(pdp.style,false);
                 // show the comboboxes again for work around IE bug
		sDDv(1);
	}else return;
}

function getRealOffsetH(o){
	//tries to determine the real horizontal offset of an element, currently works only for the first sublevel!
	var offset=0;
	var hob=o;
	var a=0;
	while (hob.offsetParent&&(a++)<loopmax){
		offset+=hob.offsetLeft;
		hob=hob.offsetParent;
	}
	return offset;
}

function getRealOffsetV(o){
	//tries to determine the real vertical offset of an element, Konqueror needs this!
	var offset=o.offsetHeight;
	var vob=o;
	var a=0;
	while (vob.offsetParent&&(a++)<loopmax){
//alert( "getRealOffsetV(o): Name: " + vob.tagName + ", top: " + vob.offsetTop + " offset:" + offset );
		offset+=vob.offsetTop;
		vob=vob.offsetParent;
	}
	return offset;
}

	var rightMostPosition=null;
function getRightMostPosition(){
if(!document.getElementById) return null;
var obj=document.getElementById("HLastL1");
	if(obj){
		rightMostPosition=getRealOffsetH(obj)+obj.offsetWidth;
	}
	if(leftMostPosition==null)rightMostPosition=0;
 return rightMostPosition;
}

	var leftMostPosition=null;
function getLeftMostPosition(){
if(!document.getElementById) return null;
	var obj=document.getElementById("HFirstL1");
	if(obj){
		leftMostPosition=getRealOffsetH(obj);
	}
	if(leftMostPosition==null)leftMostPosition=0;
 return leftMostPosition;
}

getLeftMostPosition();

/* end LI-Menu-Functions */

// function sDDv()
// short for: switchDropDownVisibility, this function is only necessary for ie
// This funktion changes the visibility for all the dropdown boxes on a page
// author: DBA
// purpose: Because of a ie bug with dropdown boxes the TopNavigation pulldown menu is displayed behind those dropdown boxes
// last modified: 2004/08/26
// introduced: 2004/08/26
	function sDDv(flag) {
//		if(is.ie) {
			var visMode;
			var formsLength;
			var elementsLength;
			var formObj;
			var elementObj;
			if(flag==0) {
				visMode = "hidden";
			}
			else {
				visMode = "visible";
			}
			formsLength = document.forms.length;
			if(formsLength>0) {
				for(var f = 0; f < formsLength; f++) {
					formObj = document.forms[f];
					elementsLength = formObj.elements.length;
					if(elementsLength>0) {
						for(var e = 0; e < elementsLength; e++) {
							elementObj = formObj.elements[e];
							if(elementObj.type == "select-one") {
								if(elementObj.size == "1" || elementObj.size == "0") {
									elementObj.style.visibility = visMode;
								}
							}
						}
					}
				}
			}
//		}
	}
