
var $parentL = section_tree_names.length;
var $childL = 0;
var $pL = 1;
var $cL= 1;
var $listId = "mbwsnav";
var $subListId = "mbwsnavsub";
var newListItem = "";
var newSubListItem = "";
var acatalogpath = 'acatalog';
var cgibinpath = 'cgi-bin';

    mainUl = document.getElementById('navigation');
	while ($pL <= $parentL) {
   		$cL = 1;
   		$urlP = section_tree_URLs[$pL].sURL;
   		$urlPL = $urlP.length;
   		$urlP = unescape($urlP.substring($urlP.indexOf("SECTIONID=")+10,$urlPL-14));
   		// add main section item here
		newListItem = document.createElement('li');
		newListItem.id = $listId + $pL;
		mainUl.appendChild(newListItem);
		newLink = document.createElement('a');
		// add in acatalog/ path if not present - eg home page
		if(document.location.href.indexOf(acatalogpath) == -1 && document.location.href.indexOf(cgibinpath) == -1) {
			$urlP = acatalogpath +'/' + $urlP; 
			}
		newLink.href = $urlP;
		//newLink.href = "#";
		newLinkText = document.createTextNode(section_tree_names[$pL].sName);
		newLink.appendChild(newLinkText);
		newListItem.appendChild(newLink);
		newLink.childNodes[0].nodeValue = newLink.childNodes[0].nodeValue.replace(/&#33;/g,'!');
		newLink.childNodes[0].nodeValue = newLink.childNodes[0].nodeValue.replace(/&#34;/g,'"');
		newLink.childNodes[0].nodeValue = newLink.childNodes[0].nodeValue.replace(/&#38;/g,'&');
		newLink.childNodes[0].nodeValue = newLink.childNodes[0].nodeValue.replace(/&#44;/g,',');
		newLink.childNodes[0].nodeValue = newLink.childNodes[0].nodeValue.replace(/&#45;/g,'-');
		newLink.childNodes[0].nodeValue = newLink.childNodes[0].nodeValue.replace(/&#47;/g,'/');
		newLink.childNodes[0].nodeValue = newLink.childNodes[0].nodeValue.replace(/&#163;/g,'£');


   		if(section_tree_names[$pL].pChild) {  // child sections present
				$childL = section_tree_names[$pL].pChild.length;

			// add child UL
		        newSubList = document.createElement('ul');
		        newSubList.id = $subListId + $pL;

 			subUl = document.getElementById($listId + $pL);
        		subUl.appendChild(newSubList);
 			    subLi = document.getElementById($subListId + $pL);

 			   // alert(subUl);

			while ($cL <= $childL) {
				$urlC = section_tree_URLs[$pL].pChild[$cL].sURL;
				$urlL = $urlC.length;
				$urlC = unescape($urlC.substring($urlC.indexOf("SECTIONID=")+10,$urlL-14));
				// add in acatalog/ path if not present - eg home page
				if(document.location.href.indexOf(acatalogpath) == -1 && document.location.href.indexOf(cgibinpath) == -1) {
					$urlC = acatalogpath +'/' + $urlC; 
					}
			    	newSubListItem = document.createElement('li');

				subLi.appendChild(newSubListItem);
				newSubLink = document.createElement('a');
				newSubLink.href = $urlC;
				newSubLinkText = document.createTextNode(section_tree_names[$pL].pChild[$cL].sName);
				newSubLink.appendChild(newSubLinkText);
				newSubListItem.appendChild(newSubLink);
				newSubLink.childNodes[0].nodeValue = newSubLink.childNodes[0].nodeValue.replace(/&#33;/g,'!');
				newSubLink.childNodes[0].nodeValue = newSubLink.childNodes[0].nodeValue.replace(/&#34;/g,'"');
				newSubLink.childNodes[0].nodeValue = newSubLink.childNodes[0].nodeValue.replace(/&#38;/g,'&');
				newSubLink.childNodes[0].nodeValue = newSubLink.childNodes[0].nodeValue.replace(/&#44;/g,',');
				newSubLink.childNodes[0].nodeValue = newSubLink.childNodes[0].nodeValue.replace(/&#45;/g,'-');
				newSubLink.childNodes[0].nodeValue = newSubLink.childNodes[0].nodeValue.replace(/&#47;/g,'/');
				newSubLink.childNodes[0].nodeValue = newSubLink.childNodes[0].nodeValue.replace(/&#163;/g,'£');


				$cL ++;
				}
			// remove LI item id - no longer needed
			subUl.removeAttribute('id');
			// remove ul item id - no longer needed
			subLi.removeAttribute('id');

		}
   		$pL ++;
   	}



