function writeHomeLocation(homeLocation, nameArraySize) 
{
   var currentLocation = new String(location.hostname + location.pathname);
   var homeLocationLength = homeLocation.length;
   if (currentLocation.substr(0, homeLocationLength) == homeLocation)
      for (x = 0; x < nameArraySize; x++)
         document.write("../");
   else document.write("http://" + homeLocation + "/");
}

function randomQuote()
{
   var numQuotes = 14;
   var selection = Math.floor(numQuotes * Math.random());
   if (selection == numQuotes) selection--;
   
   switch(selection)
   {
	  case 0:
	     return new String("Make everything as simple as possible, but not simpler. -A. Einstein");
	  case 1:
	     return new String("You must be the change you wish to see in the world. -M. Ghandi");
      case 2:
	     return new String("If I had more time I would write a shorter letter. -B. Pascal");
	  case 3:
	     return new String("What goes up must come down. Ask any system administrator.");
	  case 4:
	     return new String("If a trainstation is where the train stops, what's a workstation...?");
	  case 5:
	     return new String("Somewhere, something incredible is waiting to be known. -K. Sagan");
	  case 6:
	  	 return new String("Do only what only you can do.  -E. Dijkstra");
	  case 7:
	     return new String("I want to put a ding in the universe. -Steve Jobs");
	  case 8: 
	     return new String("Intellectuals solve problems, geniuses prevent them. -A. Einstein");
	  case 9:
	     return new String("The faster you go, the shorter you are. -A. Einstein");
	  case 10:
	     return new String("All generalizations are false, including this one. -Mark Twain");
	  case 11:
	     return new String("Cauliflower is nothing but cabbage with a college education. -M. Twain");
	  case 12:
	     return new String("Golf is a good walk spoiled. -M. Twain");
	  case 13:
	     return new String("Your theory is crazy, but it's not crazy enough to be true. -N. Bohr");
   }
}

var HOMEHOSTNAME = new String("www.rhythmiccanvas.com");  // primary host of the website eg. "www.cpsc.ucalgary.ca"
var HOMEPATH = new String("");                     // primary path of the website  eg. "/~fuhrer"
var BANNERPICTURE = new String("pictures/martinSmall.jpg");      // path to thumbnail picture in banner
var BUTTONPATH = new String("pictures/button.jpg");   // path to button picture

var homeLocation = new String(HOMEHOSTNAME + HOMEPATH);
var pagepath = new String(location.pathname);
var currentLocation = new String(location.hostname + location.pathname);
var slashIndex = 0;
var prevSlashIndex = 0;
var nameArray = new Array(10);
var urlArray = new Array(10);
var nameArraySize = 0;
var nameFile = "name.txt";

// build array of strings, where each element contains one of the pathname elements
slashIndex = pagepath.indexOf("/", 0);
while (1)
{
   prevSlashIndex = slashIndex;
   slashIndex = pagepath.indexOf("/", prevSlashIndex + 1);
   if (slashIndex < 0) 
   {
      break;
   }
   else 
   {
      nameArray[nameArraySize] = new String(pagepath.substring(prevSlashIndex + 1, slashIndex));
      nameArraySize++;
   }
}

for (x = 0; x < nameArraySize; x++)
{
   urlArray[x] = new String;
   if (nameArraySize - x - 1 < 1)
      urlArray[x] = ".";
   else
      for (y = 0; y < nameArraySize - x - 1; y++)
		 urlArray[x] = urlArray[x] + "../";		 
}


var url, connect, input;
for (x = 0; x < nameArraySize; x++)
{
   nameFile = urlArray[x] + "/name.txt";
   if (document.getElementById){
      objXml = new XMLHttpRequest();
      objXml.open("GET",nameFile,false);
      objXml.send(null);
	  if (objXml.responseText.length < 20)
         nameArray[x] = objXml.responseText;
	  else
      {
         var charCode = nameArray[x].charCodeAt(0);
         if (charCode >= 97)
            nameArray[x] = new String(String.fromCharCode(charCode - 32) + nameArray[x].substr(1));   
      }
   }
   else
   {
      var charCode = nameArray[x].charCodeAt(0);
      if (charCode >= 97)
         nameArray[x] = new String(String.fromCharCode(charCode - 32) + nameArray[x].substr(1));    
   }
}


document.writeln("<table width=\"650\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bgcolor=\"white\" align=\"center\" class=\"titlebarborder\">");
document.writeln("  <tr> ");
document.writeln("    <td rowspan=\"2\" width=\"64\" align=\"center\"><a href =\"");
writeHomeLocation(homeLocation, nameArraySize);
document.writeln("index.html\"> <img border=\"0\" src=\"");
writeHomeLocation(homeLocation, nameArraySize);
document.writeln(BANNERPICTURE + "\" width=\"56\" height=\"56\"></a></td>");
document.writeln("    <td colspan=\"3\" class=\"textSub\">");
document.writeln("      <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
document.writeln("        <tr>");
document.write("            <td width=\"190\"><font face=\"Courier New, Courier, mono\" size=\"6\"><b><a href=\"");

writeHomeLocation(homeLocation, nameArraySize);

document.writeln("index.html\">");
document.writeln("      <img border=\"0\" src=\"");
writeHomeLocation(homeLocation, nameArraySize);
document.writeln("pictures/martinaquaTN.gif\"></a></b></font></td>");
document.writeln("          <td valign=\"bottom\" class=\"pathoffset\">");

if (currentLocation.substr(0, homeLocation.length) == homeLocation)
{ 
   document.writeln("      <span class=\"titlebarhistory\">");
   document.writeln("      <a href=\"");

   writeHomeLocation(homeLocation, nameArraySize);
   
   document.write("index.html\">Home</a>"); 

   // display hierarchical navigation list
   for (x = 0; x < nameArraySize; x++)
   {
      document.write("<a href=\"" + urlArray[x] +"\"> > " + nameArray[x] + "</a>");
   }   
   
   /*
   for (x = 0; x < nameArraySize; x++)
   {
      document.write("<a href=\"");
      if (nameArraySize - x - 1 < 1) 
         document.write(".");
      else
         for (y = 0; y < nameArraySize - x - 1; y++)
            document.write("../");
      document.write("\"> > " + nameArray[x] + "</a>");
   }
   */
   
}
else
{
   document.write("      <span class=\"quotationSmall\">");
   document.write(randomQuote());
}

document.writeln("        </span>");
document.writeln("      </td></tr></table>");
document.writeln("    </td>");
document.writeln("  </tr>");
document.writeln("  <tr> ");

// table data cell for "Research"
document.writeln("    <td width=\"195\" height=\"25\"> ");
document.writeln("       <div align=\"center\">");
document.write("            <table width=\"150\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" background=\"");

writeHomeLocation(homeLocation, nameArraySize);

document.writeln(BUTTONPATH + "\">");
document.writeln("            <tr>");
document.writeln("              <td width=\"150\" height=\"25\"><div align=\"center\"><a href=\"");

writeHomeLocation(homeLocation, nameArraySize);
   
document.writeln("research/index.html\"><font size=\"2\">Research</font></a></div></td> ");
document.writeln("            </tr>");
document.writeln("         </table>");
document.writeln("      </div>");
document.writeln("    </td>");

// table data cell for "Courses"
document.writeln("    <td width=\"195\" height=\"25\"> ");
document.writeln("       <div align=\"center\">");
document.write("            <table width=\"150\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" background=\"");

writeHomeLocation(homeLocation, nameArraySize);

document.writeln(BUTTONPATH + "\">");
document.writeln("            <tr>");
document.writeln("              <td width=\"150\" height=\"25\"><div align=\"center\"><a href=\"");

writeHomeLocation(homeLocation, nameArraySize);
   
document.writeln("software/index.html\"><font size=\"2\">Software</font></a></div></td> ");
document.writeln("            </tr>");
document.writeln("         </table>");
document.writeln("      </div>");
document.writeln("    </td>");

// table data cell for "Personal"
document.writeln("    <td width=\"195\" height=\"25\"> ");
document.writeln("       <div align=\"center\">");
document.write("            <table width=\"150\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" background=\"");

writeHomeLocation(homeLocation, nameArraySize);

document.writeln(BUTTONPATH + "\">");
document.writeln("            <tr>");
document.writeln("              <td width=\"150\" height=\"25\"><div align=\"center\"><a href=\"");

writeHomeLocation(homeLocation, nameArraySize);
   
document.writeln("personal/index.html\"><font size=\"2\">Personal</font></a></div></td> ");
document.writeln("            </tr>");
document.writeln("         </table>");
document.writeln("      </div>");
document.writeln("    </td>");

document.writeln("  </tr>");
document.writeln("</table>");
