/**
 * Copyright 2009 Victor Sim
 *
 * This menu script is free, you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * Official website for this menu script : http://www.axgui.com
 */
var z = 1000;

function menu_handler(class_name)
{
    if(class_name != null)
    {
        var roots = document.getElementsByTagName("*");
        class_name = class_name.replace(/[\s\;\,]+?/g, '|');
        var p = new RegExp('\\b(' + class_name + ')\\b');
        for(var x = 0; x < roots.length; x++)
        {
            var obj = (p.test(roots[x].className)) ? roots[x] : null;
            if(obj)
            {
                obj.style.zIndex = z--;
                var objs = obj.getElementsByTagName("li");
                if(objs)
                {
                    for (i=0; i < objs.length; i++)
                    {
                       objs[i].onmouseout = function()
                       {
                          for (j=0; j < this.childNodes.length; j++)
                          {
                             node = this.childNodes[j];
                             if (node.nodeName=="UL")
                             {
                                 node.style.display="none";
                             }
                          }
                       }
                       objs[i].onmouseover = function()
                       {
                          for (j=0; j < this.childNodes.length; j++)
                          {
                             node = this.childNodes[j];
                             if (node.nodeName=="UL")
                             {
                                 node.style.top=this.style.top;
                                 node.style.display="block";
                             }
                          }
                       }
                    }
                }
            }
        }
    }
}

window.onload = function()
{
   menu_handler("horizontal_menu option_menu vertical_menu");
}
