function print_navigation () {
  // This var should have an entry for each folder in the site ...
  // It remains to be seen if this is a performance inhibitor, and if alternative arrangememnts are needed
  var directoryLookup =  {
    www_hud_ac_uk: "University&nbsp;of&nbsp;Huddersfield",
    hhs: "School&nbsp;of&nbsp;Human&nbsp;&amp;&nbsp;Health&nbsp;Sciences",
    u: "School&nbsp;of&nbsp;Human&nbsp;&amp;&nbsp;Health&nbsp;Sciences",
    departments: "Departments",
    chs: "Clinical&nbsp;&amp;&nbsp;Health&nbsp;Sciences", 
    physiotherapy: "Rehabilitation",
		podiatry: "Podiatry",
		pod_staff: "Podiatry&nbsp;Staff&nbsp;Pages",
		general: "General&nbsp;Information",
		equal_opps: "Equal&nbsp;Opportunities",
		research: "School&nbsp;Research",
		general_r: "General&nbsp;School&nbsp;Research&nbsp;Information",
		courses: "Courses",
		profdev: "Continuing&nbsp;Professional&nbsp;Development",
		certificates: "Certificate&nbsp;in&nbsp;Professional&nbsp;Studies",
		sections: "CPD&nbsp;modules",
		critical_care: "Critical&nbsp;Care",
		dermatology: "Dermatology",
		evidence_based_practice: "Evidence&nbsp;Based&nbsp;Practice",
		medical_surgical: "Medical/Surgical",
		mental_health_div: "Health&nbsp;&amp;&nbsp;Social&nbsp;Studies&nbsp;Staff",
		mental_health: "Mental&nbsp;Health&nbsp;&amp;&nbsp;Learning&nbsp;Disabilies",
		older_people: "Older&nbsp;People",
		palliative_care: "Palliative&nbsp;Care",
		practice_nursing: "Practice&nbsp;Nursing",
		prof_pol_dev: "Professional&nbsp;and&nbsp;Policy&nbsp;Development",
		public_health_promotion: "Public&nbsp;Health&nbsp;and&nbsp;Health&nbsp;Promotion",
		therapeutic_relationships: "Therapeutic&nbsp;Relationships",
		midwifery: "Midwifery",
		midstaff: "Midwifery&nbsp;Staff",
		sports: "",
		hs_site: "Sports&nbsp;&amp;&nbsp;Health&nbsp;Studies",
		facilities: "Sports&nbsp;&amp;&nbsp;Health&nbsp;Facilities",
		sports_staff: "Sports&nbsp;&amp;&nbsp;Health&nbsp;Staff",
		odp: "Operating&nbsp;Department&nbsp;Practice",
		odpstaff: "Operating&nbsp;Department&nbsp;Practice&nbsp;Staff",
		acs: "Applied&nbsp;Childhood&nbsp;Studies",
		amh: "Ageing&nbsp;&amp;&nbsp;Mental&nbsp;Health",
		eval: "Centre&nbsp;for&nbsp;Evaluation&nbsp;Studies",
		acirg: "ACIRG",
		primary: "Primary&nbsp;Care&nbsp;Research",
		staff: "Applied&nbsp;Childhood&nbsp;Studies&nbsp;Staff",
		swmhlds: "Social&nbsp;Work,&nbsp;Mental&nbsp;Health&nbsp;&amp;&nbsp;Learning&nbsp;Disability&nbsp;Studies",
		learning_disabilities: "Health&nbsp;&amp;&nbsp;Social&nbsp;Studies&nbsp;Staff",
		ld: "Learning&nbsp;Disability&nbsp;Research&nbsp;Unit",
		ld_staff: "Learning&nbsp;Disability&nbsp;Research&nbsp;Staff",
		health_and_safety: "Health&nbsp;&amp;&nbsp;Safety",
		hcs: "Health&nbsp;&amp;&nbsp;Community&nbsp;Studies",
		hcs_staff: "Health&nbsp;&amp;&nbsp;Social&nbsp;Studies&nbsp;Staff",
		nursing: "Adult&nbsp;&amp;&nbsp;Child&nbsp;Nursing",
		nursing_staff: "Nursing&nbsp;Staff",
		wyhon: "West&nbsp;Yorkshire&nbsp;History&nbsp;of&nbsp;Nursing",
		quality: "Quality&nbsp;Assurance&nbsp;in&nbsp;Practice",
		template_analysis: "Template&nbsp;Analysis",
		technique: "Template&nbsp;Analysis&nbsp;Technique",
		example1: "Template&nbsp;Analysis&nbsp;Example&nbsp;1",
		subSilver: "Template&nbsp;Analysis&nbsp;Discussion",
		chscr: "Centre&nbsp;for&nbsp;Health&nbsp;&amp;&nbsp;Social&nbsp;Care&nbsp;Research",
		apl: "Claiming Academic Credit",
		review: "Major&nbsp;Review",
		mhrg: "Mental&nbsp;Health&nbsp;Research&nbsp;Group",
		teaching_learning: "Learning&nbsp;and&nbsp;Teaching",
		masters: "Postgraduate&nbsp;Courses",
		pgmds: "Modular&nbsp;Postgraduate&nbsp;Scheme",
		ptug: "Part&#8209;time&nbsp;Undergraduate&nbsp;Courses",
		ftug: "Full&#8209;time&nbsp;Undergraduate&nbsp;Courses",
		comentor: "coMentor",
		ethics: "School&nbsp;Research&nbsp;Ethics&nbsp;Panel",
		primary_care: "Health&nbsp;&amp;&nbsp;Social&nbsp;Studies&nbsp;Staff",
		social_work: "Health&nbsp;&amp;&nbsp;Social&nbsp;Studies&nbsp;Staff",
		com_crim_justice: "Division of Criminal and Community Justice",
		hss: "Health&nbsp;and&nbsp;Social&nbsp;Studies",
		tech_support: "Technical&nbsp;Support",
		summer_school: "Aim&nbsp;Higher/ESF&nbsp;Summer&nbsp;School",
		journal: "Mental&nbsp;Health&nbsp;and&nbsp;Learning&nbsp;Disabilities&nbsp;Research&nbsp;and&nbsp;Practice"
  }
  var urlArray = document.URL.split("/");
  var urlLength = urlArray.length;
  var introArray = new Array();
  var introArrayElement = ".";
  var introArrayLength = 10;
  var segment, file;
  var html1 = "", html2 = "", html3 = "";
  var fileLookup;
  var index;
	var exception;
  for (var i = 0; i < introArrayLength; i++) {
    introArray[i] = introArrayElement;
    introArrayElement += "/..";
  }

  // first, the last section (hierarchical/breadcrumb links).
  html3 += "<p>Links to higher levels:</p<ul class=\"pad_bottom\">";
  index = 0;
  // university-level index file is .html :-(
  var filename = "/index.html";
  for (index = 4; index < urlLength && urlLength - index < introArrayLength; index++) {
    segment = urlArray[index - 2];
		if (segment == "www.google.com" || segment == "services.google.com") {
			// for the search & results pages
			exception = true; // because localHeading is specified as other than ../
			html3 += html_frag_2("http://www.hud.ac.uk" + filename, "University&nbsp;of&nbsp;Huddersfield");
		} else if (segment == "emile.hud.ac.uk") {
			exception = true; // because localHeading is specified as other than ../
			if (localHeading == "modules") {
				// for Module editing suite
				html3 += html_frag_2("http://www.hud.ac.uk" + filename, "University&nbsp;of&nbsp;Huddersfield") + html_frag_2("http://www.hud.ac.uk/hhs" + "/index.htm", "School&nbsp;of&nbsp;Human&nbsp;&amp;&nbsp;Health&nbsp;Sciences") + html_frag_2("http://www.hud.ac.uk/hhs/courses/profdev" + "/index.htm", "CPD&nbsp;Home");
			}
			else if (localHeading == "chscr") {
				// for south west yorkshire health and social care research & development network
				html3 += html_frag_2("http://www.hud.ac.uk" + filename, "University&nbsp;of&nbsp;Huddersfield") + html_frag_2("http://www.hud.ac.uk/hhs" + "/index.htm", "School&nbsp;of&nbsp;Human&nbsp;&amp;&nbsp;Health&nbsp;Sciences") + html_frag_2("http://www.hud.ac.uk/hhs/research/chscr" + "/index.htm", "Centre&nbsp;Home&nbsp;Page");
			} 
			else if (localHeading == "caqdas") {
				// for qualitative data software survey
				html3 = html_frag_2("http://www.hud.ac.uk" + filename, "University&nbsp;of&nbsp;Huddersfield") + html_frag_2("http://www.hud.ac.uk/hhs" + "/index.htm", "School&nbsp;of&nbsp;Human&nbsp;&amp;&nbsp;Health&nbsp;Sciences") + html_frag_2("http://caqdas.soc.surrey.ac.uk/onlineqda" + "/qdahome.htm", "Project&nbsp;Home&nbsp;Page");
			} else {
				// for Template Analysis discussion
				html3 += html_frag_2("http://www.hud.ac.uk" + filename, "University&nbsp;of&nbsp;Huddersfield") + html_frag_2("http://www.hud.ac.uk/hhs" + "/index.htm", "School&nbsp;of&nbsp;Human&nbsp;&amp;&nbsp;Health&nbsp;Sciences") + html_frag_2("http://www.hud.ac.uk/hhs/research" + "/index.htm", "School&nbsp;Research");
			}
			break;
		} else if (!localHeading || (localHeading && localHeading != segment)) {
			// (don't put the link in if it's not needed -- if localHeading is specified, we're pretending
			// the file is in a higher directory. This only works if it's the *next* higher directory! )
			html3 += html_frag_2(introArray[urlLength - index] + filename, directoryLookup[segment.replace(/\./g, "_")]);
		}
    filename = "/index.htm"; // for all except the first (uni) link.
 	}
	if (localHeading == "comentor") {
		html3 += "<li><a href=\"http://www.hud.ac.uk/hhs/index.htm\">School of Human &amp; Health Sciences</a>,</li> <li><a href=\"http://www.hud.ac.uk\">University of Huddersfield</a>.</li>";
	}
  html3 += "</ul>";
  // the default is to make the assignment to segment, but if localHeading is specified in the file,
	// we use that instead. This happens if the file is to be regarded as in ../ hence the first assignment.
	fileintro = (!localHeading || exception) ? "" : ((localHeading.substr(0, 8) == "intranet") ? "http://www.hud.ac.uk/hhs/"+localHeading.substr(9) : "../");
	segment = (!localHeading) ? urlArray[index - 2] : localHeading;
  // doing the last section first allows us to do this assignment (index has been set):
  file = urlArray[index - 1];
  // assemble the intro and #top link.
  html1 += "<p>Navigation:</p><ul>" + html_frag_2("#topanchor", "top&nbsp;of&nbsp;the&nbsp;page") + "</ul>";
  // assemble the sub-site links for the second section; localLookup is specified in the file.
  html2 = html_frag (urlArray[index - 2], file, localLookup, directoryLookup, directoryLookup[segment] + " links:", fileintro);
  return "<span class=\"inner_credits\">" + html1 + html2 + html3 + "</span>";
}

function html_frag (directory, file, array, directories, intro, fileintro) {
//  var index = 1;
  var html = "";
  var found = 0;
  var hash;
	var filename = (hash = file.indexOf("#")) == -1 ? file.slice(0, -4) : file.slice(0, hash - 4);
  for (prop in array) {
//	alert ("directories[prop]: " + directories[prop] + "; prop: " + prop + "; directory: " + directory);
    if (filename == "index" && directories[prop] && prop == directory) {
	  	html += "<li class=\"werehere\">" + directories[prop] + "</li> ";
	  	found = 1;
		} else if ((prop == filename) && !found && !fileintro) {
	  	html += "<li class=\"werehere\">" + array[prop][0] + "</li> ";
    } else {
	  	html += html_frag_2(fileintro + array[prop][1], array[prop][0]);
//	  	index++;
    }
  }
  if (html != "") {
    html = "<p>" + intro + "</p><ul>" + html + "</ul>";
  }
	// alert (html);
  return html
}

function html_frag_2 (url, lnk) {
	html = "";
	if (lnk) {
		html = "<li><a href=\"" + url + "\">" + lnk + "</a></li> ";
	}
	return html;
}

document.write(print_navigation());
