//
// 	Project:	CAMCS Journal Cover Design
//
// 	Author:		Ev Shafrir
// 	Date:		March 13, 2005
//	Modified:	April 21, 2005
//
// (c) Copyright 2005 Lingua Franca Design
//

// 	to begin with, nothing is visible 
//	visible status is maintained and updated at each crossover

var	visibleMenu = 0;		// object; 
var currentTitle = 0;		// object;
var currentGuide = 0;		// object; 
var currentItem = 0;		// object;

//	Future Addition:	Automatic creation of menus at run time;
//	1. define number of menus, menu titles, and menu items in arrays here;
//	2. define target links HERE and redirect with call from HTML file;
//	3. create Javascript operators to further simplify event detection;
//	4. generalize the title-guide images with 'see through' background color

function highlightObject (theObject) {	// by naming convention, three last characters of class name 
										// denote highlighted states of classes
	var currentClass;
		
	if (theObject) {
		currentClass = theObject.className;
		if (currentClass) {					// ergo a class has been defined 
			theObject.className = currentClass.replace("-reg","-sel");
		}
	}
}

function dimObject (theObject) {		// by naming convention, three last characters of class name 
										// denote highlighted states of classes
	var currentClass;
	
	if (theObject) {
		currentClass = theObject.className;
		if (currentClass) {					// ergo a class has been defined 
			theObject.className = currentClass.replace("-sel","-reg");	// all but last three chars
		}
	}
}

function showMenu (menuTitle) {		// find out which menu it is and display the corresponding submenu
									// based on an id naming convention
	var menuNumber = menuTitle.id.slice(-1);
	var subMenuName = "sub-menu-" + menuNumber;
	var subMenu = document.getElementById(subMenuName);
	var titleGuideName = "title-guide-" + menuNumber;
	var titleGuide = document.getElementById(titleGuideName);
	
	hideMenu ();
	dimObject (currentTitle);
	dimObject (currentGuide);
	
	currentTitle = menuTitle;
	highlightObject (currentTitle);
		
	currentGuide = titleGuide;
	highlightObject (currentGuide);
		
	subMenu.style.display = "block";
	// subMenu.style.visibility = "visible";
	visibleMenu = subMenu;
}

function hideMenu () {					// hide the currently visible menu
	
	if (visibleMenu) {
		visibleMenu.style.display = "none";
		// visibleMenu.style.visibility = "collapse";
		visibleMenu = 0;
	}
}

function highlightItem (menuItem) {		// dim any current item and highlight this one 
										
	
	dimObject (currentItem);
	currentItem = menuItem;				// object assignment
	highlightObject (currentItem);
}

function exitMenu () {					// leave everything on!				

	// hideMenu ();						// leaving the menu boundary, turn everything off
	dimObject (currentTitle);
	// dimObject (currentGuide);
}

function highlightMenuTitle () {		// when reentering an open submenu from below				
										// 'reignite' the menu title
	if (currentTitle)
		highlightObject (currentTitle);
}

// End
