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

var menuwidth="195"; // describes the width of the pulldowns
var generalHoffset=-1; // a general horizontal offset for all pulldowns
var inactiveCSSText="";
var activeCSSText="background-color:#9EDFF8; color:#009CD9;";

var timetohide=100; // 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=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("div");
    if(!navroot.length)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;
    //window.status = leftpos;
    if(leftpos > 720) {
        leftpos -= 2;
    }
    //window.status = leftpos;
//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){
        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.parentNode);
                pdp=o.parentNode.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);
    }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("PDNavTDLast");
    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("PDNavTDFirst");
    if(obj){
        leftMostPosition=getRealOffsetH(obj);
    }
    if(leftMostPosition==null)leftMostPosition=0;
 return leftMostPosition;
}

getLeftMostPosition();

/* end LI-Menu-Functions */

