var W3CDOM = (document.createElement && document.getElementsByTagName);
var mouseOvers = [];
var mouseOuts = [];
var moIdx = 0;

window.onload = init;

function init()
{
    // die gracefully if advanced javascript isn't supported
    if (!W3CDOM) return;

    // handle the standard mouseovers, used for the menu
    mouseoverInit('mouseovers', false);

    // engineering mouseovers
    mouseoverInit('plainmouseovers', false);
}

function mouseoverInit(element_id, fontgen)
{
    var nav = document.getElementById(element_id);
    if (nav != null)
    {
        moIdx++;
        mouseOvers[moIdx] = [];
        mouseOuts[moIdx] = [];
        var imgs = nav.getElementsByTagName('img');
        for (var i = 0; i < imgs.length; i++)
        {
            if (imgs[i].parentNode.tagName == "A")
            {
                if (imgs[i].realSrc != null) {
                    src = imgs[i].realSrc;
                } else {
                    src = imgs[i].src;
                }
                imgs[i].idx = moIdx;
                imgs[i].onmouseover = mouseGoesOver;
                imgs[i].onmouseout = mouseGoesOut;
                mouseOuts[moIdx][i] = new Image();
                mouseOuts[moIdx][i].src = src;
                mouseOvers[moIdx][i] = new Image();
                if (fontgen == true)
                {
                    mouseOvers[moIdx][i].src = imgs[i].src + "&mouseover=true";
                }
                else
                {
                    var suffix = src.substring(src.lastIndexOf('.'));
                    mouseOvers[moIdx][i].src = src.substring(0,src.lastIndexOf('.')) + "_on" + suffix;
                }
                imgs[i].number = i;
            }
        }
    }
}

function mouseGoesOver()
{
    this.src = mouseOvers[this.idx][this.number].src;
}

function mouseGoesOut()
{
    this.src = mouseOuts[this.idx][this.number].src;
}

function end()
{
    return false;
}
