var timeout;
var timeoutOut;
var timeoutClear;
var currTab = "";
var isOut = "true";
//var header_bgr = 'url(http://localhost/autocacak.co.rs/style/' + header_style + '/T1-andromeda_body.png)';
//var header_bgr_over = 'url(http://localhost/autocacak.co.rs/style/' + header_style + '/T1-andromeda_body.png)';
var delay = 1000;

function getTime()
{
	var currentTime = new Date();
	var hours = currentTime.getHours();
	var minutes = currentTime.getMinutes();
	var seconds = currentTime.getSeconds();
	if (minutes < 10)
		minutes = "0" + minutes;
	if (seconds < 10)
		seconds = "0" + seconds;
	return hours + ":" + minutes + ":" + seconds;
}

// ---------------------------------------------
//	S E C O N D   L E V E L
// ---------------------------------------------
function HideAllSecondLevelItems()
{
	for (i = 1; i <= 20; i++)
	{
		if (document.getElementById('subMenu' + i) != null)
		{			
			document.getElementById('subMenu' + i).style.display = 'none';
		}
	}
}
function ClearAllClassNames()
{
	for (i = 1; i <= 20; i++)
	{
		if (document.getElementById('liTab' + i) != null)
		{			
			document.getElementById('liTab' + i).className = "";
		}
	}
}
function ClearCurrTab()
{
	currTab = "";
}
function ShowSecondLevel(id, id2)
{
	currTab = id;
	isOut = "false";
	clearTimeout(timeoutOut);
	ClearAllClassNames();
	if (selectedTab != "") {
		document.getElementById(selectedTab).className = 'tabCurrentOut';
	}
	if (document.getElementById(id2) != null)
	{
		document.getElementById(id2).className = 'tabSelected';
	}
	timeout = setTimeout("ShowSecondLevelAfterDelay('" + id + "')", 200);
	
	/*var x = document.getElementById("hMain");
	if (x.currentStyle)
		var y = x.currentStyle['backgroundImage'];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue('background-image');
	
	k = y.replace(/"/g, "");
	
	if (k == header_bgr)
	{
		//alert('ok');
		ShowSecondLevelNow(id, id2);
	}
	else
	{
		timeout = setTimeout("ShowSecondLevelAfterDelay('" + id + "')", 100);
	}*/
}
function ShowSecondLevelAfterDelay(id)
{
	if (currTab == id)
	{
		isOut = "false";
		clearTimeout(timeoutOut);
 		HideAllSecondLevelItems();
		if (document.getElementById(id) != null)
		{
			document.getElementById(id).style.display = 'inline';
		}
		//ShowBackground(true);
		
		clearTimeout(timeout);
	}
}
function ShowSecondLevelNow(id, id2)
{
	isOut = "false";
	clearTimeout(timeoutOut);
	HideAllSecondLevelItems();
	if (document.getElementById(id) != null)
	{
		document.getElementById(id).style.display = 'inline';
	}
	if (selectedTab != id2)
	{
		ClearAllClassNames();
		if (document.getElementById(id2) != null)
		{
			document.getElementById(id2).className = 'tabSelected';
		}
		if (selectedTab != "")
			document.getElementById(selectedTab).className = 'tabCurrentOut';
		//ShowBackground(true);
	}
}
function ShowCurrentSecondlevel()
{
	if (isOut == "false")
	{
 		isOut = "true";
		timeoutOut = setTimeout("ShowCurrentSecondlevelAfterDelay()", delay);
	}
}
function ShowCurrentSecondlevelAfterDelay()
{
	if (isOut == "true")
	{
		clearTimeout(timeoutOut);
  		HideAllSecondLevelItems();
		ClearAllClassNames();
		if  (selectedSubmenu != "" && selectedTab != "")
		{
			document.getElementById(selectedSubmenu).style.display = "inline";
			document.getElementById(selectedTab).className = "tabCurrent";
		}
		//document.getElementById("hMain").style.backgroundImage = header_bgr;
		//ShowBackground(false);
	}
}
function ShowCurrentSecondlevelNow()
{
	HideAllSecondLevelItems();
	ClearAllClassNames();
	//alert(selectedSubmenu + ' - ' + selectedTab);
	if  (selectedSubmenu != "" && selectedTab != "")
	{
		document.getElementById(selectedSubmenu).style.display = "inline";
		document.getElementById(selectedTab).className = "tabCurrent";
	}
	//document.getElementById("hMain").style.backgroundImage = header_bgr;
	//ShowBackground(false);
	clearTimeout(timeoutOut);
}
function ShowCurrentSecondlevelFF()
{
	if (isOut == "false")
	{
 		isOut = "true";
		timeoutOut = setTimeout("ShowCurrentSecondlevelFFAfterDelay()", delay);
	}
}
function ShowCurrentSecondlevelFFAfterDelay()
{
	if (isOut == "true")
	{
		//alert(timeoutOut);
		clearTimeout(timeoutOut);
		bwGecko = (navigator.userAgent.indexOf('Gecko') != -1) ? "True" : "False";
		//alert(bwGecko);
		HideAllSecondLevelItems();
			ClearAllClassNames();
			if  (selectedSubmenu != "" && selectedTab != "")
			{
				document.getElementById(selectedSubmenu).style.display = "inline";
				document.getElementById(selectedTab).className = "tabCurrent";
			}
		/*if (bwGecko == "False")
		{
			HideAllSecondLevelItems();
			ClearAllClassNames();
			if  (selectedSubmenu != "" && selectedTab != "")
			{
				document.getElementById(selectedSubmenu).style.display = "inline";
				document.getElementById(selectedTab).className = "tabCurrent";
			}
		}*/
	}
}
function CancelBubble()
{
	event.cancelBubble=true;
	isOut = "false";
	clearTimeout(timeoutOut);
}

// ----------------------------------------------------
	//	S U B M E N U   L E V E L   3   H O R I Z O N T A L
	// ----------------------------------------------------
function ShowHML3Submenu(idMenu, id, RTL)
{
	var navigation = document.getElementById("navh");
	var topNav = findPosY(navigation);
	var left = findPosX(idMenu);
	var topDiff = topNav + 23;
	var leftDiff = 0;
	if (RTL == true)
	{
		leftDiff = left - (235 - idMenu.offsetWidth) + 3;
	}
	else
	{
		leftDiff = left + 2;
	}
	bwIE = (navigator.appVersion.indexOf("MSIE") != -1) ? "True" : "False";
	bwIE60 = (navigator.appVersion.indexOf("MSIE 6.0") != -1) ? "True" : "False";
	bwGecko = (navigator.userAgent.indexOf("Gecko") != -1) ? "True" : "False";
	bwFirefox3 = (navigator.userAgent.indexOf("Firefox/3") != -1) ? "True" : "False";
	bwFirefox3Beta = (navigator.userAgent.indexOf("Shiretoko/3") != -1) ? "True" : "False";
	bwSafari = (navigator.userAgent.indexOf("Safari") != -1) ? "True" : "False";
	bwOpera = (navigator.userAgent.indexOf("Opera") != -1) ? "True" : "False";
	bwChrome = (navigator.userAgent.indexOf("Chrome") != -1) ? "True" : "False";
	if (bwIE == "False")
	{
		topDiff--;
	}
	if (bwGecko == "True")
	{
		topDiff++;
	}
	if (bwFirefox3 == "True" || bwFirefox3Beta == "True")
	{
		topDiff = topDiff - 3;
		leftDiff = leftDiff - 2;
	}
	if (bwSafari == "True")
	{
		topDiff = topDiff - 3;
		leftDiff = leftDiff - 2;
	}
	if (bwOpera == "True")
	{
		topDiff = topDiff - 3;
		leftDiff = leftDiff - 2;
	}
	if (document.getElementById(id) != null)
	{
		document.getElementById(id).style.top = topDiff + "px";
		document.getElementById(id).style.left = leftDiff + "px";
	}
	if (bwIE60 == "True")
	{
		document.getElementById(id).style.display = "inline";
	}
}
function HideHML3Submenu(idMenu, id)
{
	bwIE60 = (navigator.appVersion.indexOf("MSIE 6.0") != -1) ? "True" : "False";
	if (bwIE60 == "True")
	{
		document.getElementById(id).style.display = "none";
	}
}
function ShowHML3Menu(idMenu, id)
{
	if (document.getElementById(idMenu) != null)
	{
		document.getElementById(idMenu).className = "menuLevel3Hover";
	}
	bwIE60 = (navigator.appVersion.indexOf("MSIE 6.0") != -1) ? "True" : "False";
	if (bwIE60 == "True")
	{
		document.getElementById(id).style.display = "inline";
	}
}
function HideHML3Menu(idMenu, id)
{
	if (document.getElementById(idMenu) != null)
	{
		document.getElementById(idMenu).className = "menuLevel3Normal";
	}
	bwIE60 = (navigator.appVersion.indexOf("MSIE 6.0") != -1) ? "True" : "False";
	if (bwIE60 == "True")
	{
		document.getElementById(id).style.display = "none";
	}
}
function HideHML3MenuSel(idMenu, id)
{
	if (document.getElementById(idMenu) != null)
	{
		document.getElementById(idMenu).className = "menuLevel3Selected";
	}
	bwIE60 = (navigator.appVersion.indexOf("MSIE 6.0") != -1) ? "True" : "False";
	if (bwIE60 == "True")
	{
		document.getElementById(id).style.display = "none";
	}
}
	
	
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}