function combit_menu(id)
{
    if (!document.getElementById || !document.getElementsByTagName)
    {
        return false;
    }
    this.menu               = document.getElementById(id);
    this.submenus           = this.menu.getElementsByTagName("div");
    this.remember           = false;
    this.speed              = 3;
    this.expandFirstOnStart = false;
    this.markCurrent        = true;
    this.expandCurrent      = true;
    this.oneSmOnly          = true;
}
combit_menu.prototype.init = function()
{
    var mainInstance = this;
    // Javascript-CSS-Klasse setzten, damit die Überschrift für
    // Besucher, die Javascript aktivert haben, anders aussieht
    this.menu.className = "javascript";
    for (var i = 0; i < this.submenus.length; i++)
    {
        // Alle Menüs außer das Erste einklappen
        if (i > (this.expandFirstOnStart == true ? 0 : - 1))
        {
            this.submenus[i].className = "collapsed";
        }
        else
        {
            this.submenus[i].className = "";
        }
        // Klick-Event initialiseren
        this.submenus[i].getElementsByTagName("h3")[0].onclick = function()
        {
            mainInstance.toggleMenu(this.parentNode);
        };
        // Internet-Explorer-6 Darstellungsfix für :hover
        this.submenus[i].getElementsByTagName("h3")[0].onmouseover = function()
        {
            if (this.className.length == 0)
            {
                this.className = "hover";
            }
            else
            {
                this.className = "first hover";
            }
        };
        this.submenus[i].getElementsByTagName("h3")[0].onmouseout = function()
        {
            if (this.className.length == 5)
            {
                this.className = "";
            }
            else
            {
                this.className = "first";
            }
        };
        // Fokus-Event initialisieren
        // Wird nur ausgeführt, wenn ein Besucher durch Drücken von TAB
        // in ein Menü gelangt
        this.submenus[i].getElementsByTagName("a")[0].onfocus = function()
        {
            if (this.parentNode.parentNode.parentNode.className == "collapsed")
            {
                mainInstance.toggleMenu(this.parentNode.parentNode.parentNode);
            }
        };
        if (this.markCurrent)
        {
            var links = this.menu.getElementsByTagName("a");
            for (var n = 0; n < links.length; n++)
            {
                if (links[n].href == document.location.href)
                {
                    links[n].parentNode.className = "current";
                    if (this.expandCurrent)
                    {
                        links[n].parentNode.parentNode.parentNode.className = "";
                    }
		            break;
                }
            }
	    }
	    if (this.remember && navigator.appVersion.indexOf("MSIE 5.0") == -1)
        {
        	var count = 0;
            var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)");
            var match = regex.exec(document.cookie);
            if (match)
            {
                var states = match[1].split("");
		        for (var n = 0; n < states.length; n++)
                {
                    count++;
                    this.submenus[n].className = (states[n] == 0 ? "collapsed" : "");
		        }
	        }
            if (count == 0)
            {
                this.submenus[0].className = "";
            }
        }
    }
};
combit_menu.prototype.toggleMenu = function(submenu)
{

    if (submenu.className == "collapsed")
    {
        this.expandMenu(submenu.getElementsByTagName("ul")[0]);
    }
    else
    {
        this.collapseMenu(submenu.getElementsByTagName("ul")[0]);
    }
};
combit_menu.prototype.expandMenu = function(submenu)
{
    var fullHeight = 0;
    var links      = submenu.getElementsByTagName("li");
    for (var i = 0; i < links.length; i++)
    {
        fullHeight += links[i].offsetHeight;
    }
    var moveBy = Math.round(this.speed * links.length);
    var mainInstance = this;
    var intId = setInterval(function()
    {
        var curHeight = submenu.offsetHeight;
        var newHeight = curHeight + moveBy;
        if (newHeight < fullHeight)
        {
            submenu.style.height = newHeight + "px";
        }
        else
        {
            clearInterval(intId);
            submenu.style.height = fullHeight + "px";
            submenu.parentNode.className = "";
            mainInstance.memorize();
        }
    }, 30);
    this.collapseOthers(submenu);
};
combit_menu.prototype.collapseMenu = function(submenu)
{
    var moveBy = Math.round(this.speed * submenu.getElementsByTagName("li").length);
    var mainInstance = this;
    var intId = setInterval(function()
    {
        var curHeight = submenu.offsetHeight;
        var newHeight = curHeight - moveBy;
        if (newHeight > 0)
        {
            submenu.style.height = newHeight + "px";
        }
        else
        {
            clearInterval(intId);
            submenu.style.height = "0px";
            submenu.parentNode.className = "collapsed";
            mainInstance.memorize();
        }
    }, 30);
};
combit_menu.prototype.collapseOthers = function(submenu)
{
    if (this.oneSmOnly)
    {
        for (var i = 0; i < this.submenus.length; i++)
        {
            if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
            {
                this.collapseMenu(this.submenus[i].getElementsByTagName("ul")[0]);
            }
        }
    }
};
combit_menu.prototype.collapseAll = function()
{
    for (var i = 0; i < this.submenus.length; i++)
    {
        if (this.submenus[i].className != "collapsed")
        {
             this.collapseMenu(this.submenus[i].getElementsByTagName("ul")[0]);
        }
    }
};
combit_menu.prototype.expandAll = function()
{
    var oldOneSmOnly = this.oneSmOnly;
    this.oneSmOnly = false;
    for (var i = 0; i < this.submenus.length; i++)
    {
        if (this.submenus[i].className == "collapsed")
        {
            this.expandMenu(this.submenus[i].getElementsByTagName("ul")[0]);
        }
    }
    this.oneSmOnly = oldOneSmOnly;
};
combit_menu.prototype.memorize = function()
{
    if (this.remember)
    {
        var states = new Array();
        for (var i = 0; i < this.submenus.length; i++)
        {
            states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
        }
        var d = new Date();
        d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
        document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
    }
};
