var counter;
clearTimeout(counter);
counter = null;
var locked = 0;
var child_on = 0;

var counter_sub;
clearTimeout(counter_sub);
counter_sub = null;

var menu_on = 0;
function init_menu()
{
	$('1').onmouseover = function() {
	showmenu('1');
	hidesub(0);
	};
	$('2').onmouseover = function() {
	showmenu('2');
	hidesub(0);
	};
	$('3').onmouseover = function() {
	showmenu('3');
	hidesub(0);
	};
	$('4').onmouseover = function() {
	showmenu('4');
	hidesub(0);
	};
	$('5').onmouseover = function() {
	showmenu('5');
	hidesub(0);
	}
	$('6').onmouseover = function() {
	clearTimeout(counter);
	hide(0);
	hidesub(0);
	$('child_bg').style.top = '-1000px';
	$('child_bg').style.left = '-1000px';
	$('child_bg_pad').style.top = '-1000px';
	$('child_bg_pad').style.left = '-1000px';
	}
	$('7').onmouseover = function() {
	clearTimeout(counter);
	hide(0);
	hidesub(0);
	$('child_bg').style.top = '-1000px';
	$('child_bg').style.left = '-1000px';
	$('child_bg_pad').style.top = '-1000px';
	$('child_bg_pad').style.left = '-1000px';
	}
	$('null').onmouseover = function() {
	clearTimeout(counter);
	force_hide();
	hidesub(0);
	$('child_bg').style.top = '-1000px';
	$('child_bg').style.left = '-1000px';
	$('child_bg_pad').style.top = '-1000px';
	$('child_bg_pad').style.left = '-1000px';
	}
	$('nav').onmouseout = function() {
		if(counter != null) clearTimeout(counter);
		counter = setTimeout('hide(0)', 100);
	}
}


/*---------- Show menu functions ------------------*/
function showmenu(id)
{
	$('child_bg').style.top = '-1000px';
	$('child_bg').style.left = '-1000px';
	$('child_bg_pad').style.left = '-1000px';
	$('child_bg_pad').style.top = '-1000px';
	if(counter != null) clearTimeout(counter);
	hide(id);
	hidesub(0);
	show(id);
}

function show(id)
{
	cont = document.getElementById('s'+id);
	pos_x = findPosX(document.getElementById(id));
	left_pos = pos_x;
	if(id == '4')
	{
		left_pos += 9;
	}
	if(id == '1')
	{
		left_pos += 5;
	}
	pos_y = findPosY(document.getElementById(id));
	cont.style.display = 'block';
	height = cont.offsetHeight;
	switch(id)
	{
		case '1' : {
			width = 140;
			padding = 28;
		}; break;
		case '2' : {
			width = 190;
			padding = 10; 
		}; break;
		case '3' : {
			width = 160;
			padding = 16;
		}; break;
		case '4' : {
			width = 120;
			padding = 16;
		}; break;
		case '5' : {
			width = 150;
			padding = 20;
		}; break;
	}
	iewidth = 0;
	iewwidth = 0;
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		iewidth = 10;
		iewwidth = 20;
	}
	if(id != 3)
	{
		cont.style.left = parseInt(left_pos) + iewidth + 'px';
		cont.style.top = 180 - height + 60 + 'px';
		cont.style.width = width + iewwidth + 'px';
		cont.style.paddingLeft = padding + 'px';
		$('sub_bg').style.left = parseInt(left_pos) + iewidth + 'px';
		if((id == 1) && (navigator.appName == 'Microsoft Internet Explorer'))
		{
			$('sub_bg').style.width = width + iewwidth + 10 + 'px';
		}
		else
		{
			$('sub_bg').style.width = width + iewwidth + 'px';
		}
		$('sub_bg').style.height = height + 'px';
		$('sub_bg').style.top = 180 - height + 60 + 'px';
		$('sub_bg').style.paddingLeft = padding + 'px';
	}
	else
	{
		cont.style.left = parseInt(left_pos) + iewidth - 45 + 'px';
		cont.style.top = 180 - height + 60 + 'px';
		cont.style.width = width + iewwidth - 15 +  'px';
		cont.style.paddingLeft = padding + 'px';
		$('sub_bg').style.left = parseInt(left_pos) + iewidth - 45 + 'px';
		$('sub_bg').style.width = width + iewwidth - 15 + 'px';
		$('sub_bg').style.height = height + 'px';
		$('sub_bg').style.top = 180 - height + 60 + 'px';
		$('sub_bg').style.paddingLeft = padding + 'px';
	}
	$(id).style.marginTop = '-62px';
}

function showsubmenu(id)
{
	if(counter_sub != null) clearTimeout(counter_sub);
	hidesub(id);
	showsub(id)
}

function showsub(id)
{
	if(id == '6')
	{
		cont_id = '5';
	}
	else
	{
		cont_id = id;
	}
	child = document.getElementById('child'+id);
	if(child.offsetHeight == 0)
	{
		child.style.display = 'block';
		
		navv = document.getElementById(cont_id);
		pos_y = findPosY(navv);
		
		cont = document.getElementById('s'+cont_id);
		height = cont.offsetHeight;
		cont.style.top = 242 - height - 8 + 'px';
		
		
		child_left = findPosX(child);
		child_top = findPosY(child);
		child.style.paddingLeft    = '25px';
		child.style.paddingTop     = '3px';
		child.style.paddingBottom  = '3px';
		$('sub_bg').style.top      = 242 - height - 8 + 'px';
		$('sub_bg').style.height   = cont.offsetHeight + 'px';
		if(id == 2)
		{
			$('child_bg').style.left   = child_left + 10 + 'px';
		}
		else
		{
			$('child_bg').style.left   = child_left + 'px';
		}
		$('child_bg').style.top    = child_top + 'px';
		bw = bwcheck();
		if(navigator.appName == 'Microsoft Internet Explorer' && id == '2' && bw.ie6 == 0)
		{
			$('child_bg').style.width  = child.offsetWidth  - 10 + 'px';
		} 
		else
		{
			if(id == 2)
			{
				$('child_bg').style.width  = child.offsetWidth - 10 + 'px';
			}
			else
			{
				$('child_bg').style.width  = child.offsetWidth + 'px';
			}
		}
		$('child_bg_pad').style.top = child_top + 'px';
		$('child_bg_pad').style.height = child.offsetHeight + 'px';
		if(id == '3' || id == '6')
		{
			$('child_bg').style.height = child.offsetHeight + 6 + 'px';
			$('child_bg_pad').style.height = child.offsetHeight + 4 + 'px';
		}
		else
		{
			$('child_bg').style.height = child.offsetHeight + 'px';
		}
		if(id != '3')
		{
			$('child_bg_pad').style.left = child_left - 1 + 'px';
			$('child_bg_pad').style.width = '21px';
		}
		if(id == '3')
		{
			$('child_bg').style.left   = child_left +  'px';
			$('child_bg').style.height = child.offsetHeight - 1 +  'px';
			$('child_bg_pad').style.left = child_left +  'px';
			$('child_bg_pad').style.width = '19px';
			$('child_bg_pad').style.height = child.offsetHeight - 3 + 'px';
		}
		if(id == '2')
		{
			$('child_bg_pad').style.left = child_left + 10 + 'px';
			$('child_bg_pad').style.width = '10px';
		}
	}
}

/* --------- Hide menus functions -------------- */
function hide(id)
{
	for(i = 1; i <= 5; i++)
	{
		try {
			if(i != id)
			{
				$('s'+i).style.display = 'none';
				$('sub_bg').style.left = '-1000px';
				$('sub_bg').style.top = '-1000px';
				idd = document.getElementById(i);
				if(idd.className != 'nav-activ')
				{
					idd.style.marginTop = '0px';
				}
			}
		}
		catch(e) {};
	}
	hidesub(0);
	$('child_bg').style.top = '-1000px';
	$('child_bg').style.left = '-1000px';
	$('child_bg').style.width = '0px';
	$('child_bg').style.height = '0px';
	$('child_bg_pad').style.left = '-1000px';
	$('child_bg_pad').style.top = '-1000px';
	$('child_bg_pad').style.height = '0px';
	$('child_bg_pad').style.width = '0px';
}

function force_hide()
{
	for(i = 1; i <= 5; i++)
	{
		try {
               $('s'+i).style.display = 'none';
			   $('sub_bg').style.left = '-1000px';
			   $('sub_bg').style.top = '-1000px';
			   $('child_bg').style.left = '-1000px';
			   $('child_bg').style.top = '-1000px';
			   $('child_bg_pad').style.left = '-1000px';
			   $('child_bg_pad').style.top = '-1000px';
		}
		catch(e) {};
	}
}

function hidesub(id)
{
	for(i = 1; i <= 6; i++)
	{
		try {
			if(i != id)
			{
				cont = document.getElementById('s'+i);
				child = document.getElementById('child'+i);
				
				child_height = child.offsetHeight;
				child.style.display = 'none';
				child.style.paddingLeft = '0px';
				child.style.paddingTop = '0px';
				child.style.paddingBottom = '0px';
				if(child_height)
				{
					cont.style.top = 242 - cont.offsetHeight - 2 + 'px';
					$('sub_bg').style.top = 242 - cont.offsetHeight - 2 + 'px';
					$('sub_bg').style.height = cont.offsetHeight + 'px';
					$('child_bg').style.top = '-1000px';
					$('child_bg').style.left = '-1000px';
					$('child_bg').style.width = '0px';
					$('child_bg').style.height = '0px';
					$('child_bg_pad').style.left = '-1000px';
					$('child_bg_pad').style.top = '-1000px';
					$('child_bg_pad').style.height = '0px';
					$('child_bg_pad').style.width = '0px';
				}
			}
		}
		catch(e) {};
	}
}


/* ---------------- Utiliy functions ------------ */
function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}

function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {posLeft += obj.offsetLeft; obj = obj.offsetParent;}
	return posLeft;
}

function clearTimer()
{
	if(counter != null) clearTimeout(counter);
}
function clearsubTimer()
{
	if(counter_sub != null) clearTimeout(counter_sub);
}

function setTimer()
{
	if(counter != null) clearTimeout(counter);
	counter = setTimeout('hide(0)', 200);
}

function setsubTimer()
{
	if(counter_sub != null) clearTimeout(counter_sub);
	counter_sub = setTimeout('hidesub(0)', 200);
}

