/** browser detection */
var IE, NN;
if (document.all) {
  IE = true;
} else {
  NN = true;
}

/** functions to make a navigation bar 
on the left hand side, slides in and out of the page as needed
navbar div must have id 'NavBar' */
if (IE) {
  var LEFT_PROPERTY = "pixelLeft";
}
if (NN) {
	var LEFT_PROPERTY = "left";
}
/** event handler 
params -- image for forwards and backwards buttons */
function showHideLayer(backImg,foreImg) {
 // first work out whether we're coming or going..
 var nb = document.getElementById("NavBar");
 var icon = document.getElementById("NavBarButton");
 var layerPosition = eval("nb.style." + LEFT_PROPERTY);
 if (layerPosition <= 0) {
 		showLayer();
		icon.src=backImg
 } else {
	eval("nb.style." + LEFT_PROPERTY + "= -140");
	icon.src=foreImg
 }
}
// little function that does the animation.
function showLayer() {
  var nb = document.getElementById("NavBar");
	var layerPosition = eval("nb.style." + LEFT_PROPERTY); 
	if (layerPosition <= 0) {
		eval("nb.style." + LEFT_PROPERTY + " = " + (layerPosition + 5));
		setTimeout("showLayer()",20);
	}
}

/** generate a menubar with the correct Id,s, etc.
param: array of "<A>" objects, for and back buttons. */
// arr should be an array of these.
function Sect(title, ref) {
  this.title = title;
	this.ref = ref;
}

function generateMenu(arr, foreImg, backImg) {
	writeHeader(foreImg,backImg);
	for (var i = 0; i < arr.length; i++) {
	 document.write("<p><a href='#" + arr[i].ref + "'>" + arr[i].title + "</a></p>");
	}
	writeFooter();
}
// write the header
function writeHeader(foreImg, backImg) {
 with(document) {
	write("<div id='NavBar'><div class='NavBarControls'>Contents&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
	write("<a href=\"javascript:showHideLayer('" + backImg + "','" + foreImg + "');\"");
	write(" class='NavBarControls'><img id='NavBarButton' src='" + foreImg + "'></a></div>");
	write("<div class='NavBarContents'>");
	}
}

function writeFooter() {
  document.write("</div></div>");
}
