/* **********************************************************
   JavaScript to enable 3-level navigation bar for IE6.
   (c) 2007, dpunkt.verlag
   ********************************************************** */


/* Retrieves an autogenerated, unique identifier for the object. */
var defaultBorderTopColor    = new Array();
var defaultBorderBottomColor = new Array();

activateMenu = function(nav, topColor, bottomColor) {
    var ie6 = document.getElementById && document.all && (navigator.appVersion.indexOf("MSIE 6.") >= 0);

    /* If the is no object with name <nav>, then do nothing. */
    if (ie6 && document.getElementById(nav).currentStyle) {
        var navroot = document.getElementById(nav);

        /* Get all the list items within the menu */
        var lis = navroot.getElementsByTagName("LI");
        for (i = 0; i < lis.length; i++) {

            /* Store preset colors for every link. */
            defaultBorderTopColor[ lis[i].uniqueID ]
                = '"' + lis[i].currentStyle.borderTopColor + '"';
            defaultBorderBottomColor[ lis[i].uniqueID ]
                = '"' + lis[i].currentStyle.borderBottomColor + '"';


            /* The following differentiation between item with (folded/unfolded) submenus
               and items without submenus is necessary because the mouseOver/mouseOut event
               can only be defined once and the display property has to be set or not.
               Most of the code is redundant, though */

            /* If the LI has another, folded menu level
               (an unfolded submenu is marked with id "open"!!) */
            if (lis[i].lastChild.tagName == "UL"  &&  lis[i].id != "open") {
                /* assign the function to the LI */

                /* Mouse-over event */
                lis[i].onmouseover = function() {
                    /* Change color and alignment of triggering anchor */
                    this.style.setExpression("borderTopColor", topColor);
                    this.style.setExpression("borderBottomColor", bottomColor);

                    /* display the inner menu */
                    this.lastChild.style.display = "block";
                }

                /* Mouse-out event */
                lis[i].onmouseout = function() {
                    /* Change color and alignment of triggering anchor */
                    this.style.setExpression("borderTopColor",
                        defaultBorderTopColor[ this.uniqueID ] );
                    this.style.setExpression("borderBottomColor",
                        defaultBorderBottomColor[ this.uniqueID ] );

                    /* hide the inner menu */
                    this.lastChild.style.display = "none";
                }

            /* a) LI without submenu
             * b) LI with unfolded submenu */
            } else if (lis[i].lastChild.tagName == "UL"  &&  lis[i].id == "open") {
                /* Do nothing */

            } else {
                /* Mouse-over event:
                 * Change color and alignment of first anchor in list item */
                lis[i].onmouseover = function() {
                    /* Change color and alignment of triggering anchor */
                    this.style.setExpression("borderTopColor", topColor);
                    this.style.setExpression("borderBottomColor", bottomColor);
                }

                /* Mouse-out event:
                 * Restore and alignment of first anchor in list item */
                lis[i].onmouseout = function() {
                    /* Change color and alignment of triggering anchor */
                    this.style.setExpression("borderTopColor",
                        defaultBorderTopColor[ this.uniqueID ] );
                    this.style.setExpression("borderBottomColor",
                        defaultBorderBottomColor[ this.uniqueID ] );
                }
            }
        } // end loop over all list items
    } // end IE detection
} // end function
