/*

w3menu_h - скрипт многоуровневого вертикального меню, с неограниченным количеством уровней. Меню может раскрываться как вправо, так и влево
версия: 1.0 от 04.08.2008
разработчики: http://w3box.ru
тип лицензии: freeware
w3box.ru © 2008

*/

function w3menu_v(obj_name, box_id, left, hide_timeout)
{
	this.obj=obj_name;
	this.box_id=box_id;
	this.left=left;
	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(); };
	this.ie=(navigator.userAgent.indexOf("MSIE")!=-1);
}

w3menu_v.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_v.prototype.e=function(id)
{
	return document.getElementById(id);
}

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

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

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

w3menu_v.prototype.loop=function(b, level)
{	
	b.w3menu_object=this;	
	var r=b.rows;			
	var c, ar, a, t, d;
	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); };	
		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], level+1);				
		}
		else this.items[this.items.length]={ 'item':a, 'box':0, 'div':0, 'level':level };	
	} 
}

w3menu_v.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;	
	b.style.top='-1px';
	if (this.left) b.style.right=d.offsetWidth-(this.ie?1:0)+'px';
	else b.style.left=d.offsetWidth+'px';	
	b.style.display='block';
	this.sel[this.sel_it]=index;
	this.sel_it++;	
}

w3menu_v.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_v.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);
}

