/*****************************************************************************
** Copyright (C) 2002, Stephen Gould
**
** FILENAME:	main.js
** AUTHOR:	Stephen Gould
** COMMENCED:	01 May 2002
** MODIFIED:	04 Jul 2002
** DESCRIPTION:	javascript for dymanic menus in web pages for CWC
**
*****************************************************************************/

/* Menu Structure Set Up Variables ******************************************/

var mainMenu = new Array(
	"About Us",
	"Products",
	"Search",
	"Downloads",
	"Contact Us",
	"Site Map"
);

var subMenu = new Array();

subMenu[0] = new Array(
	"Rhomberg Electronics", "aboutus/electronics.html",
	"Rhomberg Instrumentation", "aboutus/instrumentation.html"
);

subMenu[1] = new Array(
	"Electronics", "products/electronics.html",
	"Instrumentation", "products/instrumentation.html"
);

subMenu[2] = new Array(
	"by Keyword", "search/search.html",
	"by Product Code", "search/by_product.html"
);

subMenu[3] = new Array(
	"Data Sheets", "downloads/download_data.html",
	"General Product Info","downloads/download_genspecs.html",
	"Order Codes","downloads/download_ordercodes.html",
	"User Guides", "downloads/download_user.html",
	"Application Notes", "downloads/download_appnotes_inst.html",
	"Useful Info", "downloads/download_ui.html"
);

subMenu[4] = new Array(
	"Contact Details", "contactus/contact_electronics.html",
	"Contact Form", "contactus/contactform.html"
);

subMenu[5] = new Array(
	"Site Map", "sitemap/sitemap.html"
);

var subMenuIds = new Array();
k = 0;
for (i = 0; i < mainMenu.length; i++) {
	subMenuIds[i] = new Array();
	for (j = 0; j < subMenu[i].length / 2; j++) {
		subMenuIds[i][j] = k++;
	}
}

/* Display Variables *********************************************************/

var inactiveColour = "#c2def2";
var activeColour = "#ffffcc";

var menuTop = 55;
var subMenuTop = menuTop + 19;
var menuLeft = 166 + 16;
var menuWidths = 90;
var subMenuWidths = new Array(170, 120, 120, 140, 120, 120);
var activeMenu = -1;

/* System Variables **********************************************************/

var stdBrowser = (document.getElementById) ? true : false;

/* Style Sheet ***************************************************************/

var sytleSheet;
styleSheet = "<style type=\"text/css\">\n";

styleSheet += ".menu {position:absolute; font:11px verdana,tahoma, arial, helvetica;" +
		"background-color:" + inactiveColour + "; " +
		"layer-background-color:" + inactiveColour + "; " +
		"border: 1px; border-color:#000000; border-style:solid; " +
		"border-left: 0px; cursor: hand; " +
		"top:" + menuTop + "px; padding:2px; font-weight:bold; }\n";

for (i = 0; i < mainMenu.length; i++) {
	styleSheet += "#menu" + i + " {left:" + (menuLeft + i * menuWidths) +
		"px; width:" + menuWidths + "px; ";
	if (i != 0) {
		styleSheet += "border-left: 0px; ";
	}
	styleSheet += "}\n";
}

styleSheet += ".sub {position:absolute; font:12px tahoma, arial, helvetica; " +
		"background-color:" + inactiveColour + "; " +
		"layer-background-color:" + inactiveColour + "; " +
		"border: 1px; border-color:#000000; border-style:solid; " +
		"padding:2px; z-index: 1; visibility:hidden}\n";

for (i = 0; i < subMenuIds.length; i++) {
	for (j = 0; j < subMenuIds[i].length; j++) {
		styleSheet += "#sub" + subMenuIds[i][j] + " {left:" +
			(menuLeft + i * menuWidths - ((i > 0) ? 1 : 0)) +
			"px; width:" + subMenuWidths[i] + "px; " +
			"top:" + (subMenuTop + j * 19) + "px}\n";
	}
}

styleSheet += ".shorttext {font:10pt tahoma, arial, helvetica; " +
	"color:\"#7f7f7f\"; display:none };\n";

styleSheet += "</style>\n";

document.write(styleSheet);

/* Functions *****************************************************************/

function DisplayMenu(menuId) {
	var menuDiv;

	activeMenu = menuId;
	for (i = 0; i < mainMenu.length; i++) {

		menuDiv = "<div id=\"menu" + i + "\" class=\"menu\" " +
			"onMouseOver=\"ShowMenu('" + i + "')\" " +
			"onMouseOut=\"HideMenu('" + i + "')\">" +
			"<img src=\"../images/transparent.gif\" width=\"5\" height=\"12\">" +
			mainMenu[i] + "<br>\n" +
			"</div>\n";
		for (j = 0; j < subMenu[i].length; j += 2) {
			menuDiv += "<div id=\"sub" + subMenuIds[i][j / 2] +
				"\" class=\"sub\"" +
				"onMouseOver=\"ShowMenu('" + i + "', '" + j / 2 + "')\" " +
				"onMouseOut=\"HideMenu('" + i + "')\">";
			menuDiv += "<a href='../" + subMenu[i][j + 1] + "'>" +
				"&nbsp; " + subMenu[i][j] + "</a><br>\n";
			menuDiv += "</div>\n";
		}
		document.writeln(menuDiv);
	}

	if (activeMenu >= 0) {
		Highlight(activeMenu);
	}
}

function ShowMenu(menuId, subId) {
	var subObj;

	Highlight(menuId);
	for (j = 0; j < subMenuIds[menuId].length; j++) {
		if (stdBrowser) {
			subObj = document.getElementById("sub" + subMenuIds[menuId][j]).style;
		} else if (document.all) {
			subObj = eval("document.all.sub" + subMenuIds[menuId][j] + ".style");
		} else {
			subObj = eval("document.sub" + subMenuIds[menuId][j]);
		}
		subObj.visibility = "visible";
		if (j == subId) {
			subObj.backgroundColor = activeColour;
		} else {
			subObj.backgroundColor = inactiveColour;
		}
	}
}

function HideMenu(menuId) {
	var menuObj, subObj;

	if (menuId != activeMenu) {
		if (stdBrowser) {
			menuObj = document.getElementById("menu" + menuId).style;
		} else if (document.all) {
			menuObj = eval("document.all.menu" + menuId + ".style");
		} else {
			menuObj = eval("document.menu" + menuId);
		}
		menuObj.backgroundColor = inactiveColour;
	}
	for (j = 0; j < subMenuIds[menuId].length; j++) {
		if (stdBrowser) {
			subObj = document.getElementById("sub" + subMenuIds[menuId][j]).style;
		} else if (document.all) {
			subObj = eval("document.all.sub" + subMenuIds[menuId][j] + ".style");
		} else {
			subObj = eval("document.sub" + subMenuIds[menuId][j]);
		}
		subObj.visibility = "hidden";
	}
}

function Highlight(menuId) {
	var menuObj;

	if (menuId < 0)
		return;
	if (stdBrowser) {
		menuObj = document.getElementById("menu" + menuId).style;
	} else if (document.all) {
		menuObj = eval("document.all.menu" + menuId + ".style");
	} else {
		menuObj = eval("document.menu" + menuId);
	}
	menuObj.backgroundColor = activeColour;
}

function SetShortcutText(id, bVisible) {
	var textObjl

	if (stdBrowser) {
		textObj = document.getElementById("shorttext" + id).style;
	} else if (document.all) {
		textObj = eval("document.all.shorttext" + id + ".style");
	} else {
		textObj = eval("document.shorttext" + id);
	}

	if (bVisible) {
		textObj.display = "block";
	} else {
		textObj.display = "none";
	}
}

/* Body Functions ***********************************************************/

function DataSheetActivate(id, bActive) {
	var activeObj;

	if (stdBrowser) {
		activeObj = document.getElementById("datasheet" + id).style;
	} else if (document.all) {
		activeObj = eval("document.all.datasheet" + id + ".style");
	} else {
		activeObj = eval("document.datasheet" + id);
	}
	if (bActive) {
		activeObj.visibility = "visible";
	} else {
		activeObj.visibility = "hidden";
	}
}

/*****************************************************************************
** END OF FILE:	main.js
*****************************************************************************/
