﻿// java script used by Gabber skin

var gabberMainMenu = null;
var orig_spm_initMyMenu = null;

function ExtendMainGabberMenu() {
    var menuBarId = "dnn_dnnMenu_ctldnnMenu";

    if (!orig_spm_initMyMenu) {
        orig_spm_initMyMenu = spm_initMyMenu;
        spm_initMyMenu = function(oXML, oCtl) {
            orig_spm_initMyMenu(oXML, oCtl);
            if (gabberMainMenu == null && oCtl.id == "dnn_dnnMenu_ctldnnMenu") {
                gabberMainMenu = new GabberMenu("dnn_dnnMenu_ctldnnMenu");
            }
        }
    }
    
    if (gabberMainMenu == null) {
        if (typeof (m_oSolpartMenu) != "undefined") {
            var solpartMenu = m_oSolpartMenu[menuBarId];
            if (solpartMenu != null && !solpartMenu.gabberMenu) {
                gabberMainMenu = new GabberMenu(menuBarId);
            }
        }
    }
}

function GabberMenu(menuBarId) {
    if (typeof (m_oSolpartMenu) != "undefined") {
        var solpartMenu = m_oSolpartMenu[menuBarId];
        if (solpartMenu != null && !solpartMenu.gabberMenu) {
            solpartMenu.gabberMenu = this;
            solpartMenu.onMenuBarMouseOver = function(e) { return this.gabberMenu.onMouseOver(e); };
            solpartMenu.onMenuBarMouseOut = function(e) { return this.gabberMenu.onMouseOut(e); };
        }
    }
}

GabberMenu.prototype.getSeparatorCell = function(menuItemCell, leftSeparator) {
    var parentCell = menuItemCell.parentNode;
    while (parentCell.nodeName.toLowerCase() != "td") {
        parentCell = parentCell.parentNode;
    }

    var parentSeparatorCell = leftSeparator ? parentCell.previousSibling : parentCell.nextSibling;
    while (parentSeparatorCell.nodeType != 1 && parentSeparatorCell.nodeName.toLowerCase() != "td") {
        parentSeparatorCell = leftSeparator ? parentSeparatorCell.previousSibling : parentSeparatorCell.nextSibling;
    }

    var separatorCell = null;
    separatorCell = leftSeparator ? parentSeparatorCell.lastChild : parentSeparatorCell.firstChild;
    while (separatorCell.nodeName.toLowerCase() != "td") {
        separatorCell = leftSeparator ? separatorCell.lastChild : separatorCell.firstChild;
    }

    return separatorCell;
}

GabberMenu.prototype.onMouseOver = function(cell) {
    try {
        var leftSeparatorCell = this.getSeparatorCell(cell, true);
        var rightSeparatorCell = this.getSeparatorCell(cell, false);

        leftSeparatorCell.className = "GabberMenuItemSeparatorLeftHover";
        rightSeparatorCell.className = "GabberMenuItemSeparatorRightHover";
    }
    catch (ex) {
        // do nothing
    }
}

GabberMenu.prototype.onMouseOut = function (cell) {
    try {
        var leftSeparatorCell = this.getSeparatorCell(cell, true);
        var rightSeparatorCell = this.getSeparatorCell(cell, false);

        leftSeparatorCell.className = "GabberMenuItemSeparatorLeft";
        rightSeparatorCell.className = "GabberMenuItemSeparatorRight";
    }
    catch (ex) {
        // do nothing
    }
}
