function llx3_FloatMenuManager() {
    var MenuManager = this;
    this.Delay = 300;
    this.menus = new Array();
    var checkTimeOut = 0;
    var currentDelay = 1;

    this.AddMenu = function (activator, menu, align) {
        if (activator == activator + '') activator = document.getElementById(activator);
        if (menu == menu + '') menu = document.getElementById(menu);
        var mi = new MenuItem(activator, menu, align);
        MenuManager.menus.push(mi);
        return mi;
    }

    this.CheckMenus = function (delay) {
        if (delay == undefined) delay = MenuManager.Delay;
        if (currentDelay < delay) delay = currentDelay;
        currentDelay = delay;
        clearTimeout(checkTimeOut);
        checkTimeOut = setTimeout(function () {
            for (var i = 0; i < MenuManager.menus.length; i++) {
                if (MenuManager.menus[i].Active) { MenuManager.menus[i].ShowMenu() } else { MenuManager.menus[i].HideMenu() }
            }
            currentDelay = MenuManager.Delay;
        }, delay);
    }


    // <MENU>
    function MenuItem(activator, menu, align) {
        var ChildMenus = new Array();
        var This = this;
        this.ParentMenu = undefined;
        this.align = "bottom"; if (align) this.align = align;
        this.MenuObject = menu;
        this.Active = false;
        menu.style.display = "none";
        menu.style.position = "absolute";
        if (activator.style.position == '') activator.style.position = "relative";
        $(activator).mouseenter(function () { This.Active = true; MenuManager.CheckMenus(1) });
        $(activator).mouseleave(function () { This.Active = false; MenuManager.CheckMenus() });
        $(menu).mouseenter(function () { This.Active = true });
        $(menu).mouseleave(function () { This.Active = false; MenuManager.CheckMenus() });
        var commonParent = getCommonParent();
        var shown = false;

        this.ShowMenu = function () {
            if (shown == true) return true;
            menu.style.display = "block";
            var x = 0; var y = 0;
            var o = menu;
            while (o.parentNode != commonParent) {
                o = o.parentNode;
            }
            if ((This.align == "bottom") || (This.align == "bottom left")) { y += activator.offsetHeight; }
            if (This.align == "bottom center") { y += activator.offsetHeight; x += Math.round((activator.offsetWidth / 2) - (menu.offsetWidth / 2)); }
            if (This.align == "bottom right") { y += activator.offsetHeight; x += (activator.offsetWidt - menu.offsetWidth); }
            if ((This.align == "left") || (This.align == "left top")) { x += activator.offsetWidth; }
            menu.style.left = x + "px";
            menu.style.top = y + "px";
            shown = true;
        }

        this.HideMenu = function () {if(shown == false)return true; menu.style.display = "none"; shown = false; }


        function getCommonParent() {
            var o = menu;
            while (o.parentNode) { o = o.parentNode; if (o == activator) return o }
        }

        this.AddMenu = function (activator, menu, direction) {
            if (activator == activator + '') activator = document.getElementById(activator);
            if (menu == menu + '') menu = document.getElementById(menu);
            var mi = new MenuItem(activator, menu, direction);
            ChildMenus.push(mi);
            mi.ParentMenu = this;
            return mi;
        }


    }
    // </MENU>

}
