﻿/*

w3menu_h - скрипт многоуровневого горизонтального меню, с неограниченным количеством уровней
версия:
 1.0 от 01.02.2008
разработчики: http://w3box.ru
тип лицензии: freeware
w3box.ru © 2008

*/
//########################## preload images for horizontal menu
  imgPreload1 = new Image();
  imgPreload1.src = "/img/menu/about_us_green.gif";
  
  imgPreload1_1 = new Image();
  imgPreload1_1.src = "/img/menu/about_us.gif";
  
  imgPreload2 = new Image();
  imgPreload2.src = "/img/menu/disciplines_green.gif";
  
  imgPreload2_1 = new Image();
  imgPreload2_1.src = "/img/menu/disciplines.gif";
  
  imgPreload3= new Image();
  imgPreload3.src = "/img/menu/portfolio_green.gif";
  
  imgPreload3_1 = new Image();
  imgPreload3_1.src = "/img/menu/portfolio.gif";
  
  imgPreload4= new Image();
  imgPreload4.src = "/img/menu/press_room_green.gif";
  
  imgPreload4_1 = new Image();
  imgPreload4_1.src = "/img/menu/press_room.gif";
  
  imgPreload5= new Image();
  imgPreload5.src = "/img/menu/careers_green.gif";
  
  imgPreload5_1 = new Image();
  imgPreload5_1.src = "/img/menu/careers.gif";  
  
//#############################


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;	
      if (h)
          {
 	    var c=b.rows[0].cells;
		for (var i=0; i<c.length; i++)
   		 {
 	     	   var ar=c[i].getElementsByTagName('A');
                      if (ar.length===0) continue;
                   var a=ar[0];
  	           a.w3menu_object=this;
                   a.w3menu_index=this.items.length;
                   a.onmouseover=function () 
                      { 
                         this.w3menu_object.s(this.w3menu_index); 
                      };	
                   var t=c[i].getElementsByTagName('TABLE');
                   if (t.length!=0)
               	       {
                          this.items[this.items.length]={ 'item':a, 'box':t[0], 'div':c[i].firstChild, 'level':level };
  			  this.loop(t[0], false, level+1);
 	 	       }		
	    	   else this.items[this.items.length]={ 'item':a, 'box':0, 'div':0, 'level':level };	
                 }
  	 }
     else
        {
          var r=b.rows;
          for (var i=0; i<r.length; i++)
            {
                var c=r[i].cells[0];
                var ar=c.getElementsByTagName('A');
                if (ar.length===0) continue;
                var 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); 
                     };	
                var t=c.getElementsByTagName('TABLE');
                if (t.length!=0)
         	  {
                    this.items[this.items.length]={ 'item':a, 'box':t[0], 'div':c.firstChild, '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);
  }
