// JavaScript Document

/* Bread crumb script
** Judy Schaefer, Interactive Studios, i-stuff.com, 11/15/2007
** Reads the path from document.location.href and writes it out in the form of 
** breadcrumbs. Use underscores in your file & driectory names to have them 
** replaced by spaces in the breadcrumbs. The first letter of each "word" is 
** automatically capitalized. Set sSeparatorto determine the separator character 
** between crumbs. The current page is not hyperlinked.You can override the name 
** of the current page by passing in sPageName, otherwise it's determined from 
** the file name.
*/

function writeBreadcrumbs(sPageName) {
	var sSeparator = ">";
	var path = "";
	var href = document.location.href;
	var s = href.split("/");
	var sText;
	for (var i=2;i<(s.length-1);i++) {
		if (i == 2) {
			path += "<A HREF=\""+href.substring(0,href.indexOf("/"+s[i])+s[i].length+1)+"/\">Home</A>";
		}
		else {
			sText = s[i].split("_");
			path += "<A HREF=\""+href.substring(0,href.indexOf("/"+s[i])+s[i].length+1)+"/\">";
			for (var j=0; j<sText.length; j++) {
				path += sText[j].substring(0,1).toUpperCase();
				path += sText[j].substring(1,sText[j].length) + " ";
			}
			path+="</A>";
		}
		path += " " + sSeparator + " ";
	}
	// this is the last breadcrumb segment, the current page
	if (sPageName.length > 0) { // custom page name has been specified, use that
		path += sPageName;
	}
	else { // do the usual thing & calculate the breadcrumb from the page name
		if ((s[i].indexOf("index.")==0) || (s[i].length==0)) { 
			// don't write out an "Index" breadcrumb, just leave it at the folder name
			// strip the last separator that we aleady added off the end
			// also do this for a "just folder" url like http://domain.com/directory/
			path = path.substring(0, path.length-3);
		}
		else {
			i=s.length-1;
			sText = s[i].split("_");
			for (var j=0; j<sText.length; j++) {
				if (j == sText.length-1) {
					path += sText[j].substring(0,1).toUpperCase();
					path += sText[j].substring(1,sText[j].indexOf(".htm"));
				}
				else {
					path += sText[j].substring(0,1).toUpperCase();
					path += sText[j].substring(1,sText[j].length) + " ";
				}
			}
		}
	}
	document.writeln(path);
}
