var ie=0; var n=0; var ns6=0;
var fShow="visible"; var fHide="hidden";
if (document.all) ie=1;
if (document.getElementById&&!document.all) ns6=1;
if (document.layers) {n=1;fShow="show";fHide="hide";}

//Top Nav Bar I v2- By Constantin Kuznetsov Jr. (script@esolutiononline.com) 
//Modified by Dynamic Drive for NS6/Opera6 compatibility and code streamlining March 4th, 2002
//Modified by Kryloff Technologies:
//  Opera5 compatibility added;
//  menu may be placed in any position, not only at the top (static option removed);
//  submenu border and separators added.

var opr6=ie&&navigator.userAgent.indexOf("Opera")!=-1;
var opr5=opr6; // for now

window.onerror=new Function("return true")
////////////////////////////////////////////////////////////////////////////
// Function Menu()                                                        //
////////////////////////////////////////////////////////////////////////////

lastMenu = null;
hideElem = null;
rightX = 0;
rightY = 0;
leftY = 0;
leftX = 0;

function Menu()
{
	if (opr6) {
		if (document.body.offsetWidth) opr5=0;	// opera 6.0 or later
		else opr6=0;	// opera 5.x
	}
	this.bgColor	= menucolor;
	this.borderColor= bordercolor;
	this.emptyGif	= emptygif;
	if (ie) this.menuFont = "bold 12px Arial";
	if (n)  this.menuFont = "bold 12px Verdana";
	this.fontColor   = "black";

	this.addItem    = addItem;
	this.addSubItem = addSubItem;
	this.addSeparator = addSeparator;
	this.showMenu   = showMenu;
	this.mainPaneBorder = 0;
	this.subMenuPaneBorder = 0;

	HTMLstr = "";
	HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
	HTMLstr += "\n";
	if (ie||ns6) HTMLstr += "<div id='MainTable'>\n";
	HTMLstr += "<table width='100%' bgcolor='"+this.bgColor+"' border='"+this.mainPaneBorder+"' cellspacing=0>\n";
	HTMLstr += "<tr>";
	if (n) HTMLstr += "<td nowrap>&nbsp;";
	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	if (n) HTMLstr += "</td>";
	HTMLstr += "</tr>\n";
	HTMLstr += "</table>\n";
	HTMLstr += "\n";
	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	HTMLstr += "<!-- SUB MENU ENDS -->\n";
	HTMLstr += "\n";
	if (ie||ns6) HTMLstr+= "</div>\n";
	HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
}

function addItem(idItem, text, hint, location, altLocation)
{
	if (!n&&!ie&&!ns6) return;
	var Lookup = "<!-- ITEM "+idItem+" -->";
	if (HTMLstr.indexOf(Lookup) != -1)
	{
		alert(idParent + " already exist");
		return;
	}
	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
	if (n)
	{
		MENUitem += "<ilayer name="+idItem+">";
		MENUitem += "<a class=clsMenuItemNS ";
		if (location != null)
		{
			MENUitem += "href='"+location+"' ";
			MENUitem += "onmouseover=\"hideAll()\" ";
		}
		else
		{
			if (altLocation != null)
				MENUitem += "href='"+altLocation+"' ";
			else
				MENUitem += "href='#' ";
			MENUitem += "onmouseover=\"displaySubMenu('"+idItem+"')\" ";
			MENUitem += "onclick=\"return false;\" "
		}
		MENUitem += ">";
		MENUitem += "&nbsp;";
		MENUitem += text;
		MENUitem += "&nbsp;";
		MENUitem += "</a>";
		MENUitem += "</ilayer>";
	}
	if (ie||ns6)
	{
		MENUitem += "<td nowrap><!-- LAST -->\n";
		MENUitem += "<div id='"+idItem+"' style='position:relative; font: "+this.menuFont+";'>\n";
		if (location != null || altLocation != null)
			MENUitem += "<a class=clsMenuItemIE ";
		else
			MENUitem += "<a class=clsMenuIE ";
		if (hint != null)
			MENUitem += 'title="'+hint+'" ';
		if (location != null)
		{
			MENUitem += "href='"+location+"' ";
			MENUitem += "onmouseover=\"hideAll()\" ";
		}
		else
		{
			if (altLocation != null)
				MENUitem += "href='"+altLocation+"' ";
			else
				MENUitem += "href='#' ";
			MENUitem += "onmouseover=\"displaySubMenu('"+idItem+"')\" ";
			MENUitem += "onclick=\"return false;\" "
		}
		MENUitem += ">";
		MENUitem += "&nbsp;\n";
		MENUitem += text;
		MENUitem += "&nbsp;";
		MENUitem += "</a>\n";
		MENUitem += "</div>\n";
		MENUitem += "</td>\n";
	}
	MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
	MENUitem += "<!-- MAIN_MENU -->\n";

	if (ie||ns6)
	{
		HTMLstr = HTMLstr.replace("<!-- LAST -->", "");
	}
	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
}

function addSubItem(idParent, text, hint, location)
{
	if (!n&&!ie&&!ns6) return;
	var MENUitem = "";
	Lookup = "<!-- ITEM "+idParent+" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		alert(idParent + " not found");
		return;
	}
	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		if (n)
		{
			MENUitem += "\n";
			MENUitem += "<layer id='"+idParent+"submenu' visibility=hide z-index=100 bgcolor='"+this.bgColor+"'>\n";
			MENUitem += "<table border=0 bgcolor='"+this.borderColor+"' cellspacing=0 cellpadding=1><tr><td>\n";
			MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' width=100% cellspacing=0 cellpadding=4>\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</td></tr></table>\n";
			MENUitem += "</table>\n";
			MENUitem += "</layer>\n";
			MENUitem += "\n";
		}
		if (ie||ns6)
		{
			MENUitem += "\n";
			MENUitem += "<div id='"+idParent+"submenu' style='position:absolute; visibility: hidden; z-index:100; font: "+this.menuFont+"; top: -300;'>\n";
			MENUitem += "<table border=0 bgcolor='"+this.borderColor+"' cellspacing=0 cellpadding=1><tr><td>\n";
			MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' width=100% cellspacing=0 cellpadding=4>\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</td></tr></table>\n";
			MENUitem += "</table>\n";
			MENUitem += "</div>\n";
			MENUitem += "\n";
		}
		MENUitem += "<!-- SUB_MENU -->\n";
		HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
	}

	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	if (n)  MENUitem = "<tr><td><a class=clsMenuItemNS title='"+hint+"' href='"+location+"'>"+text+"</a><br></td></tr>\n";
	if (ie||ns6) MENUitem = "<tr><td><a class=clsMenuItemIE title='"+hint+"' href='"+location+"'>"+text+"</a><br></td></tr>\n";
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);

}

function addSeparator(idParent)
{
	if (!n&&!ie&&!ns6) return;
	var MENUitem = "";
	Lookup = "<!-- ITEM "+idParent+" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		alert(idParent + " not found");
		return;
	}
	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		alert(idParent + ": separator cannot go first");
		return;
	}

	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	if (n||ie||ns6) {
		MENUitem += "<tr><td><table width=100% border=0 cellspacing=0 cellpadding=0>";
		MENUitem += "<tr><td bgcolor='"+this.borderColor+"'><img src='"+this.emptyGif+"' height=1 width=1 alt=''></td></tr>";
		MENUitem += "</td></tr></table></td></tr>\n";
	}
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);
}

function showMenu()
{
	if (ie||ns6)
	{
		HTMLstr = HTMLstr.replace("><!-- LAST --", " width=99%");
	}
	document.writeln(HTMLstr);
}

////////////////////////////////////////////////////////////////////////////
// Private declaration
function elemShow(elems, verb)
{
	var i;
	if (n) {
		elems.visibility = verb;
	}
	if (ie) {
		for (i = elems[0]; i > 0; i--) {
			if (opr5 || opr6 || "SELECT"==elems[i].tagName)	elems[i].style.visibility = verb;
		}
	}
}

function displaySubMenu(idMainMenu)
{
	var menu;
	var submenu;
	var menuobj;
	var i;
	if(null == hideElem) { // called for the first time
		hideElem = false;
		if (n && document.layers["hide_me"]) {
			hideElem = document.layers["hide_me"];
		}
		if (ie && document.all.hide_me1) {
			hideElem = new Array(10);
			hideElem[0] = 0;
			for (i=1; i<10; i++) {
				if (!document.all["hide_me"+i]) break;
				hideElem[0]++;
				hideElem[i] = document.all["hide_me"+i];
			}
		}
	}

	if (n) {
		submenu = document.layers[idMainMenu+"submenu"];
		if (lastMenu != null && lastMenu != submenu) hideAll();
		submenu.left = document.layers[idMainMenu].pageX;
		submenu.top  = document.layers[idMainMenu].pageY + 23;
		if (hideElem) elemShow(hideElem, fHide);
		submenu.visibility = fShow;

		leftX  = document.layers[idMainMenu+"submenu"].left;
		rightX = leftX + document.layers[idMainMenu+"submenu"].clip.width;
		leftY  = document.layers[idMainMenu].pageY;
		rightY = document.layers[idMainMenu+"submenu"].top +
			 document.layers[idMainMenu+"submenu"].clip.height;
	} else if (ie||ns6) {
		menu = ie? eval(idMainMenu) : document.getElementById(idMainMenu);
		menuobj = ie? eval(idMainMenu+"submenu") : document.getElementById(idMainMenu+"submenu");
		submenu = menuobj.style;
		submenu.left = calculateSumOffset(menu, 'offsetLeft');
		leftY  = calculateSumOffset(menu, 'offsetTop');
		submenu.top  = leftY + 19;
		if (lastMenu != null && lastMenu != submenu) hideAll();
		if (hideElem) elemShow(hideElem, fHide);
		submenu.visibility = fShow;
		leftX  = parseInt(submenu.left);
		rightX = leftX + menuobj.offsetWidth;

		rightY = parseInt(submenu.top) + menuobj.offsetHeight;
	}
	lastMenu = submenu;
}

function hideAll()
{
	if (lastMenu != null) {
		lastMenu.visibility = fHide;
		lastMenu.left = 0;
		lastMenu=null;
		if (hideElem) elemShow(hideElem, fShow);
	}
}

function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	while (item != null) {
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	}
	return totalOffset;
}

function updateIt(e)
{
	if (lastMenu == null) return;
	if (opr5)
	{
		var x = window.event.clientX;
		var y = window.event.clientY;

		if (x < leftX || y < leftY ||
		(!MainTable.contains(event.srcElement) &&
		y > parseInt(lastMenu.top))) hideAll();
	}
	if (ie&&!opr5)
	{
		var x = window.event.clientX;
		var y = window.event.clientY;
		if (!opr6) {
			x+=document.body.scrollLeft;
			y+=document.body.scrollTop;
		}
		if (x > rightX || x < leftX) hideAll();
		else if (y > rightY || y < leftY) hideAll();
	}
	if (n||ns6)
	{
		var x = e.pageX;
		var y = e.pageY;

		if (x > rightX || x < leftX) hideAll();
		else if (y > rightY || y < leftY) hideAll();
	}
}

if (ie||ns6)
{
	document.body.onclick=hideAll;
	document.body.onscroll=hideAll;
	document.body.onmousemove=updateIt;
}
if (document.layers)
{
	window.captureEvents(Event.MOUSEMOVE);
	window.captureEvents(Event.CLICK);
	window.onmousemove=updateIt;
	window.onclick=hideAll;
}