window.onload = init;

function killMenu()
{
    try
    {
        canhide = true;
        hideMenu();
    } catch(e) {}
    return false;
}

function hideMenu()
{
    try
    {
        if(canhide) hide(subblock);
    } catch(e){}
    return false;
}

function stopMenu()
{
    try
    {
        canhide = true;
        setTimeout(hideMenu, 1588);
    } catch(e) {}
    return false;
}

function showMenu(n)
{
    try
    {
         killMenu();
         canhide = true;
         var q = n.getAttribute("menunodid");
         foreach(
            function(m)
                {
                    var t = m.getAttribute("menuparid");
                    [show, hide][q==t?0:1](m);
                },
                subnodes);
         position(subblock, n, "bl", 0, 0);
         show(subblock);
    } catch(e) {}
    return false;
}

function init()
{
    self.subnodes = filter(function(n){ return n.getAttribute("menuparid"); }, document.getElementsByTagName("DIV"));
    self.subblock = filter(function(n){ return "upmenu"==n.className; }, document.getElementsByTagName("DIV"))[0];
    self.canhide = true;
    killMenu();
    var y = function(){ return canhide = false; },
        x = reduce(function(n, r)
                {
                    n.onmouseover = function(){ return showMenu(n); };
                    n.onmouseout = stopMenu;
                    return r || n;
                },
                filter(function(n){ return n.getAttribute("menunodid"); },
                       document.getElementsByTagName("TD")),
                null).parentNode;
    x.onmouseout = stopMenu;
    x.onmouseover = y;
    subblock.onmouseover = y;
    subblock.onmouseout = stopMenu;
    subblock.style.position = "absolute";
}

// self["$"] = function(n) { return document.getElementById(n); };
function show(n) { n.style.display = ""; }
function hide(n) { n.style.display = "none"; }
function foreach(f, a, s)
{
    a = ("undefined"==typeof(a) ? [] : a);
    for(var i=0; i<a.length; i++) f(a[i], s);
}
function reduce(f, a, s)
{
    var i, r = ("undefined"!=typeof(s) ? s : null);
    a = ("undefined"==typeof(a) ? [] : a);
    for(i=0; i<a.length; i++) r = f(a[i], r);
    return r;
}
function filter(f, a, s)
{
    var i, l = [];
    a = ("undefined"==typeof(a) ? [] : a);
    for(i=0; i<a.length; i++) if(f(a[i], s)) l.push(a[i]);
    return l;
}
function position(obj, al, pnt, ox, oy)
{
    try {
        var hal = al,
            x = 0,
            y = 0,
            m = 0;
        while(hal.tagName!="BODY") {
            x += hal.offsetLeft;
            y += hal.offsetTop;
            hal = hal.offsetParent;
        }
        x = (pnt=="tr" || pnt=="br") ? x + al.clientWidth : x;
        y = (pnt=="br" || pnt=="bl") ? y + al.clientHeight : y;
        obj.style.top = y + oy + "px";
        obj.style.left = x + ox + "px";
    } catch(e) {}
}