/**
* breadcrumb.js
* 
* 5 February 2008
* Milo Schuman
* 
* This script adds a breadcrumb navigation bar to a page.
*
* To use this script, the calling document must have a
* title of the following format:
* <title>CISE :: Category : Sub-category : Current Page</title>
*
* After this script is called, the navbar is inserted as
* an <ul> dom node into a div element with id="breadcrumb".
*/
var breadbox = document.getElementById("breadcrumb");
if(breadbox && breadbox.tagName == "DIV"){
	var crumbs = document.title.split(" :: ")[1].split(" : ");
	if(crumbs.length > 1) {
		var path = new Array(crumbs.length);
		var trail = "<ul>";
		
		// make paths
		if(document.location.href.match("(\/index\.)|(\/[^\.]+$)")){
			// if page is directory index
			path[crumbs.length - 2] = "../"
		}
		else {
			// if page is child of directory index
			path[crumbs.length - 2] = "./";
		}
		
		for(i = crumbs.length - 3; i >= 0; i--){
			path[i] = "../" + path[i+1];
		}
		
		for(i = 0; i < crumbs.length - 1; i++){
			trail += "<li><a href='" + path[i] + "'>" + crumbs[i] + "</a></li>";
		}
		trail += "<li>" + crumbs[crumbs.length-1] + "</li>";
		trail += "</ul>";
		breadbox.innerHTML = trail;
	}
}
