// JavaScript Document
// menu_system.js

// *************** REQUIRES cookie_monster.js *******************

var MM_menuCookie = 'MM_menuShow'; // GLOBAL VARIABLE FOR THE MENU COOKIE THAT SAVES MENU SETTINGS.

function showMenu(e, idin) {
	if(document.getElementById('button'+idin)) {
		menuin = document.getElementById('button'+idin); // GETS THE MENU LINK.
		menuin.parentNode.style.backgroundImage = "url('images/menuButtonOn.gif')"; // CHANGES BUTTON BACKGROUND IMG FOR DIVIDE.
		menuin.onclick = function() { return hideMenu(e, idin); } // CHANGES LINK ONCLICK EVENT HANDLER TO CORRECT FUNCTION.
		document.getElementById(idin).style.display = 'block'; // MAKES SUB MENU VISIBLE.
		// GET RIGHT-ARROW IMG ELEMENT AND CHANGE IT TO DOWN-ARROW IMG...
		var imgElement = menuin.firstChild;
		if(imgElement.nodeType == 3) {
			imgElement = imgElement.nextSibling
		} // END if(imgElement.nodeType == 3).
		imgElement.src = "images/arrow_down.gif";
	} // END if(document.getElementById('button'+idin)).
	return false;
} // END function showMenu(e, idin).


function hideMenu(e, idin) {
	if(document.getElementById('button'+idin)) {
		menuin = document.getElementById('button'+idin); // GETS THE MENU LINK.
		menuin.parentNode.style.backgroundImage = "url('images/menuButtonOff.gif')"; // CHANGES BUTTON BACKGROUND IMG FOR DIVIDE.
		menuin.onclick = function() { return showMenu(e, idin); } // CHANGES LINK ONCLICK EVENT HANDLER TO CORRECT FUNCTION.
		document.getElementById(idin).style.display = 'none'; // MAKES SUB MENU INVISIBLE.
		// GET DOWN-ARROW IMG ELEMENT AND CHANGE IT TO RIGHT-ARROW IMG...
		var imgElement = menuin.firstChild;
		if(imgElement.nodeType == 3) {
			imgElement = imgElement.nextSibling
		} // END if(imgElement.nodeType == 3).
		imgElement.src = "images/arrow_right.gif";
	} // END if(document.getElementById('button'+idin)).
	return false;
} // END function hideMenu(e, idin).


function loadMenu() {
	// DYNAMICALLY LOAD MENU ITEMS?????????????????
	
	if(verifyCookies()) {
		// CHECK IF COOKIES ARE ENABLED- IF SO THEN CHECK FOR MENU COOKIE...
		var menuValue = getCookieValue(MM_menuCookie);
		if(menuValue != null) {
			// COOKIE ALREADY EXISTS SO USE ITS VALUE...
			var menuArray = menuValue.split(" ");
			for(var i=0; i<menuArray.length; i++) {
				if(menuArray[i] != "") {
					showMenu("", menuArray[i]);
				} // END if(menuArray[i] != "").
			} // END for(var i=0; i<menuArray.length; i++).
		} // END if(menuValue != null).
	} // END if(verifyCookies()).
	return true;
} // END function loadMenu().


function saveMenuSettings(menuids) {
	if(verifyCookies()) {
		// CHECK IF COOKIES ARE ENABLED- IF SO THEN CHECK MENUS FOR ONES SHOWING AND SAVE THESE IN MENU COOKIE...
		var menuArray = menuids.split(" "); // SPLIT MENU IDS TO LOOP THROUGH.
		var cookieString = ""; // RESET COOKIESTRING TO NOTHING.
		// LOOP THROUGH MENUARRAY AND CHECK EACH MENU TO SEE IF IT IS SHOWING. IF SO ADD IT TO COOKIE STRING...
		for(var i=0; i<menuArray.length; i++) {
			if(menuArray[i] !="") {
				if(document.getElementById(menuArray[i]) && document.getElementById(menuArray[i]).style.display == 'block') {
					cookieString += " "+menuArray[i]+" ";
				} // END if().
			} // END if(menuArray[i] !="").
		} // END for(var i=0; i<menuarray.length; i++).
		setCookie(MM_menuCookie, cookieString); // SET COOKIE STRING WITH NEW VALUES.
	} // END if(verifyCookies()).
	return true;
} // END function updateMenuString(menuin, show).



