// Constants
var HIDE_DELAY_MS = 100;
var ANIMATE_MS = 200;
var ANIMATION = !_isMacGecko;
var MENU_PADDING = 16;
var MENU_V_OFFSET = 3;
var MENU_H_OFFSET = 6;
var SHOW_DELAY_MS = 75;
var ARROW_CHAR = "&nbsp;&#9658;&nbsp;";
if (_isMsie)
{
    ARROW_CHAR = "<span style=\"font-size:11px; line-height:13px;\">&nbsp;&#9658;&nbsp;</span>";
}
if (_isSafari)
{
    ARROW_CHAR = "<span style=\"font-size:10px; line-height:13px;\">&nbsp;&#9658;&nbsp;</span>";
}
if (_isFf)
{
    ARROW_CHAR = "<span style=\"font-size:10px; line-height:13px;\">&nbsp;&#9654;&nbsp;</span>";
}
//ARROW_CHAR = ">";

NAVSCRIPTS = true;
function getNode(node)
{
    if (typeof node != "object")
    {
        return _nodes[node];
    }

    return node;
}


function hideParents(node)
{
    if (!node)
    {
        return;
    }

    node = getNode(node);

    var s = node.superNode;
    while (s)
    {
        hide(s.getVisibleMenu());
        s = s.superNode;
    }
}

function hideChildren(node)
{
    if (!node)
    {
        return;
    }

    node = getNode(node);

    for (var i = 0; i < node.sub.length; i++)
    {
        hideMenuTree(node.sub[i]);
    }
}

function hideSiblingTrees(node)
{
    if (!node)
    {
        return;
    }

    node = getNode(node);
    var superNode = node.superNode;
    if (!superNode)
    {
        return;
    }

    for (var i = 0; i < superNode.sub.length; i++)
    {
        var sibling = superNode.sub[i];
        if (sibling == node)
        {
            continue;
        }
        hideMenuTree(sibling);
    }
}

function hideMenuTree(node)
{
    if (!node)
    {
        return;
    }

    node = getNode(node);

    var menuElement = node.getVisibleMenu();
    hide(menuElement);

    var len = node.sub.length;
    for (var i = 0; i < len; i++)
    {
        if (node.sub[i])
        {
            hide(node.sub[i].highlight);
            node.sub[i].highlight = null;
        }
    }

    hideChildren(node);
}

function getButtons(menu)
{
    return findChildrenByClass(menu, "scrollButton");
}

function compactMenu(menuDiv)
{
    var origDisplay = menuDiv.style.display;
    menuDiv.style.display = "inline";
    var menuTable = findChildrenByClass(menuDiv, "menuTable")[0];
    var rows = menuTable.getElementsByTagName("tr");
    var maxWidth = 0;
    for (var r = 0; r < rows.length; r++)
    {
        var row = rows.item(r);
        var spans = row.getElementsByTagName("span");

        // minimum width
        var width = 20;
        for (var s = 0; s < spans.length; s++)
        {
            var span = spans.item(s);
            width += span.offsetWidth;
        }

        if (width > maxWidth)
        {
            maxWidth = width;
        }
    }
    menuDiv.style.width = maxWidth;
    menuDiv.style.display = origDisplay;
}

function scrollMenu(button, down)
{
    var menuElement = findAncestorByClass(button, "menuDiv");
    var scrollDiv = findChildrenByClass(menuElement, "menuScrollDiv")[0];
    var menuTable = findChildrenByClass(scrollDiv, "menuTable")[0];
    var cells = findChildrenByClass(menuTable, "tile");

    var pos = scrollDiv.scrollPosition;
    if (down)
    {
        pos++;
    } else {
        pos--;
    }

    if (pos < 0)
    {
        pos = 0;
    }

    if (pos > cells.length)
    {
        pos = cells.length;
    }

    var minY = -(menuTable.offsetHeight - scrollDiv.offsetHeight);
    if (_isSafari)
    {
        minY--;
    }
    var scrollPos = 0;
    for (var i = 0; i < pos; i++)
    {
        if (scrollPos < minY)
        {
            pos = i;
            break;
        }
        scrollPos -= cells[i].offsetHeight;
    }
    scrollDiv.scrollPosition = pos;

    menuTable.style.position = "relative";
    var y = scrollPos;


    if (y < minY)
    {
        y = minY;
    }

    menuTable.style.top = y;
}

var _showTimeoutId = 0;
var _showElement = null;
var _showUid = 0;
var _showPath = false;
function showMenu(element, uid, path)
{
    _showElement = element;
    _showUid = uid;
    _showPath = (path ? true : false);
    if (ANIMATION)
    {
        if (_showTimeoutId)
        {
            clearTimeout(_showTimeoutId);
            _showTimeoutId = 0;
        }
        _showTimeoutId = setTimeout(showMenuReal, SHOW_DELAY_MS);
    } else {
        showMenuReal();
    }
}

function showMenuReal()
{
    var element = _showElement;
    var uid = _showUid;
    var path = _showPath;

    var node = _nodes[uid];
    if (!node)
    {
        return;
    }

    if (path && isVisible(node.superNode))
    {
        hideMenuTree(_menuRoot);
    }

    if (isVisible(node) || isAnimating(node.superNode))
    {
        return;
    }

    var pathNode = node;
    while (pathNode)
    {
        hideSiblingTrees(pathNode);
        pathNode = pathNode.superNode;
    }
    hideChildren(node);

    var winSize = getWindowSize();
    var windowHeight = winSize.h - (MENU_PADDING * 2);
    var menuElement = node.getMenu();
    if (menuElement)
    {
        if (_isMsie)
        {
            menuElement.style.display = "inline";
        }
        var h = menuElement.offsetHeight;
        if (h > windowHeight)
        {
            if (_isMsie)
            {
                menuElement.style.display = "none";
            }
            menuElement = node.getScrollMenu();
            if (_isMsie)
            {
                menuElement.style.display = "inline";
            }
        }
    }

    if (menuElement)
    {
        var bounds = getBounds(element);
        var t = bounds.y;
        element = findAncestorByClass(element, "highlightDiv") || findAncestorByClass(element, "menuDiv") || findAncestorByClass(element, "menu");
        if (!isVisible(element))
        {
            show(element);
            bounds = getBounds(element);
        }

        var mainBounds = getBounds(MM_findObj("mainDiv"));
        var l = bounds.x + bounds.w - mainBounds.x;
        if (_isGecko)
        {
            t--;
        }
        if (_isSafari)
        {
            l++;
        }

        // offset the menu inward and downward
        l -= MENU_H_OFFSET;
        t -= MENU_V_OFFSET;
        var menuStyle = menuElement.style;

        // on IE, set to display inline so we can get accurate bounds.

        // adjust height to be onscreen.
        var buttonHeight = 0;
        var buttons = getButtons(menuElement);
        for (var i = 0; i < buttons.length; i++)
        {
            buttonHeight += buttons[i].offsetHeight;
        }

        var h = menuElement.offsetHeight;
        var scrollDiv = findChildrenByClass(menuElement, "menuScrollDiv")[0];
        if (scrollDiv)
        {
            if (!scrollDiv.origHeight)
            {
                scrollDiv.origHeight = scrollDiv.offsetHeight;
            } else {
                scrollDiv.style.height = scrollDiv.origHeight;
                var menuTable = findChildrenByClass(scrollDiv, "menuTable")[0];
                menuTable.style.top = 0;
            }
            scrollDiv.scrollPosition = 0;

            var availMenuHeight = windowHeight - buttonHeight;
            var tiles = findChildrenByClass(scrollDiv, "tile");
            var tileHeight = 100000;
            for (var i = 0; i < tiles.length; i++)
            {
                if (tiles[i].offsetHeight < tileHeight)
                {
                    tileHeight = tiles[i].offsetHeight;
                }
            }
            var menuHeight = availMenuHeight - (availMenuHeight % tileHeight) + 1;
            scrollDiv.style.height = Math.min(menuHeight, scrollDiv.origHeight);
            h = menuElement.offsetHeight;
        }

        var wh = getScrollY() + winSize.h - MENU_PADDING;
        if ((t + h) > wh)
        {
            t = (wh - h);
        }

        menuStyle.top = t;
        menuStyle.left = l;

        compactMenu(menuElement);

        // Animate and display
        if (ANIMATION)
        {
            animateNode(menuElement, l, t);
        } else {
            show(menuElement);
            var maxX = getMaxX();
            var menuWidth = menuElement.offsetWidth;
            if (l + menuWidth > maxX)
            {
                var dx = maxX - (l + menuWidth);
                shiftNodes(node, dx);
                node.startX += dx;
            }
        }
    }
}

function hideHighlight(depth)
{
    hide(_highlightDivs[depth-2]);
    hide(_highlightArrowDivs[depth-2]);
}

function hideHighlights()
{
    for (var i = 0; i < _highlightDivs.length; i++)
    {
        hide(_highlightDivs[i]);
        hide(_highlightArrowDivs[i]);
    }
}

function highlightTile(trNode, uid)
{
    var node = _nodes[uid];
    if (isAnimating(node.superNode))
    {
        node.superNode.tempTr = trNode;
        node.superNode.tempUid = uid;
        return;
    }

    var a1;
    var a2;
    if (node.sub.length)
    {
        a1 = _highlightArrowDivs;
        a2 = _highlightDivs;
    } else {
        a2 = _highlightArrowDivs;
        a1 = _highlightDivs;
    }

    var tileDiv = a1[node.depth - 2];
    hide(a2[node.depth - 2]);

    // update text
    var span = tileDiv.getElementsByTagName("span").item(0);
    span.innerHTML = node.name;
    var rootTile = ((node.depth - 2) == 0);
    if (!rootTile)
    {
        span.className = "subMenuText";
    } else {
        span.className = "menuText";
    }

    // update size and position
    var tdNode = findChildrenByClass(trNode, "tile")[0];
    var menuDiv = findAncestorByClass(trNode, "menuDiv") || findAncestorByClass(trNode, "menu");
    var tdBounds = getBounds(tdNode);
    var menuBounds = getBounds(menuDiv);
    var parentBounds = getBounds(tileDiv.offsetParent);
    var l = tdBounds.x - parentBounds.x;
    var t = tdBounds.y - parentBounds.y;
    var w = menuBounds.w;
    if (_isGecko)
    {
        l--;
        t--;
        //w++;
    } else if (_isSafari) {
        if (node.depth == 2)
        {
            w--;
        }
    }

    if (rootTile)
    {
        l++;
        w--;
    }
    tileDiv.style.left = l;
    tileDiv.style.top = t;
    tileDiv.style.width = w;
    node.highlight = tileDiv;

    // update event handlers
    tileDiv.onmouseover = function() { enterMenu(); showMenu(this, this.tileNode.uid); }
    tileDiv.onclick = function() { gotoNode(this.tileNode.uid); }
    tileDiv.tileNode = node;

    // show it
    show(tileDiv);

    tileDiv.onmouseover();
}

var _locked = false;
function lockMenu()
{
    _locked = true;
}

function unlockMenu()
{
    _locked = false;
}

function hideIfUnlocked(o)
{
    if (!_locked)
    {
        hideMenuTree(_menuRoot);
        hideHighlights();
    }
}


// HTML emitting functions ------------------------------

function emitImg(width, height, hspace, vspace)
{
    var accum = "<img width=\"" + width + "\" height=\"" + height + "\"";
    if (hspace)
    {
        accum += " hspace=\"" + hspace + "\"";
    }
    if (vspace)
    {
        accum += " vspace=\"" + vspace + "\"";
    }
    accum += "/>";

    return accum;
}

function emitSpacers(count)
{
    var accum = "";
    for (var j = 0; j < count; j++)
    {
        accum += "<td class=\"spacerTd\"></td>";
    }

    return accum;
}

function emitHLine(position, length)
{
    var colspan = length - position;
    var accum = "<tr>";
    accum += emitSpacers(position);
    accum += "<td class=\"hLine\" colspan=\"" + colspan + "\">";
    accum += emitImg(1, 1);
    accum += "</td></tr>";

    return accum;
}

function emitVLine()
{
    var accum = "<td class=\"vLine\">";
    accum += emitImg(1, 1);
    accum += "</td>";

    return accum;
}

function findPathMenuChild(obj)
{
    return findChildrenByClass(obj, "tileArrow-sel")[0] || findChildrenByClass(obj, "tile-sel")[0] || obj;
}

function emitHighlightTile(tileName, uid, depth, totalDepth, arrow, pathTile)
{
    var accum = "";

    var textType = "subMenuText";
    if (depth == 0)
    {
        textType = "menuText";
        accum += emitHLine(depth, totalDepth);
    }

    var colspan = totalDepth - depth;
    accum += "<tr";
    if (uid)
    {
        if (pathTile)
        {
            accum += " onclick=\"gotoNode(" + uid + ");\"";
            accum += " onmouseover=\"showMenu(findPathMenuChild(this), " + uid + ", true);\"";
        }
    }
    accum += ">";
    accum += emitSpacers(depth);
    accum += "<td colspan=\"" + colspan + "\"><table class=\"menuTable\" cellspacing=\"0\" cellpadding=\"0\"><tbody><tr>";
    accum += emitVLine();
    accum += "<td";
    accum += " class=\"tile-sel\" colspan=\"" + colspan +"\">";

    var widthHack = (_isSafari && (tileName.length > 7));
    if (widthHack)
    {
        accum += "<div style=\"position:relative;width:10px;overflow:visible;\">";
    }
    accum += "<span class=\"" + textType + "\">";
    accum += htmlEncode(tileName);
    accum += "</span>";
    if (widthHack)
    {
        accum += "</div>";
    }
    accum += "</td>";
    accum += emitVLine();
    if (arrow)
    {
        accum += "<td class=\"tileArrow-sel\"";
        if (_isGecko)
        {
            accum += " style=\"padding-bottom:1px;\"";
        }
        accum += ">";
        accum += "<span class=\"menuText\">" + ARROW_CHAR + "</span><br/>";
        accum += "</td>";
        accum += emitVLine();
    }
    accum += "</tr></tbody></table></td></tr>";
    accum += emitHLine(depth, totalDepth);
    return accum;
}

// END HTML emitting functions --------------------------

function createNav()
{
    var win = window;
	var element = MM_findObj("navigation");
    if (typeof element == "undefined" || element == null)
    {
        alert("navigation not found!");
        return;
    }
    disableSelection(element);
    var pathStr = element.innerText || element.textContent || htmlDecode(element.innerHTML);
	var path = pathStr.split(",");
    cleanArray(path);
	element.innerHTML = "";
    var menu = createRootMenu(path);
    element.appendChild(menu);
    createHighlights();
    animator();
    show(element);
}

function createHighlightDiv(d, arrow)
{
    var container = document.createElement("div");
    container.className = "highlightDiv";
    hide(container);
    container.style.zIndex = 100 + (((d+1) * 2) - 1);
    var accum = "<table class=\"menuTable\" cellspacing=\"0\" cellpadding=\"0\"><tbody>";
    accum += emitHighlightTile("", 0, 0, 1, arrow);
    accum += "</tbody></table>";
    disableSelection(container);
    container.innerHTML = accum;
    container.onmouseover = enterMenu;
    container.onmouseout = leaveMenu;
    MM_findObj("navigation").appendChild(container);

    return container;
}

var _highlightDivs = new Array();
var _highlightArrowDivs = new Array();
function createHighlights()
{
    for (var d = 0; d < _maxDepth; d++)
    {
        _highlightDivs[d] = createHighlightDiv(d, false);
        _highlightArrowDivs[d] = createHighlightDiv(d, true);
    }
}

function enterMenu()
{
    lockMenu();
}

var _hideTimeoutId = 0;
function leaveMenu() 
{
    unlockMenu(); 
    if (_hideTimeoutId)
    {
        clearTimeout(_hideTimeoutId);
    }
    _hideTimeoutId = setTimeout(function () { hideIfUnlocked() }, HIDE_DELAY_MS);
};

function createSubMenu(node, scroll)
{
    var container = document.createElement("div");
    container.className = "menuDiv";
    hide(container);
    container.style.zIndex = 100 + ((node.depth-1) * 2);

    disableSelection(container);
    container.innerHTML = createMenu(node, null, scroll);
    container.onmouseover = enterMenu;
    container.onmouseout = leaveMenu;
    if (scroll)
    {
        node.scrollMenu = container;
    } else {
        node.menu = container;
    }
    container.menuNode = node;
    MM_findObj("navigation").appendChild(container);
    compactMenu(container);
}

function createSubMenus(superNode)
{
    for (var i = 0; i < superNode.sub.length; i++)
    {
        var node = superNode.sub[i];
        if (!node)
        {
            continue;
        }
    
        createSubMenu(node);
        if (node.sub.length)
        {
            createSubMenus(node);
        }
    }
}

function createMenu(superNode, path, scroll)
{
    if (!superNode)
    {
        return "";
    }

    var accum = "";
    if (scroll)
    {
        accum += "<div class=\"scrollButton\" onmouseover=\"hideHighlight(" + (superNode.depth+1) + "); this.className='scrollButton-armed';\" onmousedown=\"this.className='scrollButton-pressed';\" onmouseout=\"this.className='scrollButton';\" onmouseup=\"this.className='scrollButton-armed'; scrollMenu(this);\" align=\"center\">";
        accum += "&#9650;";
        accum += "</div><div class=\"menuScrollDiv\">";
    }
    accum += "<table class=\"menuTable\" cellspacing=\"0\" cellpadding=\"0\"><tbody>";
    for (var i = 0; i < superNode.sub.length; i++)
    {
        var subNode = superNode.sub[i];
        if (!subNode)
        {
            continue;
        }
        
        if (path && cleanName(subNode.name) == cleanName(path[1]))
        {
            accum += "<tr><td class=\"pathTile\" colspan=\"2\">";
            accum += createPathMenu(superNode, path.slice(1));
            accum += "</td></tr>";
        } else { 
            accum += "<tr class=\"tileRow\" onmouseover=\"highlightTile(this, " + subNode.uid + ");\">";
            accum += "<td";
            //accum += " onmouseover=\"hideChildren(_nodes[" + subNode.uid + "].superNode);\"";
            accum += " onclick=\"gotoNode(" + subNode.uid + ");\"";
            accum += " class=\"tile\"";
            if (!subNode.sub.length) 
            {
                accum += " colspan=\"2\"";
            }
            if (path)
            {
                accum += "><span class=\"menuText\">";
            } else {
                accum += "><span class=\"subMenuText\">";
            }
            accum += subNode.name;
            accum += "</span></td>";
            if (subNode.sub.length)
            {
                accum += "<td";
                //accum += " onmouseover=\"showMenu(this, " + subNode.uid + ");\"";
				accum += " class=\"tileArrow\"";
				if (_isGecko)
				{
					accum += " style=\"padding-bottom:1px;\"";
				}
				accum += ">";
                accum += "<span class=\"menuText\">" + ARROW_CHAR + "</span><br/>";
                accum += "</td>";
            }
            accum += "</tr>";
        }
    }
    accum += "</tbody></table>";
    if (scroll)
    {
        accum += "</div><div class=\"scrollButton\" onmouseover=\"hideHighlight(" + (superNode.depth+1) + "); this.className='scrollButton-armed';\" onmousedown=\"this.className='scrollButton-pressed';\" onmouseout=\"this.className='scrollButton';\" onmouseup=\"this.className='scrollButton-armed'; scrollMenu(this, true);\" align=\"center\">";
        accum += "&#9660;";
        accum += "</div>";
    }
    return accum;
}

function createRootMenu(path)
{
    var container = document.createElement("div");
    container.className = "menu";
    container.style.position = "relative";
    if (_isSafari)
    {
        container.style.width = 138;
    } else {
        container.style.width = 140;
    }
    container.style.zIndex = 100;

    var menuHtml = createMenu(_menuRoot.sub[_menuRoot.getIndex(path[0])], path);
    disableSelection(container);
    container.innerHTML = menuHtml;
    container.menuNode = _menuRoot;
    container.onmouseover = enterMenu;
    container.onmouseout = leaveMenu;

    return container;
}

function createPathMenu(superNode, path)
{
    var accum = "<table class=\"menuTable\" cellspacing=\"0\" cellpadding=\"0\" onmouseover=\"hideHighlights();\"";
    //accum += " style=\"width:50px;\"";
    accum += "><tbody>";
    var subNode = superNode;
    for (var i = 0; i < path.length; i++)
    {
        var pathElement = path[i];
        if (!pathElement)
        {
            continue;
        }
        subNode = subNode.sub[subNode.getIndex(pathElement)];
        if (!subNode)
        {
            continue;
        }

        var tileName = subNode.name;
        accum += emitHighlightTile(tileName, subNode.uid, i, path.length, subNode.sub.length, true);
    }
    accum += "</tbody></table>";
    return accum;
}


function animateNode(menuElement, tx, ty)
{
    if (!menuElement)
    {
        return;
    }

    var node = menuElement.menuNode;
    if (!node)
    {
        return;
    }

    node.startTime = 0;
    node.totalTime = ANIMATE_MS;
    node.dY = 0;
    node.dX = menuElement.offsetWidth;
    node.startX = tx - node.dX;
    node.startY = ty;
    _animationNodes[_animationNodes.length] = menuElement;
    animate();
}

var _animationNodes = new Array();
function animator()
{
    animate();
    setTimeout(animator, 0);
}
    
function isAnimating(node)
{
    for (var i = 0; i < _animationNodes.length; i++)
    {
        var n = _animationNodes[i];
        if (n == node || n == node.menu || n == node.scrollMenu)
        {
            return true;
        }
    }
    return false;
}

function getMinX(node)
{
    var sup = node.superNode;
    if (!isVisible(sup))
    {
        var m = node.getVisibleMenu();
        return getBounds(m).x;
    }

    return getMinX(sup) + MENU_PADDING;
}

function getMaxX()
{
    var winSize = getWindowSize();
    return winSize.w - MENU_PADDING;
}

function shiftNodes(node, dx)
{
    if (!node || !dx)
    {
        return;
    }

    var element = node.getVisibleMenu();
    if (!element)
    {
        return;
    }

    var newX = Math.max(element.offsetLeft + dx, getMinX(node));
    element.style.left = newX;
    var highlight = _highlightDivs[node.depth - 1];
    highlight.style.left = newX;
    highlight = _highlightArrowDivs[node.depth - 1];
    highlight.style.left = newX;
    shiftNodes(node.superNode, dx);
}

function animate()
{
    var now = new Date().getTime();

    var restRad = Math.PI/2;
    var startRad = Math.PI/2 - restRad;
    for (var i = 0; i < _animationNodes.length; i++)
    {
        var menuElement = _animationNodes[i];
        if (!menuElement) 
        {
            continue; 
        }

        if (!isDisplayed(menuElement))
        {
            _animationNodes.splice(i, 1);
            continue;
        }

        var node = menuElement.menuNode;
        var menuStyle = menuElement.style;
        if (node.startTime <= 0)
        {
            node.startTime = now;
            menuStyle.visibility = "visible";
        } else if (!isVisible(node)) {
            _animationNodes.splice(i, 1);
            continue;
        }

        var realTime = (now - node.startTime) / (node.totalTime * 1.0);
        if (realTime > 1)
        {
            realTime = 1;
        }
        //var time = 1 - ((1 + Math.cos(realTime * Math.PI)) / 2);
        //var time = Math.sin(realTime * Math.PI/2);
        //var time = 2 * (Math.sin(Math.PI/6 + realTime * Math.PI/3) - 0.5);
        //var time = (Math.sin(Math.PI/3 + realTime * Math.PI/6) - Math.sin(Math.PI/3)) / (1 - Math.sin(Math.PI/3));
        var time = (Math.sin(startRad + (realTime * restRad)) - Math.sin(startRad)) / (1 - Math.sin(startRad));
        var dx = Math.round(node.dX * time);
        var l = node.startX + dx;
        var t = node.startY + Math.round(node.dY * time);
        var menuWidth = menuElement.offsetWidth;
        var menuHeight = menuElement.offsetHeight;
        var c = "rect(" + 0 + "px " + menuWidth + "px " + menuHeight + "px " + (menuWidth - dx) + "px)";
        menuStyle.clip = c;
        menuStyle.left = l;
        menuStyle.top = t;
        var maxX = getMaxX();
        if (l + menuWidth > maxX)
        {
            var dx = maxX - (l + menuWidth);
            shiftNodes(node, dx);
            node.startX += dx;
        }

        if (realTime == 1)
        {
            _animationNodes.splice(i, 1);
            if (_isMacGecko)
            {
                menuStyle.zIndex = 100 + ((node.depth - 1) * 2);
            }

            if (node.tempTr)
            {
                highlightTile(node.tempTr, node.tempUid);
                node.tempTr = null;
                lockMenu(node.tempUid);
                node.tempUid = null;
            }
        }
    }
}

var _iconText = new Array();
function setIconText(id, text)
{
    _iconText[id - 1] = text;
}

function iconOver()
{
    this.className="armed";
    var textDiv = MM_findObj("sidebarIconText");
    var text = "";
    if (this.ordinal)
    {
        var text = _iconText[this.ordinal - 1];
    }
    textDiv.innerHTML = text;
}

function iconDown()
{
    this.className="pressed";
}

function iconUp()
{
    this.className="armed";
}

function iconOut()
{
    this.className="";
    var textDiv = MM_findObj("sidebarIconText");
    textDiv.innerHTML = "";
}

function initIcons()
{
    var iconContainer = MM_findObj("sidebarIcons");
    if (!iconContainer)
    {
        return;
    }
    var iconList = iconContainer.getElementsByTagName("img");
    for (var i = 0; i < iconList.length; i++)
    {
        var icon = iconList[i];
        icon.onmouseover = iconOver;
        icon.onmouseout = iconOut;
        icon.onmousedown = iconDown;
        icon.onmouseup = iconUp;
        icon.ordinal = i + 1;
    }
}
runOnLoad(initIcons);


function indexEntryOver(obj)
{
    var entry = findAncestorByClass(obj, "indexEntry") || findAncestorByClass(obj, "indexEntry-pressed");
    if (entry)
    {
        entry.className="indexEntry-armed";
    }
}

function indexEntryDown(obj)
{
    var entry = findAncestorByClass(obj, "indexEntry-armed") || findAncestorByClass(obj, "indexEntry");
    if (entry)
    {
        entry.className="indexEntry-pressed";
    }
}

function indexEntryUp(obj)
{
    var entry = findAncestorByClass(obj, "indexEntry-pressed") || findAncestorByClass(obj, "indexEntry");
    if (entry)
    {
        entry.className="indexEntry-armed";
    }
}

function indexEntryOut(obj)
{
    var entry = findAncestorByClass(obj, "indexEntry-armed") || findAncestorByClass(obj, "indexEntry-pressed");
    if (entry)
    {
        entry.className="indexEntry";
    }
}


function groupEntryOver(obj)
{
	var entry = obj.getElementsByTagName("img").item(0);
    if (entry)
    {
        entry.className="armed";
    }
}

function groupEntryDown(obj)
{
	var entry = obj.getElementsByTagName("img").item(0);
    if (entry)
    {
        entry.className="pressed";
    }
}

function groupEntryUp(obj)
{
	var entry = obj.getElementsByTagName("img").item(0);
    if (entry)
    {
        entry.className="armed";
    }
}

function groupEntryOut(obj)
{
	var entry = obj.getElementsByTagName("img").item(0);
    if (entry)
    {
        entry.className="";
    }
}
