jmenuMovedLayers = 0;
jmenuMenuXLeftShift = 6;
jmenuMenuXRightShift = 10;
jmenuHiddenControls = new Array();
jmenuLWidth = new Array();
jmenuLWidthDetected = 0;

var jmenu_openedChildren = new Array();

var currentMenuName = '';

function activateMenu(menuName)
{
    if (menuName != currentMenuName) {
        jmenuShutdown();
        currentMenuName = menuName;
        jmenu = window['jmenu_'+menuName];
        jmenuMovedLayers = 0;
        jmenuMenuXLeftShift = 6;
        jmenuMenuXRightShift = 10;
        jmenuHiddenControls = new Array();
        jmenuLWidth = new Array();
        jmenuLWidthDetected = 0;
    }
}

function jmenuShutdown()
{
    if (typeof jmenu == "undefined") return;
    for (i=1; i<=jmenu.numl; i++) {
        var listl = eval("jmenu.listl.l"+i);
        jmenuPopUpL(listl, false);
    }
    jmenuShowControls(true);
}

function jmenuMoveLayers()
{
    if (!jmenuLWidthDetected) {
        for (i = 1; i <= jmenu.numl; i++) {
            var listl = jmenu.listl["l" + i];
            var l = document.getElementById(listl);
            jmenuLWidth[listl] = l ? l.offsetWidth : 0;
        }
        jmenuLWidthDetected = 1;
    }
}

function jmenuHideControls2(tagname)
{
    if (is_msie() == 0 || is_msie() >= 7) return;

    var ctls = document.getElementsByTagName(tagname);
    if (!ctls)
        return;

    for (var i=0; i<ctls.length; i++) {
        ctls[i].style.visibility = 'hidden';
        jmenuHiddenControls[jmenuHiddenControls.length] = ctls[i];
    }
}

function jmenuHideControls(topObj, tagname)
{
    if (is_msie() == 0 || is_msie() >= 7) return;

    if (topObj) {
        var menuPos = jmenuGetObjPosition(topObj);
        var ctls = document.getElementsByTagName(tagname);
        for (var i=0; i<ctls.length; i++) {
            var ctlPos = jmenuGetObjPosition(ctls[i]);
            if (!(ctlPos.right < menuPos.left || ctlPos.left > menuPos.right
            || ctlPos.bottom < menuPos.top || ctlPos.top > menuPos.bottom)) {
                ctls[i].style.visibility = 'hidden';
                jmenuHiddenControls[jmenuHiddenControls.length] = ctls[i];
            }
        }
    }
}

function jmenuShowControls(v)
{
    if (is_msie() == 0 || is_msie() >= 7) return;

    if (v) {
        for (var i=0; i<jmenuHiddenControls.length; i++)
            jmenuHiddenControls[i].style.visibility = 'visible';
        jmenuHiddenControls = new Array();
    } else {
        jmenuHiddenControls = new Array();
        jmenuHideControls2('SELECT');
    }
}

function jmenuResizeHandler()
{
    if (typeof jmenu == "undefined") return;
    jmenuShutdown();
    for (i=1; i<=jmenu.numl; i++) {
        var listl = eval("jmenu.listl.l"+i);
        jmenuSetLeft(listl, 0);
        jmenuSetTop(listl, 0);
    }
    jmenuMovedLayers = 0;
}
window.onresize = jmenuResizeHandler;

function getPixelPos(e)
{
    var l = 0;
    var t = 0;
    while (e) {
        l += e.offsetLeft;
        t += e.offsetTop;
        if (__getComputedStyle(e, 'position') != 'static' && __getComputedStyle(e, 'position') != '')
            break;
        e = e.offsetParent;
    }

    return new Array(l, t);
}

function jmenuMoveLayer(menuName, abscissa_margin, ordinate_margin, orientation)
{
    if (jmenu.jmenuLoaded) {
        if (!jmenuMovedLayers) {
            jmenuMoveLayers();
            jmenuMovedLayers = 1;
        }

        var layer = document.getElementById(menuName + jmenu.menuName);
        if (!layer) return;
        var layerwidth = layer.offsetWidth;
        var layerheight = layer.offsetHeight;
        var ref = document.getElementById("ref" + menuName + jmenu.menuName);
        if (ref && ref.firstChild && ref.firstChild.tagName && ref.firstChild.tagName.toLowerCase() == 'img') {
            ref = ref.firstChild;
        }
        var pos = ref ? getPixelPos(ref) : [0, 0];
        var newX = pos[0], newY = pos[1];
        if (orientation == "vert") {
            newX += ref.offsetWidth;
        } else if (orientation == "vert_right") {
            newX -= layerwidth;
        } else if (orientation == "horz_bottom") {
            newY -= layerheight;
        } else {
            newY += ref.offsetHeight;
        }
        newX -= abscissa_margin;
        newY -= ordinate_margin;
        windowwidth = getClientWidth();
        windowxoffset = getScrollLeft();
        if (newX + layerwidth > windowwidth + windowxoffset) {
            if (layerwidth > windowwidth) {
                newX = windowxoffset;
                // for mobile version set horizontal scrolling
                /*if (jmenu.mobile) {
                    layer.style.width = (windowwidth - 20) + 'px';
                    layer.style.overflow = 'auto';
                }*/
            } else {
                newX = windowwidth + windowxoffset - layerwidth;
            }
        }
        windowheight = getClientHeight();
        windowyoffset = getScrollTop();
        if (newY + layerheight > windowheight + windowyoffset) {
            if (layerheight > windowheight) {
                newY = windowyoffset;
                // for mobile version set vertical scrolling
                /*if (jmenu.mobile) {
                    layer.style.height = (windowheight - 20) + 'px';
                    layer.style.overflow = 'auto';
                }*/
            } else {
                newY = windowheight + windowyoffset - layerheight;
            }
        }
        jmenuSetLeft(menuName + jmenu.menuName, newX);
        jmenuSetTop(menuName + jmenu.menuName, newY);
    }
}

function jmenuPopUp(menuName)
{
    var submenuName = menuName;
    if (!menuName)
        return;

    jmenuShutdown();

    var popUpMenu = document.getElementById(menuName + jmenu.menuName);
    if (popUpMenu) {
        jmenuHideControls(popUpMenu, 'SELECT');
    }

    do {
        if (!menuName) {
            break;
        }

        jmenuPopUpL(menuName, true, submenuName == menuName);
        menuName = eval("jmenu.father."+menuName);

        var popUpMenu2 = document.getElementById(menuName + jmenu.menuName);
        if (popUpMenu2) {
            jmenuHideControls(popUpMenu2, 'SELECT');
        }

    } while (menuName != "")
}

function jmenuGetObjPosition(obj)
{
    var pos = getControlPixelPos(obj, 0, 0, 0, 0, 0);
    return {left: pos[0], top: pos[1],
        right: pos[0]+obj.offsetWidth, bottom: pos[1]+obj.offsetHeight,
        width: obj.offsetWidth, height: obj.offsetHeight};
}


function jmenuPopUpL(menuName, on, runAnimation)
{
    if (!menuName)
        return;

    var el = document.getElementById(menuName + jmenu.menuName);

    if (!el)
        return;

    if (jmenu.jmenuLoaded) {
        if (!jmenuMovedLayers) {
            jmenuMoveLayers();
            jmenuMovedLayers = 1;
        }
        if (on) {
            if (runAnimation) {
                animate(menuName + jmenu.menuName);
                if (jmenu.mobile) {
	                var cl = document.getElementById(menuName + jmenu.menuName).getElementsByTagName('a');
	                if (cl.length) {
	                	try { cl[0].focus(); } catch(e) { }
	                }
                }
            } else { 
                document.getElementById(menuName + jmenu.menuName).style.visibility = 'visible';
            }
            highlightParentItem('ref' + menuName + jmenu.menuName, true);
        } else {
            document.getElementById(menuName + jmenu.menuName).style.visibility = 'hidden';
            highlightParentItem('ref' + menuName + jmenu.menuName, false);
            if (jmenu.mobile) {
            	var cl = document.getElementById('ref' + menuName + jmenu.menuName).getElementsByTagName('a');
            	if (cl.length) {
            		try { cl[0].focus(); } catch(e) { }
            	}
            }
        }
    }
}

function animate(submenuId)
{
    var stepQuantity = 10;
    var timeStep = 25;
    var totalTime = 100;
    var menuDiv = document.getElementById(submenuId);
    if (jmenu.prevSubmenu == submenuId || is_msie() || true) {
        menuDiv.style.visibility = 'visible';
        return;
    }
    var opacityEnd = __getComputedStyle(menuDiv, 'opacity');
    jmenu.prevSubmenu = submenuId;
    if (!menuDiv.opacityEnd) menuDiv.opacityEnd = opacityEnd;
    if (menuDiv.style.visibility == 'hidden') {
        clearInterval(menuDiv.timerId);
        opacityEnd = menuDiv.style.opacity = menuDiv.opacityEnd;
        var menuHeight = parseInt(menuDiv.offsetHeight);
        var borderTop     = parseInt(__getComputedStyle(menuDiv, 'borderTopWidth'));
        var borderBottom  = parseInt(__getComputedStyle(menuDiv, 'borderBottomWidth'));
        var paddingTop    = parseInt(__getComputedStyle(menuDiv, 'paddingTop'));
        var paddingBottom = parseInt(__getComputedStyle(menuDiv, 'paddingBottom'));

        menuHeight = menuHeight - borderTop - borderBottom - paddingTop - paddingBottom;

        var step = parseInt(menuHeight / stepQuantity);

        timeStep = parseInt(totalTime / stepQuantity);
        var opacityStep = parseFloat(opacityEnd / stepQuantity);
        menuDiv.style.overflow = 'hidden';
        menuDiv.style.opacity = '0';
        menuDiv.style.height = '0px';
        menuDiv.style.visibility = 'visible';
        menuDiv.timerId = setInterval(function() {
            var height  = parseInt(menuDiv.style.height ? menuDiv.style.height : 0);
            var opacity = parseFloat(menuDiv.style.opacity);
            if (height + step >= menuHeight) {
                clearInterval(menuDiv.timerId);
                menuDiv.style.height  = '';
                menuDiv.style.opacity = opacityEnd;
            } else {
                menuDiv.style.opacity = opacity + opacityStep;
                menuDiv.style.height  = (height + step) + 'px';
            }
        }, timeStep);
    }
}

function timerCallback(ctrl, endHeight, step, opacityEnd, opacityStep)
{
    var height  = parseInt(ctrl.style.height);
    var opacity = parseFloat(ctrl.style.opacity);
    if (height + step >= endHeight) {
        clearInterval(ctrl.timerId);
        ctrl.style.height  = 'auto';
        ctrl.style.opacity = opacityEnd;
    } else {
        ctrl.style.opacity = opacity + opacityStep;
        ctrl.style.height  = (height + step) + 'px';
    }
}

function jmenuSetLeft(layer,x)
{
    var el = document.getElementById(layer);

    if (!el)
        return;

    el.style.left = x + "px";
}

function jmenuSetTop(layer,y)
{
    var el = document.getElementById(layer);

    if (!el)
        return;

    el.style.top = y + "px";
}

function jmenuGenerateClientMenu(menuName)
{
    activateMenu(menuName);
    if (!jmenu) {
        return;
    }
    if (typeof(jmenu) != "object") {
        return;
    }
    var parent = document.getElementById(menuName);
    if (!parent) {
        return;
    }
    if (jmenu.cssClass) parent.className = jmenu.cssClass;

    document.onclick = jmenuShutdown;

    var first = 1, t = '', position = 0;
    t += jmenu.beforeFirst;
    for (var i = 0; i < jmenu.items.length; i++) {
        var item = jmenu.items[i];
        var extraAttr = '';
        var caption = '';
        if (!item.parentId) {
            var style = "";
            if (item.meuHref) {
                style = "cursor: pointer; ";
            }
            if (jmenu.menuType == 'text') {
                caption = item.alt;
            } else if (jmenu.menuType == 'image') {
                if (item.sprite) {
                    // sprite
                    caption = "";
                    extraAttr = "data-x=\"" + item.x + "\" " +
                        "data-y=\"" + item.y + "\" " +
                        "data-hoverx=\"" + item.hoverX + "\" " +
                        "data-hovery=\"" + item.hoverY + "\" " +
                        "title=\"" + item.alt + "\"";
                    style += "background-position: -" + item.x + "px -" + item.y + "px; " +
                        "width: " + item.width + "px; height: " + item.height + "px; " +
                        "background-image: url(" + item.sprite + "); display: -moz-inline-box; display: inline-block; " +
                        "vertical-align: top";
                    if (is_msie()) {
                        style += "; overflow: hidden";
                    }
                } else {
                    // separate images
                    caption =
                        "<img border=\"0\" "  +
                        (item.src ? "src=\"" + item.src + "\" " : "") +
                        (item.alt ? "alt=\"" + item.alt + "\" " : "") +
                        "/>";
                    extraAttr =
                        (item.inactSrc ? "data-inactsrc=\"" + item.inactSrc + "\" " : "") +
                        (item.hoverSrc ? "data-hoversrc=\"" + item.hoverSrc + "\" " : "");
                }
            }
            extraAttr +=
                (item.cssClass ? "class=\"" + item.cssClass + "\" " : "") +
		        (item.inactClass ? "data-inactclass=\"" + item.inactClass + "\" " : "") +
                (item.hoverClass ? "data-hoverclass=\"" + item.hoverClass + "\" " : "") +
		        (item.menuHref ? "data-menuhref=\"" + item.menuHref + "\" " : "") +
		        (item.menuId ? "data-menuid=\"" + item.menuId + "\" " : "") +
		        (item.menuOrient ? "data-menuorient=\"" + item.menuOrient + "\" " : "data-menuorient=\"vert\" ") +
		        (item.menuMode ? "data-menumode=\"" + item.menuMode + "\" " : "data-menumode=\"normal\" ") +
		        (item.popupW ? "data-popupw=\"" + item.popupW + "\" " : "") +
		        (item.popupH ? "data-popuph=\"" + item.popupH + "\" " : "") +
		        (item.id ? "id=\"" + item.id + menuName + "\" " : "") +
                "data-menuname=\"" + menuName + "\" " +
                "style=\"" + style + "\" ";
                if (!jmenu.mobile) {
		            extraAttr +=
		                "onmouseover=\"navbutton_over(this, event)\" " +
		                "onmouseout=\"navbutton_out(this, event)\" " +
		                "onclick=\"navbutton_click(this, event)\" ";
                } else {
                    if (item.menuId) {
                        extraAttr += "onclick=\"navbutton_over(this, event)\" ";
                        item.menuHref = null;
                    } else {
                        extraAttr += "onclick=\"navbutton_click(this, event)\" ";
                    }
                }
            var menuItem = '';
            // find separator
            var menuSep = '';
            jmenu.menuSeparators.sort(SortCallback);
            for (var k = 0; k < jmenu.menuSeparators.length; k++) {
                var sep = jmenu.menuSeparators[k];
                if (position % sep.order == 0) {
                    menuSep = trim(jmenu.menuSeparators[k].code);
                    break;
                }
            }
            menuItem += !first ? menuSep : '';

            if (item.menuHref && item.menuMode != 'new_window' && item.menuMode != 'popup') {
                menuItem += '<a href="' + item.menuHref + '" ';
            } else {
                menuItem += '<a href="javascript:undefined" ';
            }
            menuItem += extraAttr + '>';
            menuItem += caption;
            menuItem += '</a>';

    	    t += menuItem;
            first = 0;
            position++;
            if (position == jmenu.maxItems) break;
        }
    }
    t+= '<div id="'+jmenu.menuName+ 'SubmenuPlaceholder"></div>';
    t+= jmenu.afterLast;
	parent.innerHTML = t;

    jmenuMoveLayers();
    jmenu.jmenuLoaded = 1;
}

function SortCallback(a,b)
{
    if (a.order > b.order) return -1;
    if (a.order < b.order) return 1;
    return 0;
}

function jmenuGeneratePopUpMenu(menuId)
{
    if (!jmenu)
        return;

    if (menuId == "")
        return;

    if (document.getElementById(menuId + jmenu.menuName))
        return;

    var submenuDiv = document.createElement('div');
    submenuDiv.id = menuId.toString()+jmenu.menuName;
    submenuDiv.style.position = 'absolute';
    submenuDiv.style.left = 0;
    submenuDiv.style.top = 0;
    submenuDiv.style.visibility = 'hidden';
    submenuDiv.className = 'submenuShell' + (jmenu.mobile ? ' MobileSubMenu' : '');
    submenuDiv.style.zIndex = 7300;
    if (jmenu.closeOnOut) {
        submenuDiv.onmouseover = function() {
            if (jmenu._timer) clearTimeout(jmenu._timer);
            jmenu._inSubMenu = true;
        }
        submenuDiv.onmouseout = function() {
            jmenu._timer = setTimeout(function(){ jmenu._inSubMenu = false; jmenuShutdown(); }, 100);
        }
    }

    // count quantity of items for current menu item
    var items_count = 0;
    var current_menu_items = new Array();
    for (var i=0; i<jmenu.items.length; i++) {
        var father = eval("jmenu.father."+jmenu.items[i].id.substr(3));
        if (father == menuId) {
            items_count++;
            current_menu_items.push(jmenu.items[i]);
        }
    }
    var columnsQuantity = 1;
    if (!jmenu.mobile && navmenu_max_items_per_column > 0) {
        columnsQuantity = parseInt(items_count / navmenu_max_items_per_column) + 1;
        var itemsPerColumn  = parseInt(items_count / columnsQuantity) +
                                ((items_count % columnsQuantity > 0) ? 1 : 0);
    }

    var isMultiColumn = (columnsQuantity > 1);
    if (isMultiColumn) {
        var table = document.createElement('table');
        table.setAttribute('cellpadding', '0');
        table.setAttribute('cellspacing', '0');
        submenuDiv.appendChild(table);
        var tbody = document.createElement('tbody');
        table.appendChild(tbody);
        var columns = document.createElement('tr');
        tbody.appendChild(columns);
    }
    var ncol = 0;
    if (jmenu.mobile) {
        // create 'Back/Close' option
        if (!isMultiColumn) {
            column = submenuDiv;
        } else {
            var column = document.createElement('td');
            column.className = 'submenuColumnFirst submenuLines';
            columns.appendChild(column);
            ncol++;
        }
        var a = document.createElement('a');
        a.setAttribute('data-parentmenuid', menuId);
        a.href = 'javascript:undefined';
    	a.className = "submenuInactiveItem MobileSubMenuClose";
    	a.innerHTML = 'Close ✖';
        a.onclick = function(event) { 
        	jmenuPopUp(menuId); 
        	jmenuPopUpL(menuId, false); 
        	event.cancelBubble = true;
    	}
        column.appendChild(a);
    }
    for (var i = 0; i < current_menu_items.length; i++) {
        // columns code
        var current_item = current_menu_items[i];
        if (!isMultiColumn) {
            column = submenuDiv;
        } else {
            var ind = jmenu.mobile ? i + 1 : i;
            if (ind % itemsPerColumn == 0) {
                var column = document.createElement('td');
                if (ncol == 0) {
                    column.className = 'submenuColumnFirst submenuLines';
                } else if (ncol == columnsQuantity-1) {
                    column.className = 'submenuColumnLast submenuLines';
                } else {
                    column.className = 'submenuColumn submenuLines';
                }
                columns.appendChild(column);
                ncol++;
            }
        }

        var caption = (current_item.alt) ? current_item.alt : '';
        var href = current_item.menuHref;

        var div = document.createElement('div');
        div.className = "submenuInactiveItem" + (jmenu.mobile ? " MobileSubMenuInactiveItem" : '');
        div.setAttribute('data-parentmenuid', menuId);

        if (current_item.separator) {
            div.className = 'submenuSeparator submenuLines' + (jmenu.mobile ? ' MobileSubMenuSeparator' : '');
        } else if (current_item.header) {
            div.innerHTML = current_item.alt;
            div.className = 'submenuHeading' + (jmenu.mobile ? ' MobileSubMenuHeading' : '');
        } else {
        	div.setAttribute('data-menuid', current_item.menuId ? current_item.menuId : '');
        	div.setAttribute('data-menuhref', current_item.menuHref ? current_item.menuHref : '');
        	div.setAttribute('data-menumode', current_item.menuMode ? current_item.menuMode : '');
        	div.setAttribute('data-menuorient', current_item.menuOrient ? current_item.menuOrient : '');
        	div.setAttribute('data-popupw', current_item.popupW ? current_item.popupW : '');
        	div.setAttribute('data-popuph', current_item.popupH ? current_item.popupH : '');
            div.id  = current_item.id ? current_item.id + jmenu.menuName : '';

            if (!jmenu.mobile) {
                div.onmouseover = function(event) {navmenu_over(this, event ? event : window.event);};
                div.onmouseout = function(event) {navmenu_out(this, event ? event : window.event);};
                div.onclick = function(event) {navmenu_click(this, event ? event : window.event);return false;};
            } else {
                if (current_item.menuId) {
                    href = null;
                    div.onclick = function(event) {navmenu_over(this, event ? event : window.event);return false;};
                } else {
                    div.onclick = function(event) {navmenu_click(this, event ? event : window.event);return false;};
                }
            }

            var a = document.createElement('a');
            if (href) {
                a.href = href;
            } else {
                a.href = 'javascript:undefined';
            }
            a.innerHTML = caption;
            div.appendChild(a);

            if (current_item.menuId) {
                div.className = div.className + ' hasSubmenu';
            }
        }
        column.appendChild(div);
    }

    var menuDiv = document.getElementById(jmenu.menuName+'SubmenuPlaceholder');
    menuDiv.appendChild(submenuDiv);
}

var navmenu_highlight = 1;


function getParentsMenuRecursively(parentmenuId, disallowedMenuItemsToHide) {

	disallowedMenuItemsToHide.push(parentmenuId);

	var parentMenu    = document.getElementById('ref' + parentmenuId + jmenu.menuName);
	if(!parentMenu) return;

	var _parentMenuID  =  parentMenu.getAttribute('data-parentmenuid');
	if(!_parentMenuID) return;

	getParentsMenuRecursively(_parentMenuID, disallowedMenuItemsToHide);
}

function highlightParentItem(id, isOn)
{
    var m = id.match(/(ref(L\d+))(.+)/);
    var refLm = m[1];
    var menuName = m[3];
    var Lm = m[2];
    var currentItem  = document.getElementById(id);
    var parentMenuId = currentItem.getAttribute('data-parentmenuid');
    var parentElement = document.getElementById('ref' + parentMenuId + menuName);

    if (parentElement) { // submenu level
        if (isOn) {
            currentItem.className = currentItem.className.replace('submenuInactiveItem', 'submenuActiveItem');
            if (jmenu.mobile) {
                currentItem.className = currentItem.className.replace('MobileSubMenuInactiveItem', 'MobileSubMenuActiveItem');
            }
        } else {
            currentItem.className = currentItem.className.replace('submenuActiveItem', 'submenuInactiveItem');
            if (jmenu.mobile) {
                currentItem.className = currentItem.className.replace('MobileSubMenuActiveItem', 'MobileSubMenuInactiveItem');
            }
        }
    }
    if (!parentElement) { // first level
        navbutton_highlight(currentItem, isOn);
    }
}

function navmenu_over(ctl, event)
{
    var menuHref = ctl.getAttribute('data-menuhref');
    var menuId = ctl.getAttribute('data-menuid');
    var parentmenuId = ctl.getAttribute('data-parentmenuid');

    ctl.className = ctl.className.replace('submenuInactiveItem', 'submenuActiveItem');
    if (jmenu.mobile) {
        ctl.className = ctl.className.replace('MobileSubMenuInactiveItem', 'MobileSubMenuActiveItem');
    }

    if (menuId) {
        jmenuGeneratePopUpMenu(menuId);
        jmenuMoveLayer(menuId, 2, 6, 'vert');
        jmenuPopUp(menuId);
        if (array_indexof(jmenu_openedChildren, menuId) == -1) jmenu_openedChildren.push(menuId);
	} else {
		var disallowedMenuItemsToHide = new Array();
		getParentsMenuRecursively(parentmenuId, disallowedMenuItemsToHide);
        for (var i = 0; i <	jmenu_openedChildren.length; i++) {
            if (array_indexof(disallowedMenuItemsToHide, jmenu_openedChildren[i]) == -1)
                jmenuPopUpL(jmenu_openedChildren[i], false);
        }
	}

    if (menuHref) {
        window.status = menuHref.replace(/(&&|\?&|&$|\?$)/g, '');
    }
    if (jmenu.mobile) {
    	event.cancelBubble = true;
    }
}

function navmenu_out(ctl, event)
{
    if (ctl.getAttribute('data-menuid')) return; // see jmenuPopUpL
    ctl.className  = ctl.className.replace('submenuActiveItem', 'submenuInactiveItem') ;
}

function navmenu_click(ctl, event)
{
    var menuHref = ctl.getAttribute('data-menuhref');
    var menuId = ctl.getAttribute('data-menuid');
    var menuMode = ctl.getAttribute('data-menumode');
    var popupW = ctl.getAttribute('data-popupw');
    var popupH = ctl.getAttribute('data-popuph');

    if (menuHref) {
        if (menuMode == 'new_window') {
            openWindow(menuHref, '');
            return false;
        } else if (menuMode == 'popup') {
            var attr = "scrollbars=yes,resizable=yes";
            if (popupW)
                attr += ',width=' + popupW;
            if (popupH)
                attr += ',height=' + popupH;
            openWindow(menuHref, attr);
            return false;
        } else {
            setLocation(menuHref);
        }
    } else {
        event.cancelBubble = true;
    }
}

function navbutton_over(ctl, event)
{
    var menuHref = ctl.getAttribute('data-menuhref');
    var menuId = ctl.getAttribute('data-menuid');
    var parentMenuId = ctl.getAttribute('data-parentmenuid');
    var menuMode = ctl.getAttribute('data-menumode');
    var menuOrient = ctl.getAttribute('data-menuorient');
    var menuName = ctl.getAttribute('data-menuname');

    activateMenu(menuName);
    var subMenuObj = document.getElementById(menuId+menuName);
    if (subMenuObj && subMenuObj.style.visibility == 'visible') {
        jmenu.prevSubmenu = menuId+menuName;
    } else {
        jmenu.prevSubmenu = '';
    }

    navbutton_highlight(ctl, true);
    if (menuId) {
        jmenuGeneratePopUpMenu(menuId);
        jmenuMoveLayer(menuId, 0, 0, menuOrient);
        jmenuPopUp(menuId);
    } else if (parentMenuId) {
        jmenuPopUp(parentMenuId);
    }
    else {
        jmenuShutdown();
    }

    if (menuHref) {
        window.status = menuHref.replace(/(&&|\?&|&$|\?$)/g, '');
    }
    if (jmenu.mobile) {
    	event.cancelBubble = true;
    }
}

function navbutton_out(ctl, event)
{
    var menuId = ctl.getAttribute('data-menuid');
    if (menuId) {
        if (jmenu.closeOnOut) {
            setTimeout(function(){ if (!jmenu._inSubMenu) { jmenuPopUpL(menuId, false); jmenuShowControls(true); } }, 100);
        }
        return; // see jmenuPopUpL
    }
    navbutton_highlight(ctl, false);
}

function navbutton_click(ctl, event)
{
    var menuHref = ctl.getAttribute('data-menuhref');
    var menuId = ctl.getAttribute('data-menuid');
    var menuMode = ctl.getAttribute('data-menumode');
    var popupW = ctl.getAttribute('data-popupw');
    var popupH = ctl.getAttribute('data-popuph');
    var menuName = ctl.getAttribute('data-menuname');
    activateMenu(menuName);

    if (menuHref) {
        if (menuMode == 'new_window') {
            openWindow(menuHref, '');
        } else if (menuMode == 'popup') {
            var attr = "scrollbars=yes,resizable=yes";
            if (popupW)
                attr += ',width=' + popupW;
            if (popupH)
                attr += ',height=' + popupH;
            openWindow(menuHref, attr);
        } else {
            setLocation(menuHref);
        }
    } else {
        event.cancelBubble = true;
    }
}

function navbutton_highlight(ctl, v)
{
    if (navmenu_highlight) {
        var useSprite = ctl.getAttribute('data-hoverx') != '' && ctl.getAttribute('data-hoverx') != null;
        if (useSprite) {
            if (v) {
                var hoverX = ctl.getAttribute('data-hoverx');
                var hoverY = ctl.getAttribute('data-hovery');
                ctl.style.backgroundPosition = '-' + hoverX + 'px -' + hoverY + 'px';
            } else {
                var x = ctl.getAttribute('data-x');
                var y = ctl.getAttribute('data-y');
                ctl.style.backgroundPosition = '-' + x + 'px -' + y + 'px';
            }
        } else {
            if (v) {
                var hoverSrc = ctl.getAttribute('data-hoversrc');
                var hoverClass = ctl.getAttribute('data-hoverclass');
                var img = ctl.getElementsByTagName('img')[0];
                if (img) img.src = hoverSrc;
                ctl.className = hoverClass;
            } else {
                var inactSrc = ctl.getAttribute('data-inactsrc');
                var inactClass = ctl.getAttribute('data-inactclass');
                var img = ctl.getElementsByTagName('img')[0];
                if (img) img.src = inactSrc;
                ctl.className = inactClass;
            }
        }
    }
}

