function showhideSecondLevel(id,currentElement) {
	/*
	Hide all level 2 items (items with an id structure of submenu*)
	Then show all level2 items that are children of the item where id is passed in as a parameter
	example: <dt onclick="showhideSecondLevel('menu3');" class="no"><a href="#" id="menu3">Blog</a></dt>
	*/

	// determine if current item is showing ('block') or hidden ('none')
	// This is read first, as all dt's are closed before openeing this dt again
	var state = (document.getElementById(id).style.display=="" || document.getElementById(id).style.display=="none")?"none":"block";
	// first level menus have a id structure menu1, menu2 etc,
	// second level has id structure submenu1, submenu2 etc
	var noChildren = id.indexOf('submenu') == -1;
	// does this menu item exist, if not , do nothing
	if(document.getElementById(id)){
		//loop through for every second level
		for (var x = 1; x <= document.getElementsByTagName('dt').length; x++) {
			//first hide all submenus
			var subMenuItem=document.getElementById('submenu' + x);
			if(subMenuItem){
				subMenuItem.style.display="none";
			}
		}
		// at this point all dd's are hidden
		// reshow the current one
		if(noChildren == false){
			// we are in a menu item that has children
			document.getElementById(id).style.display=(state == "block")?"none":"block";	
		}
		hideThirdLevel();
		toggleImage(id, currentElement,2);
	}
}

function showhideThirdLevel(id,currentElement){
	if(document.getElementById(id)){
		var d = document.getElementById(id);
		//keep a record of display value before it gets set to none 
		var displayValue = d.style.display;
		//get the third level number, the id passed in will be like submenu2_2
		var posOfUnderscore=id.indexOf('_');
		var secondLevelNum = id.substr(7, posOfUnderscore-7);
		var thirdLevelID = document.getElementById('submenu' + secondLevelNum + '_'+i);
		//loop through the third level submenus and hide all
		for (var i = 1; thirdLevelID; i++) {
			thirdLevelID.style.display='none';	
		}
		//toggle the current third level
		d.style.display=(displayValue=='block')?'none':'block';
		//toggle the image
		toggleImage(id, currentElement,3);
	}else{
		//when clicking on a second level element, loop through and close all third level elements that may be open
		//we know that any open third level id would start with parentID
		
		// first find out how many digits (if more than 9 submenus there will be 2 digits eg submenu10_x
		var submenuDigitLength=id.indexOf('_')- 7;
		// establish secondLevel ID
		var parentID = 'submenu' + id.substr(7, submenuDigitLength);
		var parentElement = document.getElementById(parentID);
		// how many UL elements are there that are descendants of the element with id of parentID
		var UlLength =  parentElement.getElementsByTagName('UL').length;
		//hide all ULs that are children of the parentID and have an id
		for(var x = 0;x < UlLength; x++){
			if(parentElement.getElementsByTagName('UL')[x].id.indexOf(parentID) > -1){
				parentElement.getElementsByTagName('UL')[x].style.display = 'none';
			}
		}
	}
}
function hideThirdLevel(){
	//loop through for every second level and hide any that may be showing
			var nestedUlCount = document.getElementsByTagName('ul').length;
			for (var x = 1; document.getElementById('submenu' + x); x++) {
				for (var i = 1; i < nestedUlCount; i++) {
					if(document.getElementById('submenu' + x + '_'+ i)){
						document.getElementById('submenu' + x + '_'+ i).style.display="none";
					}
				}
			}
}
function toggleImage(id, currentElement, level){
		
		/*This syntax was used because getAttribute and setAttribute are not supported
		 in either Mac/IE5.0 or IE5.1 */

		//keep a record of class value before it gets set to plus
		var classValue = currentElement.parentNode.className;
		if(level == '2'){
			var dtArray = document.getElementsByTagName('dt');
			//loop through all first level elements and set minuses to pluses
			for(var x=0; x < dtArray.length;x++){
				if(dtArray[x].className == "minus"){
					dtArray[x].className = "plus";
				}
			}
		}
		if(level == '3'){
			var liElement = document.getElementById(id);
			var liArray = liElement.getElementsByTagName('li');
			//loop through all first level elements and set minuses to pluses
			for(var x=0; x < liArray.length;x++){
				if(liArray[x].className == "minus"){
					liArray[x].className = "plus";
				}
			}
		}
		if(classValue == "no"){
			//if there is no child elements don't change the image
			var newValue = classValue;
		}else{
			//if there is child elements change the image
			var newValue = (classValue == "plus" || classValue == null)?"minus":"plus";
		}
		currentElement.parentNode.className = newValue;
}

function makeCurrent(theElement){
	linklength = document.links.length;
	for(i=0;i<linklength;i++){
		if(document.links[i].className == 'current') {
			document.links[i].className = '';
		}
	}
	theElement.className = 'current';
}