function MainMenu(ObjectName, BoxID, HideTimeout)
{
	this.ObjectName = ObjectName;
	this.BoxID = BoxID;
	this.HideTimeout = HideTimeout;
	this.sel = new Array(10);
	this.sel_it = 0;
	this.t = false;
	this.ht = 0;
	this.ie = navigator.userAgent.indexOf("MSIE") != -1 ? true : false;	
	this.items = new Array();
	var b = this.e(this.BoxID);
	this.loop(b, true, 1);
	b.onmouseover = function () { this.w3menu_object.toff(); };
	b.onmouseout = function () { this.w3menu_object.out(); };
}

MainMenu.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;
}

MainMenu.prototype.e = function(id)
{
	return document.getElementById(id);
}

MainMenu.prototype.toff = function()
{	
	if (this.t)
	{
		clearTimeout(this.ht);
		this.t = false;
	}
}

MainMenu.prototype.out = function()
{
	this.t = true;	
	this.ht = setTimeout(this.ObjectName+'.ol()', this.HideTimeout);
}

MainMenu.prototype.ol = function()
{	
	if (this.t) 
		this.c(1);
}

MainMenu.prototype.loop = function(b, h, level)
{	
	b.w3menu_object = this;
	if (b.childNodes.length == 0) 
		return;
		
	var ul, li, ar;
	var max = 0;
	for (var i = 0; i < b.childNodes.length; i++)
	{
		li = b.childNodes[i];
		if (li.tagName != 'LI') 
			continue;
					
		var ar = li.getElementsByTagName('A');
		if (ar.length === 0) 
			continue;
			
		var a = ar[0];
		a.w3menu_object = this;
		a.w3menu_index = this.items.length;
		
		a.onmouseover = function ()
		{
			if (level > 1)
			{
				if (this.offsetParent.getElementsByTagName('UL').length > 0)
					this.offsetParent.className = 'root-hover';
					
				this.offsetParent.style.backgroundColor = '#99e866';
				this.style.color = '#fff';
			}
			
			this.w3menu_object.s(this.w3menu_index); 
		};
		
		if (level > 1)
		{
			for (var j = 0; j < b.childNodes.length; j++)
			{
				_li = b.childNodes[j];
				if (_li.tagName != 'LI') 
					continue;

				var _ar = _li.getElementsByTagName('A');
				var _a = _ar[0];
				
				if (_a.innerHTML.length > max)
					max = _a.innerHTML.length;
			}
			
			var _temp = max * 7;
			
			if (_temp < 60)
				_temp = 60;
			
			a.style.width = _temp + 'px';
			
		}
		
		var ul = li.getElementsByTagName('UL');
		if (ul.length != 0)
		{
			this.items[this.items.length] = { 'item':a, 'box':ul[0], 'level':level };									
			this.loop(ul[0], false, level + 1);				
		}			
		else
			this.items[this.items.length] = { 'item':a, 'box':0, 'level':level };		
	}	
}

MainMenu.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].item.parentNode;	
	
	if (l == 1)
	{			
		b.style.top = d.offsetHeight-2 + 'px';
		b.style.left = '-1px';
		
		var ar = b.getElementsByTagName('A');
		for (var i = 0; i < ar.length; i++)
		{
			ar[i].onmouseout = function ()
			{
				this.style.color = '#545454';
				this.offsetParent.style.backgroundColor = '#fafafa';
				
				if (this.offsetParent.getElementsByTagName('UL').length > 0)
					this.offsetParent.className = 'root';
				
				this.offsetParent.style.borderRightColor = '#99e866';
				this.offsetParent.style.borderRightWidth = '1px';
				this.offsetParent.style.borderRightStyle = 'solid';
			};
		}
	}
	else
	{
		b.style.top = this.ie ? '-1px' : '-1px';
		b.style.left = i.parentNode.offsetWidth + 'px';
		
		var ar = b.getElementsByTagName('A');

		for (var i = 0; i < ar.length; i++)
			ar[i].style.color = '#545454';
			
		ar = b.getElementsByTagName('LI');

		for (var i = 0; i < ar.length; i++)
		{
			ar[i].onmouseover = function () { OverBackground(this); };
			ar[i].onmouseout = function () { OutBackground(this); };
		}
	}
	
	b.style.display = 'block';
	this.sel[this.sel_it] = index;
	this.sel_it++;	
}

function OverBackground(Item)
{
	var ar = Item.getElementsByTagName('A');
	ar[0].style.color = '#fff';
	Item.style.backgroundColor = '#99e866';
}

function OutBackground(Item)
{
	var ar = Item.getElementsByTagName('A');
	ar[0].style.color = '#545454';
	Item.style.backgroundColor = '#fafafa';
}

MainMenu.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--;		
		}
	}	
}

MainMenu.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);
}