/*
Script Name: breadcrumbs.js

Script Overview:
	This JavaScript include file will be placed on all PSHS web pages in order to generate the breadcrumbs.

Script History:
	8/7/2007:
	This script was developed by William D. Malone of SI International
	based on the requirements set forth by FCC personnel and contractors in 
	the Public Safety and Homeland Security for use on the FCC Internet site 
	and released on this date.It was adapted from the breadcrumbs code created
	by Dan Steinman for the FCC Intranet site global.js script.

	11/14/2007:
	This script was updated to include new capitalization features. 

	11/27/2007:
	This script was changed significantly ans is loosely based on the original breadcrumbs 
	code and the breadcrumbs code created by Justin Whitford (www.webreference.com).

*/

// -- Variable Declarations------------------------------------------
sURL = new String;
bits = new Object;
var x = 0;
var stop = 0;

var output = '<a href="http://www.fcc.gov/">FCC</a>&nbsp;&gt;&nbsp;<a href="http://www.fcc.gov/pshs/">PSHSB</a>&nbsp;&gt;&nbsp;';

sURL = location.href;
sURL = sURL.slice(8,sURL.length);
chunkStart = sURL.indexOf("/");
sURL = sURL.slice(chunkStart+1,sURL.length)

function displayBreadcrumbs() {
	while(!stop) {
		chunkStart = sURL.indexOf("/");
		if (chunkStart != -1){
		bits[x] = sURL.slice(0,chunkStart)
		sURL = sURL.slice(chunkStart+1,sURL.length);
		} else {
			stop = 1;
		}
		x++;
	}

	for(var i in bits){
		// Change to i>0 for www.fcc.gov/pshs/
		if (i>0) {
			if (bits[i].length) {
				var name = bits[i].replace(/-/gi, " ");
				name = name.replace(/_/gi, ".");
				name = name.replace(/911/gi, "9-1-1");
				if (name.length <= 6) {
					name = name.toUpperCase();
				} else {
					for (j = 0; j < name.length; j++) {
						if (j == 0) {
							tmpChar = name.substring(0,1).toUpperCase();
							postString = name.substring(1,name.length);
							name = tmpChar + postString;
						} else {
							tmpChar = name.substring(j,j+1);
							if (tmpChar == " " && j < (name.length-1)) {
								tmpChar = name.substring(j+1,j+2).toUpperCase();
								preString = name.substring(0,j+1);
								postString = name.substring(j+2,name.length);
								name = preString + tmpChar + postString;
							}
						}
					}
				}
			}

		output += "<a href=\"";
			for(y=1;y<x-i;y++){
				output += "../";
			}
			output += bits[i] + "/\">" + name + "</a> &nbsp;&gt;&nbsp; ";
		}
	}

document.write(output + document.title);
}


