var Menu_Enabled = false;
var Frame_Enabled = false;
var CSS1 = false;

if (navigator.userAgent.indexOf("MSIE")!= -1 && navigator.userAgent.indexOf("Windows")!= -1 && navigator.appVersion.substring(0,1) > 3)	{
	Menu_Enabled = true;
	if (document.compatMode == "CSS1Compat")		CSS1 = true;
}

if (Menu_Enabled)	{
	var sc = false;
	var scCount = 0;
	var newLine = String.fromCharCode(10);
	var char34 = String.fromCharCode(34);
	var lastMenu = "";
	var isMenu = false;
	var MainStr;
	var x = 0, y = 0, x2 = 0, y2 = 0, x3 = 0;
	var MenuWidth;
	var HeadMinWidth;
	var HeadMenu;
	var HeadLoaded = false;
	var Font = "bold xx-small Verdana";
	var MenuBGColor="black";
	var SingleBGColor="#784878";
	var FColor="#FFFFFF";
	var MColor="#ffcc00";
	var MaxMenu = 30;
	var TotalMenu = 0;
	var arrMenuInfo = new Array(30);
	var Target="_top"
	var sepNeed = true;
	
	document.write("<SPAN ID='StartMenu' STYLE='display:none;'></SPAN>");

	MainStr  = "<DIV ID='idHead' STYLE='background-color:white;width:100%;'>";
	MainStr += "<DIV ID='idRow1' STYLE='position:relative;height:90px;'>";
	MainStr += "<DIV ID='idBanner' STYLE='position:absolute;top:0px;left:0px;height:150px;width:500px;overflow:hidden;vertical-align:top;'><bb><be></DIV>";
	
	MainStr += "<DIV ID='idTopPanel' STYLE='position:absolute;top:70px;left:600px;background-color:black;float:right;' NOWRAP><!--Multi_Menu--></DIV></DIV>";
	MainStr += "<DIV ID='idRow2' STYLE='position:relative;left:300px;height:40px;'></DIV>";
	MainStr += "<DIV ID='idRow3' STYLE='position:relative;height:40px;width:100%'>";
	MainStr += "<DIV ID='idBottomPanel' STYLE='position:absolute;top:20px;left:0px;height:20px;background-color:black;' NOWRAP><!--Single_Menu--></DIV></DIV></DIV>";
	MainStr += "<SCRIPT TYPE='text/javascript'>" + " var HeadMenu = StartMenu;" + "</SCRIPT>" + "<DIV WIDTH=100%>";		

	window.onresize  = resize;
	window.onscroll  = scOpt;
}

function build()	{
	MainStr += "</DIV>";
	document.write(MainStr);
	HeadLoaded = true;
	MenuWidth     = Math.max(idTopPanel.offsetWidth, (200+112));
	HeadMinWidth = (300+18) + MenuWidth;
	idHead.style.backgroundColor     = "#784878";
	idTopPanel.style.backgroundColor  = MenuBGColor;
	idBottomPanel.style.backgroundColor = SingleBGColor;
	resize();

	for (i = 0; i < TotalMenu; i++) 	{
		thisMenu = document.all(arrMenuInfo[i].IDStr);
		if (thisMenu != null)	{
			if (arrMenuInfo[i].IDStr == lastMenu && arrMenuInfo[i].type == "R")	{
				arrMenuInfo[i].type = "A";
				arrMenuInfo[i].unit = 200;
			}
			if (arrMenuInfo[i].type == "A")
				thisMenu.style.width = arrMenuInfo[i].unit + 'px';
			else 
				thisMenu.style.width = Math.round(arrMenuInfo[i].width * arrMenuInfo[i].unit) + 'em';
		}
	}
}

function resize()	{
	sc = false;
	scCount = 0;
	if (Menu_Enabled == false) return;
	w = Math.max(HeadMinWidth, document.body.clientWidth) - HeadMinWidth;
	
	idTopPanel.style.left   = (600+w+18) + 'px';
	idTopPanel.style.width  = MenuWidth  + 'px';
	idBottomPanel.style.width = HeadMinWidth + w  + 'px';
}

function setBanner(Pict, BanUrl, BanAlt, bbTag, beTag)	{
	SubStr = MainStr.substring(MainStr.indexOf(bbTag),MainStr.indexOf(beTag) + beTag.length);
	SrcStr = bbTag+"<A Target='_top' HREF='"+BanUrl+"'><IMG SRC='"+Pict+"' ALT='"+BanAlt+"' BORDER=0></A>"+beTag;
	MainStr = MainStr.replace(SubStr, SrcStr);	
}

function itemWidth(ItemID, WidthType, WidthUnit)	{
	var fFound = false;
	if (TotalMenu == MaxMenu)	{
		alert("Unable to process menu. Maximum of " + MaxMenu + " reached.");
		return;
	}
	for (i = 0; i < TotalMenu; i++)
		if (arrMenuInfo[i].IDStr == ItemID)	{
			fFound = true;
			break;
		}
	if (!fFound)	{
		arrMenuInfo[i] = new menuInfo(ItemID);
		TotalMenu += 1;
	}
	if (!fFound && WidthType.toUpperCase().indexOf("DEFAULT") != -1)	{
		arrMenuInfo[i].type = "A";
		arrMenuInfo[i].unit = 170;
	}
	else	{
		arrMenuInfo[i].type = (WidthType.toUpperCase().indexOf("ABSOLUTE") != -1)? "A" : "R";
		arrMenuInfo[i].unit = WidthUnit;
	}
}

function menuInfo(ItemID)	{
	this.IDStr = ItemID;
	this.type  = "";
	this.unit  = 0;
	this.width = 0;
	this.count = 0;
}

function updWidth(ItemID)	{
	for (i = 0; i < TotalMenu; i++)
		if (arrMenuInfo[i].IDStr == ItemID)	{
			if (arrMenuInfo[i].width < ItemID.length) 	arrMenuInfo[i].width = ItemID.length;
			arrMenuInfo[i].count = arrMenuInfo[i].count + 1;
			break;
		}
}

function addMenu(ItemID, ItemPrompt, ItemAlt, ItemURL, bSingleMenu)		{
	bgColor = bSingleMenu? SingleBGColor : MenuBGColor;
	tagStr  = bSingleMenu? "<!--Single_Menu-->" : "<!--Multi_Menu-->";
	MenuStr = newLine;
	if ((bSingleMenu == false && lastMenu != "") || (bSingleMenu == true && sepNeed==false))
		MenuStr += "<SPAN STYLE='font:" + Font + ";color:" + FColor + "'>|&nbsp;</SPAN>"; 
	MenuStr += "<A TARGET='" + Target + "' TITLE='" + ItemAlt + "' ID='AM_" + ItemID + "'" +
		"   STYLE='text-decoration:none;cursor:hand;font:" + Font + ";background-color:" + bgColor + ";color:" + FColor + ";'";
	MenuStr += " HREF='" + ItemURL + "'";
	MenuStr += 	" onmouseout="  + char34 + "mouseMenu('out' ,'" + ItemID + "'); hideItem();" + char34 + 
		" onmouseover=" + char34 + "mouseMenu('over','" + ItemID + "'); runMenu('"+ ItemID + "');" + char34 + ">" +
		"&nbsp;" + ItemPrompt + "&nbsp;</a>";
	MenuStr += tagStr;
	MainStr = MainStr.replace(tagStr, MenuStr);	
	itemWidth(ItemID,"default",0);
}

function addItem(ItemID, ItemPrompt, ItemURL, bSingleMenu)	{
	var MenuPos = ItemID.toUpperCase().indexOf("MENU");
	InstrumentStr = ItemID.substring(0 , MenuPos) + "|" + ItemPrompt;
	var LookUpTag  = "<!--" + ItemID + "-->";
	var sPos = MainStr.indexOf(LookUpTag);
	if (sPos <= 0)	{
		MainStr += newLine + "<SPAN ID='" + ItemID + "'";
		MainStr += " STYLE='display:none;position:absolute;width:160px;background-color:" + MenuBGColor + ";padding-top:0px;padding-left:0px;padding-bottom:20px;z-index:9px;'";
		MainStr += "onmouseout='hideItem();'>";		
		if (Frame_Enabled == false || bSingleMenu == false)
			MainStr += "<HR  STYLE='position:absolute;left:0px;top:0px;color:" + FColor + "' SIZE=1>";
		MainStr += "<DIV STYLE='position:relative;left:0px;top:8px;'>";
	}
	TempStr = newLine + "<A ID='AS_" + ItemID + "'" +
		" STYLE='text-decoration:none;cursor:hand;font:" + Font + ";color:" + FColor + "'" +
		" HREF='" + ItemURL + "' TARGET='" + Target + "'" +
		" onmouseout="  + char34 + "mouseMenu('out' ,'" + ItemID + "');" + char34 + 
		" onmouseover=" + char34 + "mouseMenu('over','" + ItemID + "');" + char34 + ">" +
		"&nbsp;" + ItemPrompt + "</A><BR>" + LookUpTag;
	if (sPos <= 0)	MainStr += TempStr + "</DIV></SPAN>";
	else			MainStr = MainStr.replace(LookUpTag, TempStr);	
	updWidth(ItemID);	
}

function mouseMenu(id, ItemID) 	{
	isMenu   = (ItemID.toUpperCase().indexOf("M_") != -1);
	IsMouseout = (id.toUpperCase().indexOf("OUT") != -1);
	if (IsMouseout)	color = FColor;
	else			color = MColor;
	window.event.srcElement.style.color = color;
}

function runMenu(ItemID) 	{
	var thisMenu = document.all(ItemID);
	if (HeadMenu == null || thisMenu == null || thisMenu == HeadMenu) 	{
		window.event.cancelBubble = true;
		return false;
	}
	window.event.cancelBubble = true;
	HeadMenu.style.display = "none";
	HeadMenu = thisMenu;
	isMenu = (ItemID.toUpperCase().indexOf("M_") != -1);

	x  = window.event.srcElement.offsetLeft + window.event.srcElement.offsetParent.offsetLeft;
	if (ItemID == lastMenu)		x += (window.event.srcElement.offsetWidth - thisMenu.style.posWidth);
	x2 = x + window.event.srcElement.offsetWidth;
	y  = (isMenu)? (idRow1.offsetHeight) : (idRow1.offsetHeight + idRow2.offsetHeight + idRow3.offsetHeight);
		 
	thisMenu.style.top  = y;
	thisMenu.style.left = x;
	thisMenu.style.clip = "rect(0 0 0 0)";
	thisMenu.style.display = "block";
	thisMenu.style.zIndex = 102;
	window.setTimeout("showItem()", 1);
	return true;
}

function showItem() 	{
	if (HeadMenu != null) 	{ 
		y2 = y + HeadMenu.offsetHeight;
		HeadMenu.style.clip = "rect(auto auto auto auto)";
		x2 = x + HeadMenu.offsetWidth;
	}
}

function hideItem()	{
	if (HeadMenu != null && HeadMenu != StartMenu) 	{
		cY = event.clientY + document.body.scrollTop;
		cX = event.clientX; 
		if (document.body.offsetWidth > x && sc)	cX = x + 9;
		if((cX>=(x+5)&&cX<=x2)&&((cY>(y-10)&&cY<= y2)||(cY>=y&&cY<=(y2+10))))	{
			window.event.cancelBubble = true;
			return; 
		}
		HeadMenu.style.display = "none";
		HeadMenu = StartMenu;
		window.event.cancelBubble = true;
	}
}

function scOpt()	{
	scCount ++;
	if (scCount < 3)	sc = true;
	else	{scCount = 0;sc = false;}	
}
if (Menu_Enabled != null && Menu_Enabled == true)	{	
	setBanner("gif/top3.gif","main.htm","На главную страницу","<bb>","<be>");	
	addMenu("Single", "Главная страница", "На главную страницу","main.htm",true);sepNeed=false;
	addMenu("Single", "Объявления", "Объявления","obyvl.htm",true);sepNeed=false;
	addMenu("Single", "Контакты", "Юридический/почтовый адрес компании","kont.htm",true);sepNeed=false;
//	
}
