function sd_doMenu(itemNo) {
	clearTimeout(sd_timeOn);

	var itemName = 'sd_menu' + itemNo;
	
	if( sd_menuActiveNo == 0) {	
		var styleObject = getStyleObject(itemName);
 		sd_menuActive = itemName;
 		sd_menuActiveNo = itemNo;
		changeObjectVisibility(itemName,'visible');
		if (sd_menuTop < sd_menuAbsBottom-2) {
			sd_menuTop = sd_menuTop + 5;
			if (!document.layers) styleObject.top = sd_menuTop + 'px';
			if (!document.layers) styleObject.left = sd_menuLeft + 'px';
			styleObject.top = sd_menuTop;
			styleObject.left = sd_menuLeft;
		 	sd_timeOn = setTimeout("sd_doMenu('" + itemNo + "')", 1);
		} else {
			if (!document.layers) styleObject.top = sd_menuAbsBottom + 'px';
			styleObject.top = sd_menuAbsBottom;
		}
	} else {
		if (sd_menuActive == itemName) {
			var styleObject = getStyleObject(itemName);
			changeObjectVisibility(itemName,'visible');
			if (sd_menuTop < sd_menuAbsBottom-2) {
				sd_menuTop = sd_menuTop + 5;
				if (!document.layers) styleObject.top = sd_menuTop + 'px';
				if (!document.layers) styleObject.left = sd_menuLeft + 'px';
				styleObject.top = sd_menuTop;
				styleObject.left = sd_menuLeft;
			 	sd_timeOn = setTimeout("sd_doMenu('" + itemNo + "')", 1);
			} else {
			 	sd_menuActive = itemName;
		 		sd_menuActiveNo = itemNo;
				if (!document.layers) styleObject.top = sd_menuAbsBottom + 'px';
				styleObject.top = sd_menuAbsBottom;
				sd_menuTop = sd_menuAbsBottom;
			}
		} else {
			if(document.layers) {
				sd_myStyle[sd_menuActiveNo].bgColor=sd_offColours[sd_menuActiveNo];		
			} else {
				// get the style object for the menu heading...
				var menuBox = getStyleObject('sd_labelBox'+sd_menuActiveNo);
				// ... and change its' colour
				menuBox.backgroundColor = sd_offColours[sd_menuActiveNo];	
			}		
			var styleObject = getStyleObject(sd_menuActive);
			if (sd_menuTop > (sd_menuAbsTop+5)) {
				sd_menuTop = sd_menuTop - 5;
				if (!document.layers) styleObject.top = sd_menuTop + 'px';
				styleObject.top = sd_menuTop;
			 	sd_timeOn = setTimeout("sd_doMenu('" + itemNo + "')", 1);
			} else {
				changeObjectVisibility(sd_menuActive,'hidden');
			 	sd_menuActive = itemName;
		 		sd_menuActiveNo = itemNo;
				if (!document.layers) styleObject.top = sd_menuAbsTop + 'px';
				styleObject.top = sd_menuAbsTop;
				sd_menuTop = sd_menuAbsTop;
			 	sd_timeOn = setTimeout("sd_doMenu('" + itemNo + "')", 1);				
			}
		}
		if(document.layers) {
			sd_myStyle[itemNo].bgColor=sd_onColours[itemNo];		
		} else {
			// get the style object for the menu heading...
			var menuBox = getStyleObject('sd_labelBox'+itemNo);
			// ... and change its' colour
			menuBox.backgroundColor = sd_onColours[itemNo];	
		}
	}
} //end function doMenu


function sd_hideMenu() {
	clearTimeout(sd_timeOn);
	var styleObject = getStyleObject(sd_menuActive);
	if (sd_menuTop > (sd_menuAbsTop+5)) {
		sd_menuTop = sd_menuTop - 5;
		if(!document.layers) styleObject.top = sd_menuTop + 'px';
		styleObject.top = sd_menuTop;
	 	sd_timeOn = setTimeout("sd_hideMenu()", 1);
	} else {
		if(!document.layers) styleObject.top = sd_menuAbsTop + 'px';
		styleObject.top = sd_menuAbsTop;
		changeObjectVisibility(sd_menuActive,'hidden');
		if(document.layers) {
			sd_myStyle[sd_menuActiveNo].bgColor=sd_offColours[sd_menuActiveNo];		
		} else {
			// get the style object for the menu heading...
			var menuBox = getStyleObject('sd_labelBox'+sd_menuActiveNo);
			// ... and change its' colour
			menuBox.backgroundColor = sd_offColours[sd_menuActiveNo];	
		}
	}	
} 


function sd_doMouseOut() {
	 	sd_hider = window.setTimeout("sd_hideMenu()", 3000);
}


function sd_startSlideMenuBar(width, numMenus) {
	if (document.layers) {
	// NS 4.x
		// start the table
		document.write('<table width="' + width + '" cellpadding="0" cellspacing="0" border="0">');
		// start the row for the menu headings and add a 1px table cell for the left-hand border
		document.write('<tr height="1"><td colspan="' + ((numMenus*2)+1) + '" bgcolor="#eeffff"><img src="shim.gif" width="1" height="1" border="0" align="top" name="sd_menuPlacer" id="sd_menuPlacer"></td></tr>');	
		document.write('<tr height="20"><td bgcolor="#eeffff"><img src="shim.gif" width="1" height="1" border="0"></td>');	
	} else {
	// IE and DOM browsers - just start a table and table row
		document.write('<table width="' + width + '" cellpadding="0" cellspacing="0" border="0">');	
		document.write('<tr height="1"><td colspan="' + numMenus + '"><img src="shim.gif" width="1" height="1" border="0" align="top" name="sd_menuPlacer" id="sd_menuPlacer"></td></tr>');	
		document.write('<tr height="20">');	
	}
}
	
function sd_endSlideMenuBar(numMenus) {
	// end table row
	document.write('</tr>');
	if (document.layers) {
		document.write('<tr height="1"><td colspan="' + ((numMenus*2)+1) + '" bgcolor="#eeffff"><img src="shim.gif" width="1" height="1" border="0" align="top" name="sd_menuPlacer2" id="sd_menuPlacer2"></td></tr>');	
		document.write('</table>');
	} else {
		// close off the table
		document.write('<tr height="1"><td colspan="' + numMenus + '" bgcolor="transparent"><img src="shim.gif" width="1" height="1" border="0" align="top" name="sd_menuPlacer2" id="sd_menuPlacer2"></td></tr>');	
		document.write('</table>');
	}
}


function sd_startSlideMenu(menuNumber, width, numItems) {
	// set the tier of the menu in the tier array
	
	// record the width of the menu (used by showSubMenu() for positioning)
	sd_menuWidths[menuNumber] = width;
	
	if (document.layers) {
		//open the div that hold the menu
		 document.write('<div id="sd_menu' + menuNumber + '" name="sd_menu' + menuNumber + '" class="slider">');
		 // open the table that hold the menu
		 document.write('<table width="' + width + '" cellpadding="0" cellspacing="0" border="0"><tr height="1"><td colspan="' + ((numItems*2)+1) + '" bgcolor="#eeffff"><img src="shim.gif" width="1" height="1" border="0"></td></tr><tr><td bgcolor="#eeffff"><img src="shim.gif" width="1" height="1" border="0"></td>');
	} else {
		// open the div that hold the menu
		document.write('<div id="sd_menu' + menuNumber + '" name="sd_menu' + menuNumber + '" class="slider">');
		// open the table that holds the menu
		document.write('<table width="' + width + '" cellpadding="0" cellspacing="0" border="0"><tr>');
	}	
}
	
function sd_endSlideMenu(numItems) {
	// close off table and div
	if(document.layers) document.write('<tr><td colspan="' + ((numItems*2)+1) + '" bgcolor="#eeffff"><img src="shim.gif" width="1" height="1" border="0"></td></tr>');
	document.write('</tr></table></div>');
}
	
function sd_slideMenuItem(label, menuItemNumber, width, onColour, offColour, url) {		
	if(document.layers) {		
		// open the ilayer that holds the menu item
		document.write('<td width="' + width + '" valign="middle" height="20"><ilayer>');
		
		// open the layer that holds the menu item
		document.write('<layer width="' + width + '" ');
		
		// onmouseover - change the colour of the menu, defuse the timer that hides the menus (if its ticking) and hide any submenus above this one
		document.write('onmouseover="bgColor=\'' + onColour + '\'; window.clearTimeout(sd_hider);" ');
		
		// onmouseout - change menu item colour and set the bomb ticking to close all menus (if the mouse goes over another menu item it'll be defused
		document.write('onmouseout="bgColor=\'' + offColour + '\'; sd_doMouseOut();" ');
		
		// name the div (use "id" AND "name" to keep everyone happy)
		document.write('id="sd_menuItem' + menuItemNumber + '" name="sd_menuItem' + menuItemNumber + '" ');
		
		// set background colour
		document.write('bgcolor="' + offColour + '">');
		
		// stick in a spacer - this might not be necessary anymore but in earlier revisions NS got very annoyed without it!
		document.write('<img src="shim.gif" width="1" height="20" border="0" align="left">\n');
		
		// the link for the menu - NOTE: NS has no onclick event for layers so only the link will work
		document.write('<a class="MenuItemLink" href="' + url + '">' + label + '</a>');
		
		// close off the layer, ilayer and table cell
		document.write('</layer></ilayer></td><td bgcolor="#eeffff"><img src="shim.gif" width="1" height="1" border="0"></td>');
		
		
	} else {
		// open the table cell to hold our menu item
		document.write('<td ');
		
		// onmousover - change the table cells' background colour and change the bullet point image
		document.write('onMouseover="this.style.backgroundColor = \'' + onColour + '\';" ');

		// on mouseout - change back the background colour and bullet point image
		document.write('onMouseout = "this.style.backgroundColor = \'' + offColour + '\';" ');
		
		// does what it says on the tin
		document.write('width="' + width + '" bgcolor="' + offColour + '" valign="middle" height="20" align="center" ');
		
		// onclick - go to the address specifies in the URL parameter
		document.write('onclick="document.location.href=\'' + url + '\';" ');
		
		// put a border on the menu item - wish NS4.x could do this!
		document.write('style="border: #eeffff 1px solid;">');
		
		// open the div for our menu item
		document.write('<div id="sd_menuItem' + menuItemNumber + '" name="sd_menuItem' + menuItemNumber + '" onmouseout="sd_doMouseOut();" onMouseover="window.clearTimeout(sd_hider);">');
		
		// the link for the menu item
		document.write('<a class="MenuItemLink" href="' + url + '">&nbsp;' + label + '</a>');
		
		// close off the div, table cell and table row
		document.write('</div></td>');
	}		
}


	function sd_slideMenuLabel(label, menuNumber, width, onColour, offColour, url) {
	
		sd_offColours[menuNumber] = offColour;
		sd_onColours[menuNumber] = onColour;
		
		if(document.layers) {
			document.write('<td width="' + width + '" valign="middle" height="20"><ilayer id="sd_menuLabelOuter' + menuNumber + '" name="sd_menuLabelOuter' + menuNumber + '"><layer width="' + width + '" onmouseover="window.clearTimeout(sd_hider); sd_doMenu(' + menuNumber + '); return false;" onmouseout="sd_doMouseOut();" id="sd_menuLabel' + menuNumber + '" name="sd_menuLabel' + menuNumber + '" bgcolor="' + offColour + '"><img src="shim.gif" width="1" height="20" border="0" align="left"><a class="MenuItemLink" href="' + url + '">' + label + '</a></layer></ilayer></td><td bgcolor="#000000"><img src="shim.gif" width="1" height="1" border="0"></td>');
			sd_myStyle[menuNumber] = eval('document.sd_menuLabelOuter' + menuNumber + '.document.sd_menuLabel' + menuNumber);
		} else {
			document.write('\n<style>\n');
			document.write('\n#sd_menuLabel' + menuNumber + '{width: ' + (width-2) + 'px; layer-background-color: ' + offColour + ';}\n');
			document.write('\n</style>\n');
			document.write('<td width="' + width + '" bgcolor="' + offColour + '" valign="middle" height="20" style="border: #eeffff 1px solid; z-index: 2; position: relative;" id="sd_labelBox' + menuNumber + '" name="sd_labelBox' + menuNumber + '" align="center"><div id="sd_menuLabel' + menuNumber + '" name="sd_menuLabel' + menuNumber + '" onmouseover="window.clearTimeout(sd_hider); sd_doMenu(' + menuNumber + ');"  onmouseout="sd_doMouseOut();" onclick="document.location.href=\'' + url + '\';"><a class="MenuItemLink" href="' + url + '">');
			document.write('&nbsp;' + label + '</a></div></td>');
		}		
	}
	


	if (document.layers) onload = sd_init;

	function sd_init() {
  		setTimeout("onresize = sd_redo", 1000);
	}

	function sd_redo() {
  		location.reload();
	}
	
	//window.onError = null;
	
function sd_slideMenuInit() {
	if (document.layers) {
		var img = getImage('sd_menuPlacer');
		var x = getImagePageLeft(img);
		var y = getImagePageTop(img);
	} else {
		var x = getElementLeft('sd_menuPlacer');
		var y = getElementTop('sd_menuPlacer');
	}
	sd_menuAbsTop = y + 2;
	sd_menuTop = y + 2;
	sd_menuLeft = x;
	if (document.layers) {
		var img = getImage('sd_menuPlacer2');
		var y = getImagePageTop(img);
	} else {
		var y = getElementTop('sd_menuPlacer2');
	}
	sd_menuAbsBottom = y;
}
