var version = "";
var browser = navigator.appName;
var browser_version = parseInt(navigator.appVersion);
var menuItemWidth = 150;
var menuItemHeight = 19;
var NS4 = document.layers;

if (NS4) {
	origWidth = innerWidth;
	origHeight = innerHeight;
}
	
function handleResize() {
	if (innerWidth != origWidth || innerHeight != origHeight)
		location.reload();
}
	
if (NS4) onresize = handleResize;

if (document.images) { // Browser supports image swaps (most do)

	var imgSelected = new Image();
	imgSelected.src = "http://www.computicity.com/images/cellBG3_ovr.gif";

	var imgNotSelected = new Image();
	imgNotSelected.src = "http://www.computicity.com/images/cellBG3_def.gif";
}

var menuLengths = new Array(3,2); //Number of menu items in each menu.
var menuButtonIdxs = new Array(2,4); //Index of button that menu is attached to
var menuButtonNames = new Array('menuButton2','menuButton4'); //Names (Style Id) given to each menu button
var menuURLs = new Array(menuLengths.length);
var menuTimers = new Array(menuLengths.length);

for (i=0;i<menuLengths.length;i++)
	menuURLs[i] = new Array(menuLengths[i]);

menuURLs[0][0] = "http://www.computicity.com/Convert/index.asp";
menuURLs[0][1] = "http://www.worshipscheduler.com/";
menuURLs[0][2] = "http://www.computicity.com/development/index.asp";

menuURLs[1][0] = "http://www.computicity.com/Convert/ProgramOrder.asp";
menuURLs[1][1] = "http://www.worshipscheduler.com/ordernow.asp";

function getStyleObj(id) {
	if (document.getElementById || document.all) { // DOM-compliant browsers (MSIE5, NSN6, O5) or MSIE 4
		return getObj(id).style;
	} 
	else return getObj(id); // NSN4
}

function getObj(name)
{
	if (document.getElementById) { // Netscape 6.x, IE 5.x, Opera 5.x
		return document.getElementById(name);
	} 
	else if (document.all){ // Explorer 4.x
		return document.all[name];
	} 
	else if (document.layers){ // Netscape 4.x
		return document.layers[name];
	} 
	else { // DHTML-impaired browsers.
		return false;
	}
}

function showIndicator(index) { // Shows an Underline bar under the selected menu item
	if (document.images)
		document.images["indicator"+index].src = imgSelected.src;
}

function hideIndicator(index) { // Removes the Underline bar from under the last selected menu item
	if (document.images)
		document.images["indicator"+index].src = imgNotSelected.src;
}

function showMenu(index) {
	if (menuTimers[index-1]) clearTimeout(menuTimers[index-1]);

	for (i=1;i<=menuLengths.length;i++)
		if (i!=index) closeMenu(i);

	var menu = getStyleObj("menu"+index);				
	if (menu)  menu.visibility = "visible";
	
	showIndicator(menuButtonIdxs[index-1]);
}

function hideMenu(index) {
	if (menuTimers[index-1]) clearTimeout(menuTimers[index-1]);

	menuTimers[index-1] = setTimeout("closeMenu('"+index+"');",200);

	hideIndicator(menuButtonIdxs[index-1]);
}

function closeMenu(index) {
	var menu = getStyleObj("menu"+index);
	if (menu) menu.visibility = "hidden";
}

function overMenuItem() {
	this.hilightitem.visibility='visible';
	showMenu(this.menuid);
}

function outMenuItem() {
	this.hilightitem.visibility='hidden';
	hideMenu(this.menuid);
}

function clickMenuItem() {
	if (this.url) { // There is a URL associated with this item
		window.location = this.url;
	}
}

window.onload=setupMenus; // Assign to onLoad event handler

function setupMenus() {
	if (document.layers) { // This section is for Netscape 4 only
		for (menuid=1;menuid<=menuLengths.length;menuid++) { // For each menu

			var menu = getObj("menu"+menuid);
			menu.clip.width = menuItemWidth + 2;
			menu.clip.height = (menuItemHeight+1) * menuLengths[menuid-1] + 1;
			menu.document.bgColor="maroon";

			for (i=1;i<=menuLengths[menuid-1];i++) { // For each menu item

				var item = eval("menu.document.menu"+menuid+"item"+i);
				var onitem = eval("menu.document.menu"+menuid+"item"+i+"on");

				if (i==1) {
					item.top = 1;
					onitem.top = 1;
				} else {
					item.top = (menuItemHeight) * (i-1) + 1; 
  			  	           	onitem.top = (menuItemHeight) * (i-1) + 1;
				}                

				item.clip.width = menuItemWidth;
				item.clip.height = menuItemHeight;
				item.document.bgColor="#E6E6E6";
				onitem.clip.width = menuItemWidth;
				onitem.clip.height = menuItemHeight;
				onitem.document.bgColor="#CCCCCC";
				item.hilightitem = onitem;
				onitem.hilightitem = onitem;
				item.menuid = menuid;
				onitem.menuid = menuid;

				var url = menuURLs[menuid-1][i-1];
				item.url = url;
				onitem.url = url;

				var eTypes = Event.MOUSEOVER | Event.MOUSEOUT | Event.CLICK;
				item.captureEvents(eTypes);
				onitem.captureEvents(eTypes);
				item.onmouseover = overMenuItem;
				onitem.onmouseover = overMenuItem;
				item.onmouseout = outMenuItem;
				onitem.onmouseout = outMenuItem;
				item.onclick = clickMenuItem;
				onitem.onclick = clickMenuItem;
			}
		}
	} else { // This section is for all other browsers
		for (menuid=1;menuid<=menuLengths.length;menuid++) { // For each menu
			for (i=1; i<=menuLengths[menuid-1]; i++) { // For each menu item
				
				var item = getObj("menu"+menuid+"item"+i);
				var onitem = getObj("menu"+menuid+"item"+i+"on");
				var itemstyle = getStyleObj("menu"+menuid+"item"+i);
				var onitemstyle = getStyleObj("menu"+menuid+"item"+i+"on");

				// Space each menu item immediately below the previous item. For the first
				// item, skip 1 pixel so that we can have a border around the menu.
				if (i==1) {
					itemstyle.top = "1px";
					onitemstyle.top = "1px";
				} else {
					itemstyle.top = ((menuItemHeight) * (i-1)) + "px"; //(menuItemHeight + 1) * (i-1) + 1;
					onitemstyle.top = ((menuItemHeight) * (i-1)) +"px"; //(menuItemHeight + 1) * (i-1) + 1;
				}

				if (navigator.appName=="Microsoft Internet Explorer") {
					itemstyle.cursor = "hand";
					onitemstyle.cursor = "hand";
				}

				item.hilightitem = onitemstyle;
				onitem.hilightitem = onitemstyle;
				item.menuid = menuid;
				onitem.menuid = menuid;

				var url = menuURLs[menuid-1][i-1];
				item.url = url;
				onitem.url = url;
				item.onmouseover = overMenuItem;
				onitem.onmouseover = overMenuItem;
				item.onmouseout = outMenuItem;
				onitem.onmouseout = outMenuItem;
				item.onclick = clickMenuItem;
				onitem.onclick = clickMenuItem;
			}
		}
	}
}