//-------------JS Breadcrumbs for SCOSA ---------------
//Usage:
// document.write(allbread); //<--put this on the page...it will write the crumb trail
// Warning: This Version only works for 3 levels: Home > Section > Page
// The Breadcrumb grabs the page title based on the last occurence of the pipe | char, so the | is *required* in page titles
/////////////////////////////////////////////

var crumbsep = " > ";
var precrumb = "<span class=\"crumb\">";
var postcrumb = "</span>";
var sectionsep = "/";
var rootpath = "/"; // Use "/" for root of domain.  //<------- //////////// CHANGE THIS TO '/' AT LAUNCH ///////////////
var rootname = "Home";
var ucfirst = 1; // var to set uppercase first letter...if set to 1, ex: "home" will display as "Home"
var landingurl = new Object;
landingurl['trails'] = 'Trails + Preserves';//use this object to rename crumbs
landingurl['urban'] = 'Urban Open Space';
landingurl['about'] = 'About OSA';
landingurl['news'] = 'News + Media';
////////////////////////////////////////



// 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 http:// 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(sectionsep);
var currenturl = protocol + rooturl;
var allbread = precrumb + "<a href=\"" + currenturl + "\">" + rootname + "</a>" + postcrumb; // start with root

//strip away beginning of page title (based on 3 levels):
var titleArray = document.title.split(" | ");
var crumb_title = "";
if (titleArray[2] == undefined) {
	crumb_title="";
}else{
	crumb_title = crumbsep + titleArray[2];
}


for (i=0; i < page_ar.length-1; i++)
{
  var displayname = "";
  currenturl += "/" + page_ar[i];
  if (landingurl[page_ar[i]])
  {
    displayname = landingurl[page_ar[i]];
  }
  else
  {
    if (ucfirst == 1)
    {
      displayname = page_ar[i].charAt(0).toUpperCase() + page_ar[i].substring(1);// Capitalize
    }
    else
    {
      displayname = page_ar[i];
    }
  }
  allbread += crumbsep + precrumb + "<a href=\"" + currenturl + "\">" + displayname + "</a>" + postcrumb + crumb_title;

}

