/* 	MENU.js

*

*	Include this code in an HTML page that needs rollover drop down menus.

*	Use <script language="Javascript" type="text/Javascript" src="menu.js"></script>

*	

*	A few notes:

*	- wrap the layer tags (needed for netscape) in div tags.

*	- all of the event handlers are in the images.

*

*	All Javascript code written by Scott Richmond

* 	All Javascript code (c)2000 RainCastle Communications, Inc.

*/



/* 	initialize variables */

//	inMenu to fix IE image bug; set to true when the mouse is in a menu

var inMenu = false;

// 	activeMenu is set to the ID of the menu the mouse is in

var activeMenu = null;

//var menupix = new Array();

//var pixcount = 0;

//	these variables are used for killMenu to reduce runtime.

var menus = new Array();

var menucount = 0;





/* 	turns the menu on

 	function takes the id of the menu to show as a string.

	called by event handlers from HTML */

function showMenu(menuID) {

	//	you can't turn on a menu that's already on...

	if (activeMenu == menuID) {

		inMenu = true;

	} 

	//	if you're turning on a menu you're not in already....

	else {

		// 	get rid of old menu (if one is open)

		killAll();

		// 	yup, you're in a menu

		inMenu = true;

		//	and now you're in the new menu

		activeMenu = menuID;

		//	turn top graphic on

//		menuTopOn(menuID);

		// turn the menu on

		// if netscape

		if (document.layers) document[activeMenu].visibility = "show";

		// if IE

		else if (document.all) document.all[activeMenu].style.visibility = "visible";

		

		else if (document.getElementById) document.getElementById(activeMenu).style.visibility = "visible";

	}

}





/* 	turns the menu off without the time delay.

	this function takes menuID as a string as a parameter.

	Called by hideMenu(.) and showMenu(.) and event handlers from HTML. */

function killMenu(menuID) {

	// turn it off

	// if netscape

	if (document.layers) {

		if (document[menuID]) document[menuID].visibility = "hide";

	}

	// if IE

	else if (document.all) {

		if (document.all[menuID].style) document.all[menuID].style.visibility = "hidden";

	}

	

	else if (document.getElementById){

		if (document.getElementById(activeMenu).style) document.getElementById(activeMenu).style.visibility = "hidden";

	}

	//	turn top graphic off

	menuTopOff(menuID);

	//	make sure activeMenu is null

	activeMenu = null;

}



/*	turns the menu off after a time delay (to let inMenu be overridden by other functions).

	this function takes menuID as a string as a parameter.

	Called by event handlers in HTML code. */

function hideMenu(menuID) {

	inMenu = false;

	menuCheck = "checkMenu('" + menuID + "');";

	setTimeout(menuCheck,100);

}



/*	checks to see if inMenu is true before calling killMenu(.) on the specified menu.

	takes menuID as a string as a parameter.

	called by hideMenu(.)*/

function checkMenu(menuID) {

	if (!inMenu) {

		killMenu(menuID);

	}

}



/*	turns an image in a menu ON. 

	this is different from regular swap image methods. the path to the object is hard coded, more or less.

	netscape's DOM makes this necessary.

	takes the div, layer, image, and source to swap the image to in strings.

	called by event handlers in HTML code. */

function menuImageOn(div, layer, image, source) {

	// set inMenu to true; obviously, if your in an image in a menu, you're in the menu

	inMenu = true;

	//	if netscape's funky DOM

	// (we really only have to do it this way because we wrapped the layers in the divs.)

	for (i = 0; i < pic_count; i++) {

		if (pics[i][0] == image) {

			if (document.layers) {

				document.layers[div].document.layers[layer].document.images[image].src = pics[i][2].src;

			}

			// if anything else

			else {

				document[image].src = pics[i][2].src;

			}

		}

	}

}



/*	turns an image in a menu OFF.

	this function is very much the same as menuImageOn. */

function menuImageOff(div, layer, image, source) {

	inMenu = false;

	hideMenu(div);

	for (i = 0; i < pic_count; i++) {

		if (pics[i][0] == image) {

			if (document.layers) {

				document.layers[div].document.layers[layer].document.images[image].src = pics[i][1].src;

				return;

			}

			else {

				document[image].src = pics[i][1].src;

				return;

			}

		}

	}

}



/*	turns all the menus off. loops through and makes everything in menus[.] invisible.

	this function takes no parameters.

	this function called from showMenu() */

function killAll() {



	if (document.layers) 

	{

		for (i = 0;i < menus.length; i++) 

		{

			document.layers[menus[i][0]].visibility = "hide";

			document.images[menus[i][1]].src = menus[i][2].src;

		}

	} 

	else if (document.all) 

	{

	

		for (i = 0;i < menus.length; i++) 

		{

			document.all[menus[i][0]].style.visibility = "hidden";

			document.images[menus[i][1]].src = menus[i][2].src;

		}

	}

	else if (document.getElementById)

	{

		for (i = 0;i < menus.length; i++) 

		{

			document.getElementById(menus[i][0]).style.visibility = "hidden";

			document.images[menus[i][1]].src = menus[i][2].src;

		}

	}

}



/*	puts menuID and all pertinent information regarding the graphic at the top into an array in the menus[.] array.

	takes menuID, imgName, graphicOff, and graphicOn as parameters, all as strings.

	called from within the head tag.*/

function init(menuID, imgName, graphicOff, graphicOn) {

	menus[menucount] = new Array();

	menus[menucount][0] = menuID;

	menus[menucount][1] = imgName;

	menus[menucount][2] = new Image();

	menus[menucount][2].src = graphicOff;

	menus[menucount][3] = new Image();

	menus[menucount][3].src = graphicOn;

	menucount++;

}



/*	switches image at top of menu to on state.

	takes menuID as a string.

	called from showMenu(.)*/

function menuTopOn(menuID) {

	for (i = 0; i < menucount; i++) {

		if (menus[i][0] == menuID) {

			if (document.layers) {

				document.images[menus[i][1]].src = menus[i][3].src;

			}

			else {

				document.images[menus[i][1]].src = menus[i][3].src;

			}

		}

	}

}



/*	switches image at top of menu to off state.

	takes menuID as a string.

	called from showMenu(.)*/

function menuTopOff(menuID) {

	for (i = 0; i < menucount; i++) {

		if (menus[i][0] == menuID) {

			if (document.layers) {

				document.images[menus[i][1]].src = menus[i][2].src;

			}

			else {

				document.images[menus[i][1]].src = menus[i][2].src;

			}



		}

	}

}

