/*
 *   TOP MENU
 *   [01.05.2011, TC]
 */

function HiTopMenuSubTD(Obj, HasHref)
{
	Obj.className = "top_menu_sub_td_hi" + ((HasHref) ? "_href" : "");
}

function LoTopMenuSubTD(Obj)
{
	Obj.className = "top_menu_sub_td";
}

function HiImg(Obj)
{
	if (Obj.src.indexOf("_hi.png") < 0)
	{
		Obj.src = Obj.src.replace(".png", "_hi.png");
	}
}
function LoImg(Obj)
{
	if (Obj.src.indexOf("_hi.png") > 0)
	{
		Obj.src = Obj.src.replace("_hi.png", ".png");
	}
}

function GoToUrl(URL)
{
	location.href = URL;
}

var HideTimeout = null;

var VisibleMainImgID   = null;
var VisibleSubMenusIDs = [];

function ShowSubMenus(MainImgID, SubMenusIDs)
{
	if (HideTimeout != null)
	{
		clearTimeout(HideTimeout);
		HideTimeout = null;
	}

	if (MainImgID != VisibleMainImgID)
	{
		if (VisibleMainImgID != null)
		{
			LoImg(document.getElementById(VisibleMainImgID));
		}

		VisibleMainImgID = MainImgID;

		if (MainImgID != null)
		{
			HiImg(document.getElementById(MainImgID));
		}
	}

	var AreSame = (VisibleSubMenusIDs.length == SubMenusIDs.length);

	for (var i = 0; i < SubMenusIDs.length; i++)
	{
		var found = false;

		for (var v = 0; v < VisibleSubMenusIDs.length; v++)
		{
			if (VisibleSubMenusIDs[v] == SubMenusIDs[i])
			{
				found = true;
				break;
			}
		}

		if (!found)
		{
			AreSame = false;
			VisibleSubMenusIDs.push(SubMenusIDs[i]);
			document.getElementById(SubMenusIDs[i]).style.display = "";
		}
	}

	if (!AreSame)
	{
		for (v = 0; v < VisibleSubMenusIDs.length; v++)
		{
			found = false;

			for (i = 0; i < SubMenusIDs.length; i++)
			{
				if (VisibleSubMenusIDs[v] == SubMenusIDs[i])
				{
					found = true;
					break;
				}
			}

			if (!found)
			{
				document.getElementById(VisibleSubMenusIDs[v]).style.display = "none";
			}
		}

		VisibleSubMenusIDs = SubMenusIDs;
	}
}

function HideSubMenus(Immediatelly)
{
	if (Immediatelly)
	{
		ShowSubMenus(null, []);
	}
	else if (HideTimeout == null)
	{
		HideTimeout = setTimeout("ShowSubMenus(null, [])", 500);
	}
}
