/* Modules' menu code for WebTOP (uses Mike Hall's menu system) */

//Returns HTML for a button with the given menu, subpage destination, actual
//hyperlink, and label.  Use null for unused stuff.
function oneButton(menuname,link,href,text) {
	return '<a class="menuButton" onmouseover="buttonMouseover(this,'+menuname+')" onclick="return buttonClick(this,\''+menuname+'\',\''+!menuname+'\',\''+link+'\');" href="'+href+'">&nbsp;&nbsp;'+text+'&nbsp;&nbsp;</a>\n';
}
function oneVerticalButton(menuname,link,href,text) {
	return '<div class="menuButton" onmouseout="this.className=\'menuButton\';" onmouseover="buttonMouseover(this,'+menuname+');this.className=\'menuButtonHover\';" onmousedown="this.className=\'menuButtonActive\';" onclick="this.className=\'menuButtonActive\';window.location=\''+href+'\';">&nbsp;&nbsp;'+text+'&nbsp;&nbsp;</a></div>\n';
}

//Returns HTML for a link to a sibling module 'page' with the given name.
//Highlights the label if requested.
function modulePageButton(page,name,hilite) {
	return oneButton(null,page,page,(hilite?'<span style="color:Yellow">':'')+name+(hilite?'</span>':''));
}

function moduleVerticalPageButton(page,name,hilite) {
	return oneVerticalButton(null,page,page,(hilite?'<span style="color:Yellow">':'')+name+(hilite?'</span>':''));
}

//Here are helper functions to build the semantic parts of the menu.
//They can be used separately for such things as the /about.html page.

//Returns HTML for the button identifying the current family of pages.
function familyButton(depth,title) {
	/* If we make the current button unresponsive,
     this will have to be a special case */
	return modulePageButton(dirPrefix(depth)+'index.html',title,true);
}

//Returns HTML for the button that drops down the list of modules
//Uses 'Other Modules' if specified (else 'WebTOP Modules'
function moduleListButton(other) {
	return oneButton('modulesMenu',null,'#',(other?'Other':'WebTOP')+' Modules');
}

//Returns HTML for the button that closes the window
function closeButton() {
	return oneButton(null,null,'javascript:top.close()','Close');
}

/*
Returns an HTML string for the standard WebTOP menu for a page belonging to
the module with the given title and residing at the given depth in the tree (0
is a sibling of the module's page), with the given standard page (if any)
indicated as current, and (optionally) providing links to TOP content.

 Values for 'which':
  0: module		(actually unused; any undefined value will do)
  1: directions
  2: theory
  3: examples
  4: exercises
  5: TOP images
  6: TOP movies
*/
function stdMenu(depth,title,which,hasTOP) {
	pfx=dirPrefix(depth);

	//Any page which supports this menu will provide it a 'which' value;
	//we use that to determine the appropriate class of subpage to stay in.
	switch(which) {
		case 1: setSubpage('directions.html'); break;
		case 2: setSubpage('theory.html'); break;
		case 3: setSubpage('examples.html'); break;
		case 4: setSubpage('exercises.html'); break;
		case 5: setSubpage('topimages.html'); break;
		case 6: setSubpage('topmovies.html'); break;
		default: setSubpage('index.html');		//Otherwise, just use main page
	}

	toWrite='<div id=menuBar>\n';

	//The buttons for the module
	toWrite+=familyButton(depth,title);
	toWrite+=modulePageButton(pfx+'directions.html','Directions',which==1);
	toWrite+=modulePageButton(pfx+'theory.html','Theory',which==2);
	toWrite+=modulePageButton(pfx+'examples.html','Examples',which==3);
	toWrite+=modulePageButton(pfx+'exercises.html','Exercises',which==4);
	if(hasTOP) {
		toWrite+=modulePageButton(pfx+'topimages.html','Images',which==5);
		toWrite+=modulePageButton(pfx+'topmovies.html','Movies',which==6);
	}

	//The modules menu
	toWrite+=moduleListButton(true);

	//Back to thumbnail page (this got moved to the module list)
	//toWrite+=oneButton(null,null,pfx+'../about.html','About WebTOP');

	//'Close' button
	if(top.opener) toWrite+=closeButton();

	toWrite+='\n</div>\n';

	return toWrite;
}





