// Bread Crumb Trail Creator
// by: Tom Nolan - April 8, 2004
// for: University of New Hampshire Website

// *** Customisable Settings ** //
// root - this variable should be the root path to the root index page
//  !!! IMPORTANT NOTE !!!
//      Note: do not put the final slash after the last directory of the root website
var root = "http://www.unh.edu/";

// rootTitle - this is the name of the root webpage that should display in the bread crumbs
var rootTitle = "UNH Home";

// delim - this is the delimiter for the different bread crumbs &gt;
var delim = "<span id='carrot'> &gt;&gt;</span>";

// Bread Crumbs - These are the names of the folder paths and the names they should display
// Use the name of the folder with the "/" before it, then use "<==>" to seperate it from the alias
// and list the alias.  These folders will be case sensitive.
var bcTrail = new Array(
	"/academics<==>Academics",
	"/administration<==>Administration",
	"/alumni<==>Alumni",
	"/athletics<==>Athletics and Recreation",
	"/current<==>Current Students",
	"/faculty<==>For Faculty & Staff",
	"/finance<==>Finance & Administration",
	"/nhoutdoors<==>New Hampshire Outdoors",
	"/outreach<==>Outreach",
	"/parents<==>For Parents & Friends",
	"/prospective<==>Prospective Students",
	"/research<==>Research",
	"/sitemap<==>Site Map",
	"/ucm<==>University Communications and Marketing",
	"/welcome<==>Welcome",
	"/tomtest<==>Tom's Test Folder"
);

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *** //
// *** Do not change anything below this line *** //
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *** //
if (root.charAt(root.length-1) == "/") // fix the slash if the person configuring this script didnt read the note
  root = root.substring(0, root.length - 1);
var path = location.toString();  // current file path
var tmp = path.substr(root.length, path.length - root.length);
var page = tmp.substring(tmp.lastIndexOf("/"), tmp.length); // current page name
var cdir = path.substring(root.length, path.lastIndexOf("/") + 1); // current directory structure

// Function CreateBreadCrumbs
// Parameters:
//   bcPageTitle - Title for the crumb of the current page
// Results:
//   Prints out to the screen the entire bread crumb structure for this page
function CreateBreadCrumbs()
{
  if (document.title.indexOf(" - ") < 0)
	  bcPageTitle = document.title;
	else
		bcPageTitle = document.title.substring(document.title.indexOf(" - ") + 3, document.title.length);
  document.write ("<a href=\"" + root + "\/\" >" + rootTitle + "</a>");
  if (path != root || bcPageTitle != "")
    document.write (delim);
    
  var sls = true;
  var csl = -1;
  var osl = 0;

  while(sls==true)
  {
    osl = csl;
    csl = cdir.indexOf("/", csl+1);
    if (csl >= 0)
    {
      for (var x=0;x<bcTrail.length;x++)
      {
        if (bcTrail[x].substring(0, bcTrail[x].indexOf("<==>")) == cdir.substring(0, csl))
          WriteCBT(x, bcPageTitle);
      }
    }
    else
      sls = false;
  }
  
  document.write ("<span id='pgTitle'> " + bcPageTitle + "</span>");
}

// Function WriteCBT
// Parameters:
//   i - The index in the bread crumb array to write
//   t - The title of the current page, used for printing the delimiter
// Results:
//   Prints out the i-th bread crumb
function WriteCBT(i, t)
{
  var wAddress = root + bcTrail[i].substring(0, bcTrail[i].indexOf("<==>"));
  var wTitle = bcTrail[i].substring(bcTrail[i].indexOf("<==>") + 4, bcTrail[i].length);
  if (t != wTitle)
  {
    document.write(" <a href=\"" + wAddress + "\/\" >" + wTitle + "</a> ");
    document.write(delim);
  }
}