// Org (C) 2002 Tangora Software A/S

Array.prototype.isArray = true;
Object.prototype.isMenu = false;
Object.prototype.submenu = null;
Object.prototype.imageItem = null;
//

// Enable extra height at bottom for jsnav2 
var navPaddingBottom = (typeof(TS_PaddingBottom) == "undefined") ? 0 : TS_PaddingBottom;
// Enable changing the css-class of the main element
var navMenuItemPrefix = (typeof(TS_MenuItemPrefix) == "undefined") ? "" : TS_MenuItemPrefix;
var navMenuItemSuffix = (typeof(TS_MenuItemSuffix) == "undefined") ? "" : TS_MenuItemSuffix;
var navClassName = (typeof(TS_ClassName) == "undefined") ? "jsnav2" : TS_ClassName;
var navClassNameActive = (typeof(TS_ClassNameActive) == "undefined") ? "jsnav2" : TS_ClassNameActive;

TS_JSTimeout = 500;

function TJSMenu() {

    this.SeparatorSize = TS_SeparatorSize;
    this.SeparatorColor = TS_SeparatorColor;
    this.BGColor = TS_BGColor;
    this.BGColorOver = TS_BGColorOver;
    this.ItemPadding = TS_ItemPadding;
    this.BorderWidth = TS_BorderWidth;
    this.BorderColor = TS_BorderColor;
    this.ImageSrcOver = TS_ImageSrcActive
    this.ImageSrc = TS_ImageSrcInactive;
    this.ChildOverlap = TS_ChildOverlap;
    this.ChildOffset = TS_ChildOffset;
    this.ImageSize = TS_ImageSize;
    this.ImageHorizSpace = TS_ImageHorizSpace;
    this.ImageVertSpace = TS_ImageVertSpace;
    this.useClickOpen = (typeof(TS_useClickOpen) == "undefined") ? false : TS_useClickOpen;
    this.TS_Safari = (navigator.userAgent.indexOf("Safari") != -1);

    this.tsArrayPrefix = "tsmenu";
    this.MenuIdArray = new Array;
    this.CurrentActiveMenu = null;
    this.CurrentActiveSubMenu = null;
    this.UserOverMenu = false;
    this.UserOverSubMenu = false;
    this.curRule = null;
    this.curRule1 = null;
    this.curRule2 = null;
    this.curRule1text = "";
    this.curRule2text = "";
    this.curImage = null;
    this.SubMenuObject = null;

    this.itemHeight = 20;
    this.isOpen = false;
    this.isExplicitClose = false;

    this.TSHideMenuEvent = null;
    this.TSHideMenuEventElemid = null;

    this.YPOP = TS_YPOP;
    if (typeof (TS_XPOP) == "undefined") {
        this.XPOP = 0;
    } else {
        this.XPOP = TS_XPOP;
    }
    this.TS_YOFFSET = 0;

    this.init = function () {
        if (!window.BuildListArray) {
            BuildListArray = [];
            for (i = 1; i < 100; i++) {
                if (this.IsValidArray(this.tsArrayPrefix + i + "properties")) {
                    if (window[this.tsArrayPrefix + i + "properties"].length > 0) {
                        BuildListArray[BuildListArray.length] = i;
                    }
                }
            }
        }
        if (TS_IE && !TS_Mac && !TS_Opera) {
            if (window.document.styleSheets.length) {
                var css = window.document.styleSheets.item(0);
                if (css.rules) {
                    str = css.rules.length;
                    for (var i = 0; i < css.rules.length; i++) {
                        str += css.rules.item(i).selectorText + ", ";
                        if (css.rules.item(i).selectorText == ".jsnav2") {
                            this.curRule1 = css.rules.item(i);
                            this.curRule1text = this.curRule1.style.filter;
                        }
                        if (css.rules.item(i).selectorText == ".jsnav3") {
                            this.curRule2 = css.rules.item(i);
                            this.curRule2text = this.curRule2.style.filter;
                        }
                    }
                }
            }
        }
    }

    this.loadMenu = function () {
        if (typeof (ts_init) == "undefined") {
            tsinit()
        } else {
            ts_init()
        }
        ;
        this.MakeTrees();
        if (!TS_IE && !TS_Mac) {
            if (window.document.styleSheets.length) {
                var css = window.document.styleSheets.item(0);
                if (css && css.rules) {
                    str = css.rules.length;
                    for (var i = 0; i < css.rules.length; i++) {
                        str += css.rules.item(i).selectorText + ", ";
                        if (css.rules.item(i).selectorText == ".jsnav2") {
                            css.rules.item(i).style.filter = "";
                        }
                        if (css.rules.item(i).selectorText == ".jsnav3") {
                            css.rules.item(i).style.filter = "";
                        }
                    }
                }
            }
        }
        if (typeof(jsnavLoad) == "function") {
            jsnavLoad();
        }
        if (typeof (needToPop) != "undefined") {
            TS_PopUp(needToPop, null)
        }
        if (Tangora.Browser.Opera && parseFloat(Tangora.Browser.Version) < 9) {
            this.TS_YOFFSET = this.fullOffsetV(document.getElementById("bodytable"));
        }
        if (tsLoadMenusRetryFunc) {
            tsLoadMenusRetryFunc();
        }
    }

    this.MakeTrees = function () {
        tree = new Array();
        for (var i = 0; i < BuildListArray.length; i++) {
            MenuObject = this.makeMenu(BuildListArray[i]);
            if (MenuObject) {
                MenuObject.onmouseover = this.KeepMenuAlive;
                MenuObject.arrIndex = i;
                document.body.appendChild(MenuObject);
            }
        }
    }

    this.makeMenu = function (index) {
        var props = window[this.tsArrayPrefix + index + "properties"];
        if (props) {
            MenuObject = document.createElement("div");
            with (MenuObject) {
                id = "elMenu" + props[0];
                className = "jsnav2";
                MenuObject.isMenu = true;
                with (style) {
                    backgroundColor = TS_BGColor;
                    position = "absolute";
                    visibility = "hidden";
                    left = "-500px";
                    top = "0px";
                    width = props[1] + "px";
                    if ((this.BorderWidth > 0) && (this.BorderColor != "")) border = this.BorderWidth + "px solid " + this.BorderColor;
                    overflow = "hidden";
                    zIndex = 100;
                }
                var itemArr = window[this.tsArrayPrefix + index + "items"];
                for (var j = 0; j < itemArr.length; j++) {
                    for (var rpvar = 0; rpvar < 6; rpvar++) {
                        var str = new String(itemArr[j]);
                        itemArr[j] = str.replace('_aa_', '"');
                    }
                    itemArr[j] = itemArr[j].split(",");
                    for (var jj = 0; jj < itemArr[j].length; jj++) {
                        compatStr = new String(itemArr[j][jj]);
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        compatStr = compatStr.replace("¤a¤", ",");
                        itemArr[j][jj] = compatStr.replace("¤a¤", ",");
                    }
                    this.CreateMenuElement(MenuObject, itemArr[j], index, j + 1, "", j == (itemArr.length - 1));
                }
            }
            return MenuObject;
        } else {
            return null;
        }
    }

    this.makeSubMenu = function (index) {
        this.SubMenuObject = document.createElement("div");
        with (this.SubMenuObject) {
            id = "elMenu" + window[this.tsArrayPrefix + index + "properties"][0];
            className = "jsnav3";
            MenuObject.isMenu = true;
            with (style) {
                backgroundColor = TS_BGColor;
                position = "absolute";
                visibility = "hidden";
                left = "-500px";
                top = "0px";
                width = window[this.tsArrayPrefix + index + "properties"][1] + "px";
                if ((this.BorderWidth > 0) && (this.BorderColor != "")) border = this.BorderWidth + "px solid " + this.BorderColor;
                overflow = "hidden";
                zIndex = 100;
            }
            var itemArr = window[this.tsArrayPrefix + index + "items"];
            for (var j = 0; j < itemArr.length; j++) {
                for (var rpvar = 0; rpvar < 6; rpvar++) {
                    var str = new String(itemArr[j]);
                    itemArr[j] = str.replace('_aa_', '"');
                }
                itemArr[j] = itemArr[j].split(",");
                for (var jj = 0; jj < itemArr[j].length; jj++) {
                    compatStr = new String(itemArr[j][jj]);
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    compatStr = compatStr.replace("¤a¤", ",");
                    itemArr[j][jj] = compatStr.replace("¤a¤", ",");
                }
                this.CreateMenuElement(this.SubMenuObject, itemArr[j], index, j + 1, "sub", j == (itemArr.length - 1));
            }
        }
        this.SubMenuObject.onmouseover = this.KeepSubMenuAlive;
        return this.SubMenuObject;
    }

    this.CreateMenuElement = function (parent, arr, parentindex, itemindex, issub, islast) {
        var menuElement;
        menuElement = document.createElement("div")
        with (menuElement) {
            id = parentindex + "_" + itemindex;
            if (arr[5]) {
                // Add unique ID for this element (necessary in order to use RemoveMenuElement)
                this.MenuIdArray[arr[5]] = id;
            }

            // New try
            if (typeof(supressParentPages) != "undefined") {
                if (supressParentPages) {
                    if (arr[4] == 1) {
                        var str = arr[0];
                        str = str.replace("href=", "onClick='return false' href=").replace("<a ", "<A ").replace("</a>", "</A>").replace("<A ", "<span ").replace("</A>", "</span>");
                        arr[0] = str;
                    }
                }
            }

            innerHTML = "<div style='width:" + (parseInt(window[this.tsArrayPrefix + parentindex + "properties"][1]) - this.ItemPadding * 2) + "px;'>" + arr[0] + "</div>";

            menuElement.name = issub;
            with (style) {
                backgroundColor = TS_BGColor;
                if (!islast) borderBottom = this.SeparatorSize + "px solid " + this.SeparatorColor;
                var FullPadding = this.ItemPadding;
                paddingLeft = FullPadding + "px";
                paddingTop = FullPadding + "px";
                if (TS_IE && !(/Opera\/9/.test(navigator.userAgent))) paddingBottom = FullPadding + "px";
                width = window[this.tsArrayPrefix + parentindex + "properties"][1] + "px";
                //if (/Mozilla\/5\.0/.test(navigator.userAgent) || /Opera\/9/.test(navigator.userAgent)) {} else {height = this.itemHeight + "px"}
                zIndex = 100;
            }
            isMenu = true;
            menuElement.onmouseover = this.ItemOver;
            menuElement.onmouseout = this.ItemOut;
            if (arr[4] == 1) {
                if (this.ImageSize != 0 && this.IsValidImagePath(this.ImageSrc)) {
                    var imageElement;
                    imageElement = document.createElement("IMG")
                    with (imageElement) {
                        src = this.ImageSrc;
                        hspace = 0;
                        vspace = 0;
                        with (style) {
                            position = "absolute";
                            marginTop = this.ImageVertSpace;
                            width = this.ImageSize + "px";
                            if (TS_RightToLeft == 1) {
                                menuElement.firstChild.style.width = (parseInt(menuElement.firstChild.style.width) - this.ImageSize) + "px"
                                menuElement.firstChild.style.marginLeft = parseInt(width) + this.ImageHorizSpace;
                                left = (this.ItemPadding + this.ImageHorizSpace) + "px";
                                if (menuElement.firstChild.style.styleFloat) menuElement.firstChild.style.styleFloat = "right";
                                else {
                                    if (menuElement.firstChild.style.cssText) menuElement.firstChild.style.cssText += "; float:right";
                                }
                            } else {
                                menuElement.firstChild.style.width = (parseInt(menuElement.firstChild.style.width) - this.ImageSize) + "px"
                                left = window[this.tsArrayPrefix + parentindex + "properties"][1] - this.ItemPadding - this.ImageHorizSpace - this.ImageSize + "px";
                                //if (menuElement.firstChild.style.styleFloat) menuElement.firstChild.style.styleFloat="left";
                                //else {
                                //	if (menuElement.firstChild.style.cssText) menuElement.firstChild.style.cssText+="; float:left";
                                //}
                            }
                            if (typeof (styleFloat) != "undefined") styleFloat = "right";
                            else {
                                if (cssText) cssText += "; float:right";
                            }
                        }
                        imageElement.onmouseover = this.doActivate;
                        imageElement.onmouseout = this.doDeactivate;
                    }
                    //alert (menuElement.firstChild.firstChild.nextSibling);
                    menuElement.insertBefore(imageElement, menuElement.firstChild);
                    menuElement.imageItem = imageElement;
                }
                var submenu = this.makeSubMenu(parentindex + "_" + itemindex);
                submenu = this.SubMenuObject;
                submenu.parent = parent;
                submenu.parentE = menuElement;
                window.document.body.appendChild(submenu);
            }
        }
        parent.appendChild(menuElement);
    }

    this.IsValidImagePath = function (s) {
        if (s.toLowerCase().indexOf('.jpg') != -1 || s.toLowerCase().indexOf('.gif') != -1 || s.toLowerCase().indexOf('.png') != -1) return true;
        else return false;
    }

    this.IsValidArray = function (arrayname) {
        var MenuArrayIsValid = false;
        var MenuArrayIsObject = (typeof(window[arrayname]) == "object");
        if (MenuArrayIsObject) {
            var TheMenuArray = window[arrayname];
            if (TheMenuArray.isArray && TheMenuArray.length > 1) {
                MenuArrayIsValid = true;
            }
        }

        return MenuArrayIsValid;
    }

    this.displayEffect = function (sI, eI) {
        if (this.CurrentActiveMenu) {
            sI += 5;
            if (sI < eI) {
                this.CurrentActiveMenu.style.height = sI + "px";
                window.setTimeout("jsmenu.displayEffect(" + sI + "," + eI + ")", 50);
            } else {
                this.CurrentActiveMenu.style.height = eI + "px";
            }
        }
    }

    this.fadeIt = function (lv, mv) {
        if (TS_IE && !TS_Mac) {
            if (this.curRule) {
                factor = (TS_FadingEndValue - TS_FadingStartValue) / TS_FadingSteps;
                lv += factor;
                if (lv > mv) {
                    lv = mv;
                    this.curRule.style.filter = "alpha (opacity=" + lv + ")";
                    window.clearTimeout;
                    if (this.curRule == this.curRule1) {
                        this.curRule.style.filter = this.curRule1text;
                    } else {
                        this.curRule.style.filter = this.curRule2text;
                    }
                } else {
                    this.curRule.style.filter = "alpha (opacity=" + lv + ")";
                    window.setTimeout("jsmenu.fadeIt(" + lv + "," + mv + ")", 1);
                }
            }
        }
    }

    this.KeepInWindow = function (MenuObject, menutype) {
        var ExtraSpace = 10;
        var WindowLeftEdge = (TS_IE) ? document.body.scrollLeft : window.pageXOffset;
        var WindowTopEdge = (TS_IE) ? document.body.scrollTop : window.pageYOffset;
        var WindowWidth = (TS_IE) ? document.body.clientWidth : window.innerWidth;
        var WindowHeight = (TS_IE) ? document.body.clientHeight : window.innerHeight;

        var o_s = this.fullOffsetH(MenuObject);
        if (TS_RightToLeft != 1) {
            if ((o_s + MenuObject.offsetWidth >= (WindowWidth + WindowLeftEdge))) {
                if (menutype == 0) {
                    o_d = Math.abs((o_s + MenuObject.offsetWidth) - (WindowWidth + WindowLeftEdge));
                    o_l = o_s;
                    MenuObject.style.left = o_l - o_d + "px";
                } else {
                    MenuObject.style.left = this.fullOffsetH(MenuObject.parent) - MenuObject.offsetWidth + this.ChildOverlap + "px";
                }
            }
        } else {
            if (o_s < WindowLeftEdge) {
                if (menutype == 0) {
                    MenuObject.style.left = WindowLeftEdge + "px";
                } else {
                    MenuObject.style.left = this.fullOffsetH(MenuObject.parent) + MenuObject.parent.offsetWidth - this.ChildOverlap + "px";
                }
            }
        }
    }

    this.TS_PopUp = function (elemid, e) {
        if (this.TSHideMenuEvent && this.TSHideMenuEventElemid == elemid) {
            window.clearTimeout(this.TSHideMenuEvent);
            this.TSHideMenuEvent = null;
        }
        if (this.isOpen || !this.useClickOpen) {
            var MenuObject;
            MenuObject = document.getElementById(elemid);
            if (MenuObject) {
                if (MenuObject != this.CurrentActiveMenu) {
                    if (typeof(jsnavBeforeShow) == "function") {
                        jsnavBeforeShow(elemid);
                    }
                    this.UserOverMenu = false;
                    this.UserOverSubMenu = false;
                    this.isExplicitClose = false;
                    this.HideMenu();
                    with (MenuObject) {
                        with (style) {
                            var obj = document.getElementById(elemid + "wrapper");
                            if (obj) {
                                //if (obj.offsetWidth==0) left = this.fullOffsetH (obj.childNodes[0])+"px";
                                //else left = this.fullOffsetH (obj)+"px";
                                if (location.href.indexOf("/admin") == -1)
                                {
                                    left = this.fullOffsetH(obj.childNodes[0]) + 1 + "px";
                                    if (TS_RightToLeft == 1) left = this.fullOffsetH(obj) + obj.offsetWidth - MenuObject.offsetWidth + "px";
                                    if (this.YPOP > 0) top = this.YPOP + this.TS_YOFFSET + "px";
                                    else
                                    {
                                        //top = this.fullOffsetV (obj)+obj.offsetHeight+"px";
                                        var bodyMargin = 0;
                                        //if (Tangora.Browser.IE) bodyMargin = parseInt(document.body.style.marginTop);
                                        top = this.fullOffsetV(obj.childNodes[0]) + obj.childNodes[0].offsetHeight + bodyMargin + 1 + "px";
                                    }
                                }
                                else
                                {
                                    left = this.fullOffsetH(obj) + "px";
                                    if (TS_RightToLeft == 1) left = this.fullOffsetH(obj) + obj.offsetWidth - MenuObject.offsetWidth + "px";
                                    if (this.YPOP > 0) top = this.YPOP + this.TS_YOFFSET;
                                    else top = this.fullOffsetV(obj) + obj.offsetHeight + "px";
                                }
                                if (TS_Mac && TS_IE && false) {
                                    var v = window.document.body.style.marginTop;
                                    var v2 = top;
                                    v = v.replace("px", "")
                                    v2 = v2.replace("px", "")
                                    v3 = new Number(v);
                                    v4 = new Number(v2);
                                }
                                this.KeepInWindow(MenuObject, 0);
                                visibility = "visible";
                                this.fixSize(MenuObject);
                            }
                        }
                    }
                    // Change css-class of the main element
                    setMenuItemClassName(elemid, navClassNameActive);
                    this.CurrentActiveMenu = MenuObject;
                    this.CurrentActiveSubMenu = null;
                    this.UserOverMenu = true;
                    this.curRule = this.curRule1;
                    if (TS_UseFading == 1) {
                        this.fadeIt(TS_FadingStartValue, TS_FadingEndValue);
                    }
                    if (typeof(jsnavAfterShow) == "function") {
                        jsnavAfterShow(elemid);
                    }
                }
            }
        }
    }

    this.TS_PopDown = function (elemid) {
        this.UserOverMenu = false;
        this.isExplicitClose = true;
        this.TSHideMenuEventElemid = elemid;
        this.TSHideMenuEvent = window.setTimeout("jsmenu.HideMenu('" + elemid + "')", TS_JSTimeout);
    }

    this.KeepMenuAlive = function (e) {
        var obj = TS_MenuGetEventSrcElement(e);
        if (!obj || (obj.tagName && obj.tagName != "DIV")) {
            this.UserOverMenu = true;
        }
    }

    this.KeepSubMenuAlive = function () {
        jsmenu.UserOverSubMenu = true;
    }

    this.HideMenu = function (elemid) {
        if (elemid && this.CurrentActiveMenu && this.CurrentActiveMenu.id != elemid) {
            return false;
        }
        if (this.isExplicitClose) {
            this.isOpen = false
        }
        MenuObject = this.CurrentActiveSubMenu;
        if (MenuObject) {
            if (!this.UserOverSubMenu || !this.UserOverMenu) {
                MenuObject.style.visibility = "hidden";
                this.CurrentActiveSubMenu = null;
                this.UserOverSubMenu = false;
            }
        }
        MenuObject = this.CurrentActiveMenu;
        if (MenuObject) {
            if (!this.UserOverMenu) {
                if (typeof(jsnavBeforeHide) == "function") {
                    jsnavBeforeHide(MenuObject.id);
                }
                MenuObject.style.visibility = "hidden";
                this.CurrentActiveMenu = null;
                this.UserOverMenu = false;
                // Change css-class of the main element
                setMenuItemClassName(MenuObject.id, navClassName);
                if (typeof(jsnavAfterHide) == "function") {
                    jsnavAfterHide(MenuObject.id);
                }
            }
        }
        this.TSHideMenuEvent = null;
        if (elemid) window.status = this.UserOverMenu;
    }

    this.showsubmenu = function (menu) {
        this.UserOverSubMenu = false;
        this.hidesubmenu();
        with (menu) {
            position = "absolute";
            with (style) {
                left = this.fullOffsetH(menu.parent) + menu.parent.offsetWidth - this.ChildOverlap + "px";
                if (TS_RightToLeft == 1) {
                    left = this.fullOffsetH(menu.parent) - menu.offsetWidth;
                }
                if (this.XPOP == 0) {
                    top = this.fullOffsetV(menu.parent) + menu.parentE.offsetTop + this.ChildOffset + "px";
                } else {
                    top = this.fullOffsetV(menu.parentE) + menu.parentE.offsetHeight + "px";
                }

                zIndex = 110;
                this.KeepInWindow(menu, 1);
                visibility = "visible";
                this.fixSize(menu);
            }
        }
        this.CurrentActiveSubMenu = menu;
        this.UserOverSubMenu = true;
        this.UserOverMenu = true;
        this.curRule = this.curRule2;
        if (TS_UseFading == 1) {
            this.fadeIt(TS_FadingStartValue, TS_FadingEndValue);
        }
    }

    this.hidesubmenu = function () {
        MenuObject = this.CurrentActiveSubMenu;
        if (MenuObject) {
            if (!this.UserOverSubMenu) {
                MenuObject.style.visibility = "hidden";
                this.CurrentActiveSubMenu = null;
            }
        }
    }

    this.doActivate = function () {
        if (jsmenu.curImage) {
            jsmenu.curImage.src = TS_ImageSrcActive;
        } else {
            this.src = TS_ImageSrcActive;
            jsmenu.curImage = this;
        }
    }

    this.doDeactivate = function () {
        if (jsmenu.curImage) {
            jsmenu.curImage.src = TS_ImageSrcInactive;
        } else {
            this.src = TS_ImageSrcInactive;
        }
        jsmenu.curImage = null;
    }

    this.fullOffsetH = function (o) {
        var tmp = o;
        var value = 0;
        while (tmp.offsetParent) {
            value += tmp.offsetLeft;
            tmp = tmp.offsetParent;
        }

        if (this.XPOP > 0 && (o.className != 'jsnav3' || TS_FLOW == 1)) {
            value += this.XPOP;
        }

        if (TS_Mac && TS_IE) {
            ttop = parseInt(value);
            var tmpLeft = tmp.style.marginLeft;
            ttop += parseInt(tmpLeft ? tmpLeft : 0);
            value = ttop;
        }
        return value;
    }

    this.fullOffsetV = function (o) {
        var tmp = o;
        var value = 0;
        if (typeof(tmp) != "undefined")
        {
            if (typeof(tmp.offsetParent) != "undefined")
            {
                while (tmp.offsetParent) {
                    value += tmp.offsetTop;
                    tmp = tmp.offsetParent;
                }
            }
        }

        if (this.XPOP > 0) {
            value -= o.offsetHeight;
        }

        if (TS_Mac && TS_IE) {
            ttop = parseInt(value);
            var v = window.document.body.style.marginTop;
            v = parseInt(v ? v : 0);
            ttop += v;
            value = ttop;
        }

        return value;
    }

    this.fixSize = function (m) {
        var max = 0;
        if (!m.fixed && (1 == 1)) {
            m.fixed = true;
            if (!TS_IE || /Opera\/9/.test(navigator.userAgent))
            {
                for (i = 0; i < m.childNodes.length; i++) {
                    var tempItem = m.childNodes[i];
                    tempItem.style.height = '1px';
                    var h = tempItem.clientHeight;
                    if (/Mozilla\/5\.0/.test(navigator.userAgent) || /Opera\/9/.test(navigator.userAgent)) {
                        max += parseInt(tempItem.style.paddingTop);
                        if (tempItem.childNodes[0].tagName != "IMG" && tempItem.childNodes[0].clientHeight > h) {
                            h = tempItem.childNodes[0].clientHeight + parseInt(tempItem.style.paddingTop);
                            //if (h<20) {max+=(20-h); h=20;}
                            //h=20;
                            //alert (h);
                        }
                        if (tempItem.childNodes[0].tagName == "IMG" && tempItem.childNodes[1].clientHeight > h) {
                            h = tempItem.childNodes[1].clientHeight + parseInt(tempItem.style.paddingTop);
                            //tempItem.childNodes[0].style.top = parseInt((h - tempItem.childNodes[0].clientHeight) / 2)+"px";
                        }
                        tempItem.style.height = h + 'px';
                        max += h;
                    }
                }
                if (this.SeparatorSize != 0) {
                    max += ((i - 1) * this.SeparatorSize);
                }
                if (TS_IE && (!/Opera\/9/.test(navigator.userAgent))) {
                    max += this.BorderWidth * 2
                }
                m.style.height = max + 'px';
            }
        }
    }

    this.ItemOver = function () {
        jsmenu.UserOverMenu = true;
        if (this.style) {
            this.style.backgroundColor = jsmenu.BGColorOver;
            if (this.imageItem) {
                jsmenu.curImage = this.imageItem;
                jsmenu.doActivate();
            }
            tempo = document.getElementById("elMenu" + this.id);
            if (tempo) {
                jsmenu.showsubmenu(tempo);
            }
        }
    }

    this.ItemOut = function () {
        if (this.style) {
            this.style.backgroundColor = jsmenu.BGColor;
            jsmenu.UserOverMenu = false;
            jsmenu.UserOverSubMenu = false;
            if (this.imageItem) {
                jsmenu.curImage = this.imageItem;
                jsmenu.doDeactivate();
            }
            window.setTimeout("jsmenu.HideMenu ()", TS_JSTimeout);
        }
    }

    this.init();
}

var jsmenu = new TJSMenu();

var tsLoadMenusRetryFunc;
if (window.onload) {
    // Store current load handler
    tsLoadMenusRetryFunc = window.onload;
}

window.onload = function() {
    setTimeout("jsmenu.loadMenu()", 0)
};
function TS_PopUp(elemid, e) {
    jsmenu.TS_PopUp(elemid, e);
}

function TS_PopDown(elemid) {
    jsmenu.TS_PopDown(elemid);
}

function setMenuItemClassName(id, navClassNameActive) {
    var MenuItemID = navMenuItemPrefix + id + navMenuItemSuffix;
    var MenuItem = document.getElementById(MenuItemID);
    if (MenuItem) {
        MenuItem.className = navClassNameActive;
    }
}

function AppendMenuElement(parentindex, link) {
    var parent = document.getElementById("elMenu" + parentindex);
    if (parent && parent.children) {
        var arr = new Array();
        arr[0] = link;
        arr[4] = 0; // is sub menu

        var itemindex = parent.children.length;
        jsmenu.CreateMenuElement(parent, arr, parentindex, itemindex, false, true);
        parent.fixed = false;
        jsmenu.fixSize(parent);
    }
}

function RemoveMenuElement(elemid) {
    var obj = document.getElementById(jsmenu.MenuIdArray[elemid]);
    if (obj && obj.parentNode) {
        var parent = document.getElementById(obj.parentNode.id);
        obj.parentNode.removeChild(obj);
        if (parent) {
            parent.fixed = false;
            jsmenu.fixSize(parent);
        }
    }
}

function TS_MenuGetEventSrcElement(e) {
    var obj;
    if (!e) {
        e = window.event;
    }
    if (e) {
        if (e.srcElement) {
            // Internet Explorer
            obj = e.srcElement;
        } else if (e.target) {
            // Mozilla
            obj = e.target;
            while (obj && !obj.tagName) {
                obj = obj.parentNode;
            }
        }
    }
    return obj;
}
