/**
 * Adds a breadcrumb navigation bar to a page.
 *
 * Assumes the calling document has a title in the following format:
 *   <title>CISE :: Category : Sub-category : Current Page</title>
 *
 * After this script is called, the navbar is inserted as an unsorted list into
 * an element with the id of "breadcrumb".
 *
 * @author Milo Schuman <nschuman@cise.ufl.edu>
 * @author Taeber Rapczak <trapczak@cise.ufl.edu>
 */

// Wrap and execute an anonymous function to keep the global namespace clean.
(function () {

var breadbox = document.getElementById("breadcrumb");
if ( breadbox == null ) {
    return;
}

// We ignore the first bit ("CISE :: ") and split the rest.
var crumbs = document.title.split(" :: ")[1].split(" : ");
if ( crumbs.length < 2 ) {
    return;
}

var pathname = window.location.pathname.split("/");

// Create links for all of the crumbs but the last.
var trail = "<ul>";
for ( i = 0, linkcount = crumbs.length - 1; i < linkcount; ++i ) {
    var url = pathname.slice( 0, i + 2 ).join("/");
    var text = crumbs[i];
    trail += '<li><a href="' + url + '">' + text + "</a></li>";
}

// Add a text-only crumb that represents the current page.
trail += "<li>" + crumbs[crumbs.length - 1] + "</li>";

breadbox.innerHTML = trail + "</ul>";

})();

