// This script identifies the current page and then builds a menu based
// upon that page's location within the heirarchy.  The menu is then
// returned as a stand-alone HTML table.
// Revision History:  Created 1999 to work with image files.
// May 2000: Rewritten with comments to work with text
//          and style sheets.

// Declare variables and set up constants-------------------------------

var doMe=false
var x=0
var i=0
var dynaMenu = "<CENTER><TABLE WIDTH=140 CELLPADDING=2 CLASS='menu'>"
var temp=""
var lineCount=0
var startIndex=0
var arrayIndex=0
var thisFile=""
// Define the pageName and menuItem functions---------------------------

function pageName(){
// pageName returns the simple name of the current page.
// Example: If we are at http://www.xx.org/mypage.htm
// pageName will return the string mypage
if (navigator.appName=="Microsoft Internet Explorer"){
	var temporaryVariable = location.href
	thisFile=location.href.substring((temporaryVariable.lastIndexOf("/")+1),temporaryVariable.lastIndexOf("."))
	}
	else{
	var temporaryVariable = location.href
	thisFile=location.href.substring((temporaryVariable.lastIndexOf("/")+1),temporaryVariable.lastIndexOf("."))
	}
	return thisFile
}

function menuItem(page,conditions,style,text){
// Builds a menuItem object; the data is stored in an array of
// such objects.
	this.page=page			//friendly name of 'home' page cf pageName
	this.conditions=conditions	//filenames of pages to display this menu item on
	this.style=style		//style class
	this.text = text		//link text
}

//Set up the arrays of  objects:------------------------------------

menu = new Array(8)  // An arbitrary figure as the array expands as needed.  No maintenance necessary.

menu[0] = new menuItem("index","","menu","Home")

menu[1] = new menuItem("webprojects","openstreetmap,popups,dbweb,search,.org/andyg/,.org/,index,webprojects,glossarysource,ssi,speechbubbles,van,vegoil,lipodiesel","menu","Projects")

menu[2] = new menuItem("openstreetmap","openstreetmap,popups,dbweb,webprojects,glossarysource,ssi,speechbubbles,van,vegoil","submenu","OpenStreetMap")

menu[3] = new menuItem("van","openstreetmap,popups,dbweb,webprojects,glossarysource,ssi,speechbubbles,van,vegoil","submenu","Camper Van Conversion")

menu[4] = new menuItem("vegoil","openstreetmap,popups,dbweb,webprojects,glossarysource,ssi,speechbubbles,van,vegoil","submenu","Vegetable Oil as Vehicle Fuel")
menu[5] = new menuItem("glossarysource","openstreetmap,popups,dbweb,webprojects,glossarysource,ssi,speechbubbles,van,vegoil","submenu","Pop-up Help")

menu[6] = new menuItem("ssi","openstreetmap,popups,dbweb,webprojects,glossarysource,ssi,speechbubbles,van,vegoil","submenu","SSIs")

menu[7] = new menuItem("speechbubbles","openstreetmap,popups,dbweb,webprojects,glossarysource,ssi,speechbubbles,van,vegoil","submenu","Speech Bubbles")

menu[8] = new menuItem("dbweb","openstreetmap,popups,dbweb,webprojects,glossarysource,ssi,speechbubbles,van,vegoil","submenu","Database-Driven Websites")

menu[9] = new menuItem("popups","openstreetmap,popups,dbweb,webprojects,glossarysource,ssi,speechbubbles,van,vegoil","submenu","Pop-Up Windows That Behave Themselves")

menu[10] = new menuItem("weirdscience","search,.org/andyg/,.org/,index,weirdscience,psychtypes","menu","Weird Science")

menu[11] = new menuItem("psychtypes","weirdscience,psychtypes","submenu","Psychological Types")

menu[12] = new menuItem("spirit",".org/andyg/,runes,raven,stones,kingland,.org/,index,spirit,ouija,spiritbio,moon,whatthouwilt","menu","Spirit")

menu[13] = new menuItem("raven","runes,raven,stones,kingland,spirit,ouija,spiritbio,moon,whatthouwilt","submenu","Raven")

menu[14] = new menuItem("ouija","runes,raven,stones,kingland,spirit,ouija,spiritbio,moon,whatthouwilt","submenu","Virtual Ouija")

menu[15] = new menuItem("moon","runes,raven,stones,kingland,spirit,ouija,spiritbio,moon,whatthouwilt","submenu","The Moon")

menu[16] = new menuItem("whatthouwilt","runes,raven,stones,kingland,spirit,ouija,spiritbio,moon,whatthouwilt","submenu","Do What Thou Wilt?")

menu[17] = new menuItem("kingland","runes,raven,stones,kingland,spirit,ouija,spiritbio,moon,whatthouwilt","submenu","The King is the Land")

menu[18] = new menuItem("stones","runes,raven,stones,kingland,spirit,ouija,spiritbio,moon,whatthouwilt","submenu","Standing Stones: Speculation")

menu[19] = new menuItem("runes","runes,raven,stones,kingland,spirit,ouija,spiritbio,moon,whatthouwilt","submenu","Making Runes: Notes")

menu[20] = new menuItem("velocity","search,.org/andyg/,.org/,index,lazyman,velocity,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick,dunrunkit","menu","VeloCity")


menu[21] = new menuItem("roadtrain","velocity,lazyman,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick,dunrunkit","submenu","Road Train: Two BOB trailers in tandem")

menu[22] = new menuItem("drbike","velocity,lazyman,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick,dunrunkit","submenu","Dr. Bike")

menu[23] = new menuItem("kit","velocity,lazyman,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick,dunrunkit","submenu","Bike Kit Reviews")

menu[24] = new menuItem("26slick","velocity,lazyman,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick,dunrunkit","submenu","26-inch Slick Tyre Comparisons")



menu[25] = new menuItem("risk","velocity,lazyman,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick,dunrunkit","submenu","Risk Compensation")

menu[26] = new menuItem("lazyman","velocity,lazyman,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick,dunrunkit","submenu","The Lazy Cyclist")

menu[27] = new menuItem("mybikes","velocity,lazyman,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick,dunrunkit","submenu","My Bikes")

menu[28] = new menuItem("dunrunkit","velocity,lazyman,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick,dunrunkit","submenu","Dunwich Dynamo kit list")

menu[29] = new menuItem("speedophiles","velocity,lazyman,kit,risk,speedophiles,drbike,mybikes,roadtrain,26slick","submenu","Speedophiles: Child killers on the loose")

menu[30] = new menuItem("body","search,.org/andyg/,.org/,index,body,training/index.htm,weights","menu","Body")

menu[31] = new menuItem("training/index","body,training/index,weights","submenu","My training diary")

menu[32] = new menuItem("weights","body,training/index,weights","submenu","What I Love About Weight Training")

menu[33] = new menuItem("roleplaying","search,.org/andyg/,.org/,index,roleplaying,btv,roleplay-devil,blood","menu","Roleplaying")

menu[34] = new menuItem("btv","roleplaying,btv,roleplay-devil,blood","submenu","Beyond the Veil")

menu[35] = new menuItem("roleplay-devil","roleplaying,btv,roleplay-devil,blood","submenu","RPGs and the Devil")

menu[36] = new menuItem("blood","roleplaying,btv,roleplay-devil,blood","submenu","Blood!")

menu[37] = new menuItem("thoughts","search,.org/andyg/,.org/,index,thoughts,wotw-archive,fidelity","menu","Thoughts")

menu[38] = new menuItem("fidelity","metamorphosis,thoughts,stormdream,giantspecs,wotw-archive,fidelity","submenu","The Fidelity Meme")

menu[39] = new menuItem("giantspecs","metamorphosis,thoughts,stormdream,giantspecs,wotw-archive,fidelity","submenu","Raven and the Giant's Spectacles")

menu[40] = new menuItem("stormdream","metamorphosis,thoughts,stormdream,giantspecs,wotw-archive,fidelity","submenu","Storm Dream")

menu[41] = new menuItem("metamorphosis","metamorphosis,thoughts,stormdream,giantspecs,wotw-archive,fidelity","submenu","Metamorphosis")

menu[42] = new menuItem("wotw-archive","metamorphosis,thoughts,stormdream,giantspecs,wotw-archive,fidelity","submenu","Word of the Week Archive")

menu[43] = new menuItem("reference","aslan,reference,trespass,search,.org/andyg/,.org/,index,","menu","Reference")

menu[44] = new menuItem("trespass","aslan,reference,trespass","submenu","Aggravated Trespass: CJA Section 68")

menu[45] = new menuItem("aslan","aslan,reference,trespass","submenu","ASLaN Charter")


menu[46] = new menuItem("aboutme","bald,search,.org/andyg/,.org/,index,aboutme,cv,gates","menu","About Me")

menu[47] = new menuItem("cv","bald,aboutme,cv,gates","submenu","My CV")

menu[48] = new menuItem("gates","bald,aboutme,cv,gates","submenu","I am not Bill!")

menu[49] = new menuItem("bald","bald,aboutme,cv,gates","submenu","Mister Shinyhead")

//This concludes the header script
//This is the body script.  If they don't work like this, split them.

for(x=0; x<=menu.length-1; x++){
// Loop through the menu array.

	// Reset the doMe flag.
	doMe=false

	// Special circumstance; menu items with null conditions are always displayed.
	if(menu[x].conditions==""){
		doMe=true
	}

	// Scan through the conditions looking for a match with the current page.
	temp=menu[x].conditions
	
	startIndex=0
	arrayIndex=0
	conds = new Array(1)
	conds[0]=""
	
	while(temp.substring(startIndex, startIndex+1) != ""){
		if(temp.substring(startIndex, startIndex+1) == ","){
			startIndex++
			arrayIndex++
			conds[arrayIndex]=""
		}
		else{
			conds[arrayIndex]+=temp.substring(startIndex, startIndex+1)
			startIndex++
		}
	}

	for(i=0; i<=(conds.length - 1); i++){

		if(pageName()==conds[i]){
			doMe=true
			}
	}

	// Write a line of code to dynaMenu if the line is to be displayed.
	// The style class is prefixed with current if this entry is the
	// current page.
	if(doMe==true){
		dynaMenu += "<TR><TD><A class='"
		
		//Test to see if this is the current page.
		if(pageName()==menu[x].page){
			dynaMenu += "current"
			}

		dynaMenu += menu[x].style
		dynaMenu += "' HREF='http://www.ravenfamily.org/andyg/"
		dynaMenu += menu[x].page
		dynaMenu += ".htm'>"
		dynaMenu += menu[x].text
		dynaMenu += "</A></TD></TR>"

		lineCount++
	}
	
}

dynaMenu+="</TABLE>"
document.write(dynaMenu)
