/********************************************************************
 *        menu1.js                                                  *
 ********************************************************************/
/*
 * This script supports the topmenubar menuitem selection.
 * topmenubar->menuitem "mouseovers" display a particular scripture message
 * and select a particular menu in the index panel.
 * Each menuitem is associated with a particular style theme of colors and images.
 */
/* Use of DOM1 Styles
 ********************
 * This script uses DOM Level 1 Styles as used by "modern" browsers. This includes
 * IE5.0+ and NS6.2+ (Mozilla 1.4+) (see http://www.quirksmode.org/?dom/contents.html)
 *
 * Use of DOM Styles in NS4
 **************************
 * <object>.style, a DOM1 Style feature, does not work for NS4
 * getElementById is a recognized function but seems to always return a NULL.
 * e.g.   scripturemsg = document.getElementById("scripturemsg");
 * getElementsByTagName is NOT a recognized function.
 * e.g.   body = document.getElementsByTagName("body")[0];
 *
 * document.ids or document.classes returns a Style object (NS4 but not later versions)
 * Furthermore, it doesn't actually change the style.
 * e.g. document.ids.scripturemenu.display = "none"  (no JS errors, but doesn't display) 
 *
 *
 */
		var body;
		var topmenubar;
		var scripturemsg;
		var indexStyle;
//		var index1;
		var main;
		var news;
		
		var menuStyle = new Array(5);
		
		//var themeColor         = new Array('blue',    'purple',  'green',   'olive',    'brown'     );
		//var themeColor         = new Array('blue',    'gold',    'yellow',  'gray',    'orange'     );
		var themeBackgroundColor = new Array('#003366', '#330000', '#004000', '#333300', '#003333' );
		var themeForegroundColor = new Array('#003366', '#CC9900', 'yellow',  '#CCCCCC', '#FFCC33' );
		var menuBorderColor      = new Array('blue',    '#CC9900', 'yellow',  '#CCCCCC', '#FFCC33' );
		var menuBackgroundColor  = new Array('navy',    'purple',  'green',   'brown',   'gray'    );
		var menuForegroundColor  = new Array('white',   'white',   'white',   'white',   'white'   );

		var scriptureMessage = new Array(
				'\"Praise God From Whom all Blessings Flow\"',
				'\"Let everyone who is thirsty come\" Rev 22:17',
				'\"Where two or three are gathered in my name, I am present\" Mt 18:20',
				'\"Where can I go from your Spirit? Or where can I flee from your presence?\" ps 139 v 7',
				'\"Those who wait for the Lord will renew their strength; they will mount up with wings like eagles\"  Isa 40:31'
		);

		// Browser Sensing
		var modern = false;
		if (navigator.userAgent.indexOf ("Mozilla") != -1) {
				var mozversion = parseInt(navigator.appVersion.substring(0,1));
				if (mozversion > 4) { modern = true; }
				else {
						var MSIEindex = navigator.userAgent.lastIndexOf("MSIE");
						if (MSIEindex != -1) {
								var MSIEversion = parseInt(navigator.userAgent.substr(MSIEindex+5,1));
								if (MSIEversion > 5) { modern = true; }
						}
				}
		}

onLoad = function() {
				//document.classes.body.all.backgroundColor="red";

				//alert("body:" + body);
				
//		if (modern) {
		// Test for getElementById function and test for availability of style property
		var is_DOM1 = false;
		if (document.getElementById("body")!= null) {
				is_DOM1 = true;
		}
		if (is_DOM1) {
				scripturemsg = document.getElementById("scripturemsg");
				body = document.getElementById("body");
				topmenubar = document.getElementById("topmenubar");
				indexStyle = document.getElementById("index").style;
//				index1 = document.getElementById("index1");
				main = document.getElementById("main");
				news = document.getElementById("news");

				menuStyle[0] = document.getElementById("sitemenu").style;
				menuStyle[1] = document.getElementById("christmenu").style;
				menuStyle[2] = document.getElementById("communitymenu").style;
				menuStyle[3] = document.getElementById("dailymenu").style;
				menuStyle[4] = document.getElementById("wordsmenu").style;

/* The following doesn't work in modern browsers
				 menuStyle[0] = document.ids.sitemenu;
				 menuStyle[1] = document.ids.christmenu;
				 menuStyle[2] = document.ids.communitymenu;
				 menuStyle[3] = document.ids.dailymenu;
				 menuStyle[4] = document.ids.wordsmenu;
*/
				body.style.backgroundColor = themeBackgroundColor[thisThemeIndex];
				topmenubar.style.backgroundColor = menuBackgroundColor[thisThemeIndex];
				topmenubar.style.borderColor = menuBorderColor[thisThemeIndex];
				main.style.color = themeBackgroundColor[thisThemeIndex];
				
				selectMessage(thisThemeIndex);
//alert("menuStyle:" + menuStyle[1].display);
				selectMenu(thisThemeIndex);
//alert("menuStyle:" + menuStyle[1].display);
				paintMenu(thisThemeIndex);
			} else if (document.ids.body != null) {
				 body = document.classes.body.all;
				 //document.classes.logo.all.backgroundColor = 'white'; <= this works in ns4

				scripturemsg = document.getElementById("scripturemsg",this);
//alert("scripturemsg:" + scripturemsg);
				topmenubar = document.getElementById("topmenubar");
//alert("topmenubar:" + topmenubar);
				indexStyle = document.ids.index;
//alert("indexStyle:" + indexStyle);

				 menuStyle[0] = document.ids.sitemenu;
				 menuStyle[1] = document.ids.christmenu;
				 menuStyle[2] = document.ids.communitymenu;
				 menuStyle[3] = document.ids.dailymenu;
				 menuStyle[4] = document.ids.wordsmenu;
				selectMenu(thisThemeIndex);
//				menuStyle[0].backgroundColor ="red";
//alert("menuStyle(id=\'" + menuStyle[1].display + "\'): " + menuStyle[1].display);
//alert("menuStyle:" + menuStyle[1].display);
			}
			if (!modern) {
					// This alert should appear *after* the page is painted
					alert(
			  		"This web site is best viewed with a modern browser"
			 		+ " that supports CSS1 + DOM Level 1 Styles, e.g. Internet Explorer 5.x, Netscape 6.x"
			 		+ " or later versions."
			 		+ " (Better support for Netscape 4.x will be provided at a later date.)"
					+ "\n\n[Your user agent is:\'" + navigator.userAgent + "\']"
			 		);
			}
		}
		menuOnMouseOver = function(triggeredBy, themeIndex) {
				window.status = "mouse over \'" + triggeredBy.id + "\' menuitem";
				selectMessage(themeIndex);
				selectMenu(themeIndex);
				if (modern) { triggeredBy.style.backgroundColor = menuBackgroundColor[themeIndex]; }
				//triggeredBy.style.color = 'gray';
				paintMenu(themeIndex);
				return true;
		}
		menuOnMouseOut = function(triggeredBy) {
				window.status = "";
				selectMessage(thisThemeIndex);
				selectMenu(thisThemeIndex);
				if (modern) { triggeredBy.style.backgroundColor = menuBackgroundColor[thisThemeIndex]; }
				//triggeredBy.style.color = 'white';
				paintMenu(thisThemeIndex);
				return true;
		}
		selectMessage = function(themeIndex) {
				if (scripturemsg) { 
					scripturemsg.firstChild.nodeValue = scriptureMessage[themeIndex];
				}
		}
		selectMenu = function(themeIndex) {
				for ( i = 0; i < menuStyle.length; i++ ) {
						if (i==themeIndex) {
								menuStyle[i].display = 'block';
//alert("displaying theme #" + themeIndex);
						} else {
								menuStyle[i].display = 'none';
						}
				}
		}
		paintMenu = function(themeIndex) {
				indexStyle.backgroundColor = themeBackgroundColor[themeIndex];
				//index1.style.backgroundColor = themeBackgroundColor[themeIndex];
				indexStyle.color = themeForegroundColor[themeIndex];
				//index1.style.color = themeForegroundColor[themeIndex];
				//main.style.color = themeBackgroundColor[themeIndex];
				//news.style.color = themeBackgroundColor[themeIndex];
		}
