
function w3menu_h(obj_name, box_id, hide_timeout)
{
    this.obj=obj_name;
    this.box_id=box_id;
    this.hide_timeout=hide_timeout;
    this.sel=new Array(10);
    this.sel_it=0;
    this.t=false;
    this.ht=0;  
    this.items=new Array();
    var b=this.e(this.box_id);
    this.loop(b, true, 1);
    b.onmouseover=function () { this.w3menu_object.toff(); };
    b.onmouseout=function () { this.w3menu_object.out(); };
}

w3menu_h.prototype.in_sel=function(value) 
{
    if (this.sel_it==0) return false;
    for (var i=0; i<this.sel_it; i++)
    {
        if (this.sel[i]==value) return true;
    }
    return false;
}

w3menu_h.prototype.e=function(id)
{
    return document.getElementById(id);
}

w3menu_h.prototype.toff=function()
{   
    if (this.t)
    {           
        clearTimeout(this.ht);
        this.t=false;
    }
}

w3menu_h.prototype.out=function()
{
    this.t=true;    
    this.ht=setTimeout(this.obj+'.ol()', this.hide_timeout);
}

w3menu_h.prototype.ol=function()
{   
    if (this.t) this.c(1);
}

w3menu_h.prototype.loop=function(b, h, level)
{   
    b.w3menu_object=this;
    var ar, a, d, c, r, t;  
    if (h)
    {
        c=b.rows[0].cells;
        for (var i=0; i<c.length; i++)
        {           
            ar=c[i].getElementsByTagName('A');
            if (ar.length===0) continue;
            a=ar[0];
            a.w3menu_object=this;
            a.w3menu_index=this.items.length;
            a.onmouseover=function () { this.w3menu_object.s(this.w3menu_index); }; 
            t=c[i].getElementsByTagName('TABLE');
            if (t.length!=0)
            {
                ar=c[i].getElementsByTagName('DIV');
                if (ar.length===0) continue;
                d=ar[0];
                this.items[this.items.length]={ 'item':a, 'box':t[0], 'div':d, 'level':level };                                 
                this.loop(t[0], false, level+1);                
            }           
            else this.items[this.items.length]={ 'item':a, 'box':0, 'div':0, 'level':level };   
        }
    }
    else
    {       
        r=b.rows;           
        for (var i=0; i<r.length; i++)
        {               
            c=r[i].cells[0];
            ar=c.getElementsByTagName('A');
            if (ar.length===0) continue;
            a=ar[0];
            a.w3menu_object=this;
            a.w3menu_index=this.items.length;
            a.onmouseover=function () { this.w3menu_object.s(this.w3menu_index, this.tagName); };   
            t=c.getElementsByTagName('TABLE');
            if (t.length!=0)
            {
                ar=c.getElementsByTagName('DIV');
                if (ar.length===0) continue;
                d=ar[0];
                this.items[this.items.length]={ 'item':a, 'box':t[0], 'div':d, 'level':level };                     
                this.loop(t[0], false, level+1);                
            }
            else this.items[this.items.length]={ 'item':a, 'box':0, 'div':0, 'level':level };   
        }       
    }
}

w3menu_h.prototype.o=function(index)
{       
    if (this.in_sel(index)) return;
    var i=this.items[index].item;
    var b=this.items[index].box;
    var l=this.items[index].level;
    var d=this.items[index].div;
    if (l==1)
    {           
        b.style.top=d.offsetHeight+'px';
        b.style.left='-1px';        
    }
    else
    {
        b.style.top='-1px';
        b.style.left=d.offsetWidth+'px';
    }   
    b.style.display='block';
    this.sel[this.sel_it]=index;
    this.sel_it++;  
}

w3menu_h.prototype.c=function(l)
{
    if (l<=this.sel_it)
    {           
        for (var i=this.sel_it-1; i>=l-1; i--) 
        {               
            this.items[this.sel[i]].box.style.display='none';
            this.sel_it--;          
        }
    }   
}

w3menu_h.prototype.s=function(index)
{   
    o=this.items[index];    
    if (this.in_sel(index))
    {
        this.c(o.level+1);
    }
    else this.c(o.level);
    if (o.box!==0) this.o(index);
}

