// JavaScript Document
//This bit of JavaScript generates a common menu for all the general pages on my web site.
//Changes to this code will be reflected in my home page, and in the Career, Research and IPSSI pages.

p = document.URL;                                           //Where are we? (e.g. "http://www.computing.dcu.ie/~howard/text/IPPSI.html"
dirs = p.split("/");                                        //Break out the parts (e.g. "http:" "" "www.computing.dcu.ie" "~howard" "text" "IPPSI.html"
root = "";
last = dirs.length -1
page = dirs[last];
rootPage = "~howard"											//Root directory for this set of pages

//for (i = last; (i > 0) && (dirs[i] != "~howard"); i--)      //Work out the path back to the "Root" directory. (e.g. "../")
for (i = last; (i > 0) && (dirs[i] != rootPage); i--)			 //Work out the path back to the "Root" directory. (e.g. "../")
{
	if (i < last)
	{
		root = root + "../";
		page = dirs[i] + "/" + page;
	}
}
if (i == last-1)                                            //Means we are already in the "Root" directory
{
	root = "./";
}

if (p.substring(p.length-1, p.length) == "/")
{
	page = "./"
}

//	document.write("page: " + page + "<br>");
//	document.write("root: " + root + "<br>");
																//Images for headings
	var imageSource = new Array(	"images/home.jpg",									//Home
									"images/research.jpg",								//Research
									"images/publications.jpg",							//Publications
									"images/teaching.jpg",								//Teaching
									"images/projects.jpg",								//Project Proposals
									"images/administration.jpg",						//Administration
									"images/calendar.jpg",								//Calendar
									"images/personal.jpg",								//Personal
									"",
									"images/computing.jpg",								//Computing Home
									"images/faculty.jpg",								//Faculty Home
									"images/dcu.jpg",									//DCU Home
									"",
									"images/ics.jpg");									//ICS
																//Images for mouseover headings
	var imageSourceO = new Array(	"images/home-o.jpg",								//Home
									"images/research-o.jpg",							//Research
									"images/publications-o.jpg",						//Publications
									"images/teaching-o.jpg",							//Teaching
									"images/projects-o.jpg",							//Project Proposals
									"images/administration-o.jpg",						//Administration
									"images/calendar-o.jpg",							//Calendar
									"images/personal-o.jpg",							//Personal
									"",
									"images/computing-o.jpg",							//Computing Home
									"images/faculty-o.jpg",								//Faculty Home
									"images/dcu-o.jpg",									//DCU Home
									"",
									"images/ics-o.jpg");								//ICS
																//Image names
	var imageName = new Array(	"home",													//Home
								"research",												//Research
								"publications",											//Publications
								"teaching",												//Teaching
								"projects",												//Project Proposals
								"administration",										//Administration
								"calendar",												//My Calendar
								"personal",												//Personal
								"",
								"computing",											//Computing Home
								"faculty",												//Faculty Home
								"dcu",													//DCU Home
								"",
								"ics");													//ICS
																//Alt names for main heading images
	var altName     = new Array("Home",													//Home
								"Research",												//Research
								"Publications",											//Publications
								"Teaching",												//Teaching
								"Project Proposals",									//Project Proposals
								"Administration",										//Administration
								"My Calendar",											//My Calendar
								"Personal",												//Personal
								"",
								"Computing Home",										//Computing Home
								"Faculty of Engineering and Computing",					//Faculty Home
								"DCU Home",												//DCU Home
								"",
								"Irish Computer Society");								//ICS
																//URLs for detailed links
	var linkUrl = new Array(	"index.html",											//Home
								"research/index.html",									//Research
								"publications/index.html",								//Publications
								"teaching/index.html",									//Teaching
								"projects/index.html",									//Project Proposals
								"administration/index.html",							//Administration
								"calendar/index.html",									//My Calendar
								"personal/index.html",									//Personal
								"",
								"http://www.computing.dcu.ie/",							//Computing Home
								"http://www.dcu.ie/engineering_and_computing/index.shtml",	//Faculty Home
								"http://www.dcu.ie/",									//DCU Home
								"",
								"http://www.ics.ie/");									//ICS Home
	entries = linkUrl.length;												//Last heading to be include in the loop


// Loop for writing the body of the menu.

	for (i=0; i < entries; i++)								// Loop for main headings
	{
		if (linkUrl[i] == "")
		{
			document.write("<hr>");
		}
		else
		{
			if (page == linkUrl[i])
			{								//No link for current page
				document.write("<img src=\"" + root + imageSource[i] + "\" alt=\"" + altName[i] + "\" name=\"" + imageName[i] + "\" width=\"140\" height=\"34\" border=\"0\">");
			}
			else
			{
				if (linkUrl[i].substring(0,7)=="http://")
				{														//"Foreign" link
					document.write("<a href=\"" + linkUrl[i] + "\" ");
				}
				else
				{														//internal link
					document.write("<a href=\"" + root + linkUrl[i] + "\" ");
				}
				document.write("onMouseOut=\"MM_swapImgRestore() \" ");
				document.write("onMouseOver=\"MM_swapImage('" + imageName[i] + "','','" + root + imageSourceO[i] + "',1)\">");
				document.write("<img src=\"" + root + imageSource[i] + "\" alt=\"" + altName[i] + "\" name=\"" + imageName[i] + "\" width=\"140\" height=\"34\" border=\"0\">");
				document.write("</a>");
			}
			document.write("<br>");
			document.write("<img src=\"" + root + "images/spacer.gif\" height=\"5\">");
			document.write("<br>");
		}
	}