function menu_init()
{
	var top_ul = document.getElementById('menu').getElementsByTagName('ul')[0];
	var top_lis = get_children(top_ul, 'li');
	  
	var sub_uls;
	var sub_lis;
	  
	var left;
	  
	var menu_width = top_ul.offsetWidth;
	var el_width = 0;
	  
	var i;
	var j;
	var k;
	
	for(i = 0;i < top_lis.length;i++)
	{
		el_width += top_lis[i].offsetWidth;
	}
	
	var between_width = Math.floor((menu_width - el_width) / (top_lis.length - 1));
	
	for(i = 1;i < top_lis.length;i++)
	{
		top_lis[i].style.marginLeft = (between_width - menu_between_offset) + 'px';
	}
	
	for(i = 0;i < top_lis.length;i++)
	{
		if((sub_ul = top_lis[i].getElementsByTagName('ul')[0]) != undefined)
		{
			sub_lis = get_children(sub_ul,'li');
			
			el_width = 0;
			for(k = 0;k < sub_lis.length;k++)
			{
				el_width += sub_lis[k].offsetWidth;
				
			}
			sub_ul.style.width = (el_width + 5) + 'px';
			sub_lis[k-1].firstChild.style.background = 'none';
			
			if(document.getElementsByTagName('body')[0].clientWidth)
			{
				
				if((find_pos(sub_ul)[0] + el_width) > document.getElementsByTagName('body')[0].clientWidth)
				{
					left = (find_pos(top_lis[i])[0] + sub_ul.offsetWidth) - (find_pos(top_lis[top_lis.length - 1])[0] + top_lis[top_lis.length - 1].offsetWidth);
					sub_ul.style.left = '-' + (left - 5) + 'px';
				}
			}
			
			else
			{
			}
		}
	}

}

function find_pos(obj)
{
	var curleft = curtop = 0;
	
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
	}
		
	return [curleft,curtop];
}

function check_node(node, filter)
{
	return (filter == null || node.nodeName.toUpperCase() == filter.toUpperCase());
}

function get_children(node, filter)
{
	var result = new Array();
	var children = node.childNodes;
	for(var i = 0; i < children.length; i++)
	{
		if(check_node(children[i], filter)) result[result.length] = children[i];
	}
	return result;
}
