// JavaScript Document
/*This code take the current location and sperates it out. It then makes a cookie/bread-crumb trail based on the folders
and file that the user is looking at. It makes anchors tag out of the these seperated values. It always makes SBSC the first
anchor tag, it then makes the next folder unless the next folder is the last folder which contains the document that the user
is looking at, it then make and anchor tag for the file the user is on (this is why it skips the last folder, because the
last folder and the file the user is looking at should match). The last part of this code takes the text inside of the 
anchors tags and gets rid of the underscore and replaces it with a space. It also capitalizes the first letter of each word.*/
var path = "";
var realPath = "";
var href = document.location.href;
var s = href.split("/");
//alert(s);
path+="<a href=\"/\"><acronym title=\"Southwest Biological Science Center\">SBSC</acronym></a> | ";
//alert(path);
for (var i=3;i<(s.length-1);i++) {
	path+="<a href=\""+href.substring(0,href.indexOf("/"+s[i])+s[i].length+1)+"/\">"+s[i]+"</a> | ";
	//alert(i +" :||: "+ path);
}
i=s.length-1;
//Getting rid of the last anchor tag text's .htm, have a blah.htm, turns into blah
noDot = (s[i].split("."));
//alert(noDot);
if (noDot.length == 2) {
	path+="<a href=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"\">"+noDot[0]+"</a>"; //previous code
}

theRef = path.split(">");
theNewRef = new Array();
theNewRef[0] = new Array();
for (s=0; s<(theRef.length); s++) {
	theNewRef[s] = theRef[s].split("<");
	if (s==(theRef.length-1)) {
		for (h=5; h<(theNewRef.length); h+=2) {
			theNewRef[h][0] = theNewRef[h][0].replace(/_/g, ' ');
			//re = /^((\S)(\S+))(\s(\S)(\S+))?(\s(\S)(\S+))?$/; //Would split each word then you could take the RegExp Properties and toUpperCase and toLowerCase [limit=couldn't have over 3 words]
			re = /^(\S+)(\s(\S+))?(\s(\S+))?(\s(\S+))?(\s(\S+))?$/;
			re.exec(theNewRef[h][0]);
			theNewRef[h][0] = RegExp.$1.substring(0,1).toUpperCase() + RegExp.$1.substring(1) + "  "+ RegExp.$3.substring(0,1).toUpperCase() + RegExp.$3.substring(1) +"  "+ RegExp.$5.substring(0,1).toUpperCase() + RegExp.$5.substring(1) +"  "+ RegExp.$7.substring(0,1).toUpperCase() + RegExp.$7.substring(1) +"  "+ RegExp.$9.substring(0,1).toUpperCase() + RegExp.$9.substring(1);
			//theNewRef[h][0] = RegExp.$2.toUpperCase() + RegExp.$3.toLowerCase()+"  "+ RegExp.$5.toUpperCase() + RegExp.$6.toLowerCase()+"  "+ RegExp.$8.toUpperCase() + RegExp.$9.toLowerCase();
			/*This next if statement checks to see wether SBSC is in the anchor text, if so CAPATALIZE ALL LETTERS*/
			theNewRef[h][0] = theNewRef[h][0].replace(/And/g, 'and');
			theNewRef[h][0] = theNewRef[h][0].replace(/Sbsc/g, '<acronym title="Southwest Biological Science Center">SBSC</acronym>');
			//theNewRef[h][0] = theNewRef[h][0].replace(/Gcmrc/g, '<acronym title="Grand Canyon Monitoring and Research Center">GCMRC</acronym>');
		}
		for (r=0; r<(theNewRef.length-1); r++) {
			realPath += theNewRef[r][0]+"<"+theNewRef[r][1]+">";
		}
		//
		//Fix names
		//
		realPath = realPath.replace(/About/, 'About <acronym title="Southwest Biological Science Center">SBSC</acronym>');
		//realPath = realPath.replace(/contact\.htm">Contact<\/a>\s\|\s<a\shref="http:\/\/sbsc\.wr\.usgs\.gov\/about\/contact\/bio\//, 'personnel.aspx');
		realPath = realPath.replace(/contact.htm">Contact(\s+)<\/\w>(\s+)\|(\s+)/, 'personnel.aspx">Personnel</a> | ');
		realPath = realPath.replace(/sorted.htm/, 'sorted.aspx');
		realPath = realPath.replace(/Contact/g, 'Contact <acronym title="Southwest Biological Science Center">SBSC</acronym>');
		realPath = realPath.replace(/News(\s+)Info/, 'News &amp; Info');
		realPath = realPath.replace(/Events/, 'Currrent Events');
		realPath = realPath.replace(/Db/, 'Database');
		realPath = realPath.replace(/Personnel/, 'Personnel List');
		realPath = realPath.replace(/Metadata/, 'Data / MetaData');
		realPath = realPath.replace(/Canyonlands/, 'Canyonlands Research Station');
		realPath = realPath.replace(/Plateau/, 'Colorado Plateau Research Station');
		realPath = realPath.replace(/Sonoran/, 'Sonoran Desert Research Station');
		realPath = realPath.replace(/Gcmrc/, 'Grand Canyon Monitoring and Research Center');
		realPath = realPath.replace(/Projects/, 'Project Information');
		realPath = realPath.replace(/Sorted/, 'Products (Pre-Sorted)');
		realPath = realPath.replace(/Forums/, 'Discussion Forums');
		realPath = realPath.replace(/Ofr/, 'Open-File Reports');
		realPath = realPath.replace(/Factsheets/, 'Fact Sheets');
		realPath = realPath.replace(/Spotlight/, 'Product Spotlight');
		realPath = realPath.replace(/\s+<\/A>/g, '</a>');
	}
}

document.writeln(realPath);