// MENU BUILDER ver 3 - DECLARATIONS & FUNCTIONS
// Dave McLean, February 2003
// Called from menu.html
// To display the section 1 submenu on initial opening call menu.html?1

m = new Array()		// Array of HTML link strings
var i=0						// Array index
var section=0			// menu section no, base 1
var line=0				// line no within a section, base 1
var newIndex = location.search.substring(1)		// the selected section

// Initialises a new menu section
function newSection() {
	line=0
	section++
}

// Generates a link which re-creates the menu.
function Menu(name) {
	line++
	URL='menu.htm?' + section
	return linkString(name,URL,"_self","main")
}

// Generates a link to another URL
function Link(name,URL,target) {
	line++
	if (line==1) {
		return linkString(name,URL,target,"main")
	} else {
		if (newIndex==section) {
			return linkString(name,URL,target,"sub")
		} else {
			return ""
		}	
	}
}

// Produces the HTML string for the link. Called from Menu() and Link()
function linkString(name,URL,target,style) {
	return '<a class=' + style + ' href="' + URL + '" target="' + target + '">' + name + '</a><br>'
}

// Writes the menu HTML to the document.  Called from menu.html.
function writeMenu() {
	for (i=0;i<m.length;i++) {
		document.write(m[i]);
	}
}

