/*****
Dynamic Javascript Breadcrumb Navigation by Adam DuVander
http://duvinci.com/projects/javascript/crumbs/

Released under Creative Commons License:
http://creativecommons.org/licenses/by/2.5/

Modified by Phil Kelsey
Communications & Public Relations
Vancouver Island University
http://www.viu.ca/communications/
14 July 2010
*****/
var crumbsep = " > ";
var precrumb = "<span class=\"crumb\">";
var postcrumb = "</span>";
var urlsep = "/";
var rootpath = "/"; // Use "/" for root of domain.
var rootname = "viu.ca";

var ucfirst = 1; // uppercase first letter? if set to 1, makes "directory" default to "Directory"
// showpage: specifies what to display as the current page in the crumb. Set to "" to show nothing
var pipeIndex = document.title.indexOf("|");
var showpage = (pipeIndex > 0 ? document.title.substring(0, pipeIndex) : document.title);

var objurl = new Object;
// objurl['wierddirectoryname'] = 'Nice Directory Name'; // alias for specified directory name

// research_dev:
objurl['about'] = 'About VIU';
objurl['aboutresearchatVIU'] = 'About Research At VIU';
objurl['alumni'] = 'Alumni Office';
objurl['animalcare'] = 'Animal Care';
objurl['Brag-Page'] = 'Brag Page';
objurl['calendar'] = 'Calendar';
objurl['cc'] = 'Cultural Connections';
objurl['Current-Students'] = 'Current Students';
objurl['elections'] = 'Faculty and Staff Elections';
objurl['employee'] = 'Employees';
objurl['FAQ'] = 'Frequently Asked Questions';
objurl['facultyhelp'] = 'Faculty Help';
objurl['FineArts'] = 'Art, Design &amp; Performing Arts Programs';
objurl['forestry_dev'] = 'Forestry';
objurl['ForFaculty'] = 'Faculty';
objurl['ForStudents'] = 'Students';
objurl['FrontSection'] = 'Introduction';
objurl['GeneralInformation'] = 'General Information';
objurl['giving'] = 'Development &amp; Alumni Relations Office';
objurl['Giving'] = 'Development &amp; Alumni Relations Office';
objurl['hhs'] = 'Health and Human Services';
objurl['india'] = 'Centre for Canadian Education - India';
objurl['international'] = 'International Education';
objurl['liberalstudies'] = 'Liberal Studies';
objurl['mba2012'] = 'Master of Business Administration';
objurl['milnergardens'] = 'Milner Gardens &amp; Woodland';
objurl['pnwnas'] = 'Pacific Northwest Numerical Analysis Seminar (PNWNAS)';
objurl['PNWNAS'] = 'Pacific Northwest Numerical Analysis Seminar (PNWNAS)';
objurl['Prospective-Students'] = 'Prospective Students';
objurl['provostcouncil'] = 'Provost Council';
objurl['renew'] = 'Renew with VIU';
objurl['ResearchandScholarlyActivityCommittees'] = 'Committees';
objurl['ResearchChairs'] = 'Research Chairs';
objurl['ResourcesForFaculty'] = 'Faculty Resources';
objurl['ResourcesForStudents'] = 'Student Resources';
objurl['sas'] = 'Services for Aboriginal Students';
objurl['scienceandtechnology'] = 'Science and Technology';
objurl['severe-weather'] = 'Closure due to Severe Weather';
objurl['socialmedia'] = 'Social Media';
objurl['Success-Tips'] = 'Success Tips';
objurl['unitedway'] = 'United Way';
objurl['VIU-Policies'] = 'VIU Policies';
objurl['year-of-science'] = 'Year of Science';

// Grab the page's url and break it up into directory pieces
var pageurl = (new String(document.location));
var protocol = pageurl.substring(0, pageurl.indexOf("//") + 2);
pageurl = pageurl.replace(protocol, ""); // remove protocol from pageurl
var rooturl = pageurl.substring(0, pageurl.indexOf(rootpath) + rootpath.length); // find rooturl
if (rooturl.charAt(rooturl.length - 1) == "/") //remove trailing slash
{
  rooturl = rooturl.substring(0, rooturl.length - 1);
}
pageurl = pageurl.replace(rooturl, ""); // remove rooturl from pageurl
if (pageurl.charAt(0) == '/') // remove beginning slash
{
  pageurl = pageurl.substring(1, pageurl.length);
}

var page_ar = pageurl.split(urlsep);
var currenturl = protocol + rooturl;
var allbread = precrumb + "<a href=\"" + currenturl + "\">" + rootname + "</a>" + postcrumb; // start with root

for (i=0; i < page_ar.length-1; i++)
{
  var displayname = "";
  currenturl += "/" + page_ar[i];
  if (objurl[page_ar[i]])
  {
    displayname = objurl[page_ar[i]];
  }
  else
  {
    if (ucfirst == 1)
    {
      displayname = page_ar[i].charAt(0).toUpperCase() + page_ar[i].substring(1);
    }
    else
    {
      displayname = page_ar[i];
    }
  }
  allbread += crumbsep + precrumb + "<a href=\"" + currenturl + "\">" + decodeURIComponent(displayname) + "</a>" + postcrumb;
}

var pathname = window.location.pathname;
var pagename = pathname.substring(pathname.lastIndexOf('/') + 1);
var isHome = pagename=="" || pagename.indexOf("index")==0;

if (showpage != "" && !isHome)
{
  allbread += crumbsep + showpage;
}
document.write(allbread);


