/*
	BreadCrumbs.js
	Errol Sayre
	esayre@olemiss.edu
	
	Provided by the Office of Research and Sponsored Programs
	The University of Mississippi
	
	This script is free to be used but provides no warranty of function or quality.
*/

// BreadCrumb configuration
// set up the site prefix
var sitePrefix = "/";
	// Please note that we don't use the whole prefix, just the important
	//	part that we need for the server so as to make this script easy for
	//	us to migrate between testing and live server. You can use whatever you
	//	like here.

// set up the bread crumb separator text
var breadCrumbSeparator = " > ";

// set up our list of crumb items
	// The bread crumb items refer to items on your site that require special
	//	labels. You can specify a label specifically using the URI of the
	//	file/folder or generically for all occurences of a file/folder.
var breadCrumbLabels = new Array();
// specific labels
//breadCrumbLabels["images/"] = "Images Folder";
	//breadCrumbLabels["/BPSS/"] = "HOME";
	breadCrumbLabels["/BPSS/BPS/"] = "BPSS";
	breadCrumbLabels["/BPSS/"] = "Home";
	breadCrumbLabels["/BPSS/CPS/"] = "CPS";
	breadCrumbLabels["/BPSS/TRN/"] = "Training";
	breadCrumbLabels["/BPSS/NOTICES/"] = "Notices";
	breadCrumbLabels["/BPSS/TRN/ELECT/"] = "Electives";
	breadCrumbLabels["/BPSS/TRN/CORE/"] = "Core Courses";
	breadCrumbLabels["/BPSS/TRN/SEM/"] = "Seminars";
// generic labels
//breadCrumbLabels["staff.html"] = "Staff List";
	breadCrumbLabels["bps.asp"] = "Welcome";
	breadCrumbLabels["bps_body.asp"] = "Welcome";
	breadCrumbLabels["Links.asp"] = "Links"; 
	breadCrumbLabels["PriNot.asp"] = "Privacy Notice";
	breadCrumbLabels["site.asp"] = "Site Map";
	breadCrumbLabels["cdr.asp"] = "Past Commanders";
	breadCrumbLabels["cpsMembership.asp"] = "CPS Membership";
	breadCrumbLabels["cps.asp"] = "About CPS";
	breadCrumbLabels["Bridge.asp"] = "The Bridge";
	breadCrumbLabels["abtBPS.asp"] = "About BPSS";
	breadCrumbLabels["Evnts.asp"] = "Events & Calendar";
	breadCrumbLabels["Boat.asp"] = "Boating";
	breadCrumbLabels["Pilot.asp"] = "Piloting";
	breadCrumbLabels["AdvPilot.asp"] = "Advanced Piloting";
	breadCrumbLabels["Celestial.asp"] = "Celestial Navigation";
	breadCrumbLabels["Maint.asp"] = "Marine Maintenance";
	breadCrumbLabels["Elect.asp"] = "Marine Electronics";
	breadCrumbLabels["Power.asp"] = "Power Boating";
	breadCrumbLabels["Sail.asp"] = "Seamanship Sail";
	breadCrumbLabels["Weather.asp"] = "Fundamentals of Weather";
	breadCrumbLabels["WeatherG.asp"] = "Global Weather";
	breadCrumbLabels["Cruise.asp"] = "Extended Cruising";
	breadCrumbLabels["BoatPro.asp"] = "BoatPro Seminar";
	breadCrumbLabels["VHF.asp"] = "Maritime Radio (VHF) Seminar";
	breadCrumbLabels["GPS.asp"] = "Navigating with GPS Seminar";
	breadCrumbLabels["Instruct.asp"] = "Instructor Development";
	breadCrumbLabels["JN.asp"] = "Junior Navigation";
	
	
	
	breadCrumbLabels["06GradNotice.asp"] = "2006 Graduation";
	breadCrumbLabels["060520BurkeObit.asp"] = "P/D/C Burke - 12 May 06";
	breadCrumbLabels["06CoursesNotice.asp"] = "Winter 2007 Courses";
	breadCrumbLabels["06RegistrationNotice.asp"] = "Fall Courses Registration";
	breadCrumbLabels["060726Sailboat4Sale.asp"] = "Sailboat for Sale";
	breadCrumbLabels["061019WineAndCheese.asp"] = "Wine & Cheese";
	breadCrumbLabels["061107NavWithGPS.asp"] = "Navigating with GPS";
	breadCrumbLabels["TrnPgm.asp"] = "Training Program";
	breadCrumbLabels["061104NatConfVol.asp"] = "National Conference - Volunteers Needed";
	breadCrumbLabels["Boats.asp"] = "Member's Boats";
	breadCrumbLabels["061215Dinner.asp"] = "Christmas Party";
	breadCrumbLabels["07Flotilla.asp"] = "2007 Flotilla ?";
	breadCrumbLabels["Phonetic.asp"] = "Maritime Radio - Phonetic Alphabet";
	breadCrumbLabels["070205Charts4Sale.asp"] = "Charts for Sale";
	breadCrumbLabels["Vol.asp"] = "Volunteering";
	breadCrumbLabels["VolFormProcess.asp"] = "Volunteer Acknowldgement";
	breadCrumbLabels["Budget.asp"] = "Budget Highlights";
	breadCrumbLabels["MO_BridgeDocs.asp"] = "Bridge Documents";
	breadCrumbLabels["LoginBPS.asp"] = "Member's Only Login";
	
	
	
	breadCrumbLabels["History.asp"] = "Introduction";
	breadCrumbLabels["History.asp?FileName=1964.asp&Title=YEAR~No:~1~-~1964~to~1965"] = "Year No: 1 - 1964 / 1965";
	breadCrumbLabels["History.asp?FileName=1965.asp&Title=YEAR~No:~2~-~1965~to~1966"] = "Year No: 2 - 1965 / 1966";
	breadCrumbLabels["History.asp?FileName=1966.asp&Title=YEAR~No:~3~-~1966~to~1967"] = "Year No: 3 - 1966 / 1967";
	breadCrumbLabels["History.asp?FileName=1967.asp&Title=YEAR~No:~4~-~1967~to~1968"] = "Year No: 4 - 1967 / 1968";
	breadCrumbLabels["History.asp?FileName=1968.asp&Title=YEAR~No:~5~-~1968~to~1969"] = "Year No: 5 - 1968 / 1969";

	breadCrumbLabels["History.asp?FileName=1969.asp&Title=YEAR~No:~6~-~1969~to~1970"] = "Year No: 6 - 1969 / 1970";
	breadCrumbLabels["History.asp?FileName=1970.asp&Title=YEAR~No:~7~-~1970~to~1971"] = "Year No: 7 - 1970 / 1971";
	breadCrumbLabels["History.asp?FileName=1971.asp&Title=YEAR~No:~8~-~1971~to~1972"] = "Year No: 8 - 1971 / 1972";
	breadCrumbLabels["History.asp?FileName=1972.asp&Title=YEAR~No:~9~-~1972~to~1973"] = "Year No: 9 - 1972 / 1973";
	breadCrumbLabels["History.asp?FileName=1973.asp&Title=YEAR~No:~10~-~1973~to~1974"] = "Year No: 10 - 1973 / 1974";

	breadCrumbLabels["History.asp?FileName=1974.asp&Title=YEAR~No:~11~-~1974~to~1975"] = "Year No: 11 - 1974 / 1975";
	breadCrumbLabels["History.asp?FileName=1975.asp&Title=YEAR~No:~12~-~1975~to~1976"] = "Year No: 12 - 1975 / 1976";
	breadCrumbLabels["History.asp?FileName=1976.asp&Title=YEAR~No:~13~-~1976~to~1977"] = "Year No: 13 - 1976 / 1977";
	breadCrumbLabels["History.asp?FileName=1977.asp&Title=YEAR~No:~14~-~1977~to~1978"] = "Year No: 14 - 1977 / 1978";
	breadCrumbLabels["History.asp?FileName=1978.asp&Title=YEAR~No:~15~-~1978~to~1979"] = "Year No: 15 - 1978 / 1979";

	breadCrumbLabels["History.asp?FileName=1979.asp&Title=YEAR~No:~16~-~1979~to~1980"] = "Year No: 16 - 1979 / 1980";
	breadCrumbLabels["History.asp?FileName=1980.asp&Title=YEAR~No:~17~-~1980~to~1981"] = "Year No: 17 - 1980 / 1981";
	breadCrumbLabels["History.asp?FileName=1981.asp&Title=YEAR~No:~18~-~1981~to~1982"] = "Year No: 18 - 1981 / 1982";
	breadCrumbLabels["History.asp?FileName=1982.asp&Title=YEAR~No:~19~-~1982~to~1983"] = "Year No: 19 - 1982 / 1983";
	breadCrumbLabels["History.asp?FileName=1983.asp&Title=YEAR~No:~20~-~1983~to~1984"] = "Year No: 20 - 1983 / 1984";

	breadCrumbLabels["History.asp?FileName=1984.asp&Title=YEAR~No:~21~-~1984~to~1985"] = "Year No: 21 - 1984 / 1985";
	breadCrumbLabels["History.asp?FileName=1985.asp&Title=YEAR~No:~22~-~1985~to~1986"] = "Year No: 22 - 1985 / 1986";
	breadCrumbLabels["History.asp?FileName=1986.asp&Title=YEAR~No:~23~-~1986~to~1987"] = "Year No: 23 - 1986 / 1987";
	breadCrumbLabels["History.asp?FileName=1987.asp&Title=YEAR~No:~24~-~1987~to~1988"] = "Year No: 24 - 1987 / 1988";
	breadCrumbLabels["History.asp?FileName=1988.asp&Title=YEAR~No:~25~-~1988~to~1989"] = "Year No: 25 - 1988 / 1989";

	breadCrumbLabels["History.asp?FileName=1989.asp&Title=YEAR~No:~26~-~1989~to~1990"] = "Year No: 26 - 1989 / 1990";

	
function displayBreadCrumbs(attempts)
{
	// locate the breadcrumb container
	var theBreadCrumbBar = null;
	if (document.all)
	{
		theBreadCrumbBar = document.all.BreadCrumbBar;
	}
	else
	{
		theBreadCrumbBar = document.getElementById("BreadCrumbBar");
	}
	
	// check to make sure that we have our breadcrumb bar
	if (theBreadCrumbBar != null)
	{
		// get the current url
		// we'll want to ensure that we get the start of our site so, we'll
		//	ignore everything up to and including our site prefix
		var thePath = location.href;
		// determine if the path has a protocol
		if (thePath.indexOf("://") > -1)
		{
			thePath = thePath.substring(thePath.indexOf("://") + 3);
		}
		// determine if the site prefix is present
		if (thePath.indexOf(sitePrefix) > -1)
		{
			thePath = thePath.substring(thePath.indexOf(sitePrefix) + sitePrefix.length);
		}
		
		// remove hash links
		var theHash = "";
		if (thePath.indexOf("#") > -1)
		{
			theHash = thePath.substring(thePath.indexOf("#"));
			thePath = thePath.substring(0, thePath.indexOf("#"));
		}
		
		// break out the individual pieces of the location
		var crumbs = thePath.split("/");
		var currentPath = sitePrefix;
		var crumbCount = 0;
		
		// loop through the crumbs
		for (var crumbIndex = 0; crumbIndex < crumbs.length; crumbIndex++)
		{
			// setup the current path
			currentPath += crumbs[crumbIndex];
			if (crumbIndex + 1 < crumbs.length)
			{
				currentPath += "/";
			}
			
			if ((crumbs[crumbIndex] != "") &&
				(crumbs[crumbIndex].indexOf("index.html") == -1))
			{
				// add this crumb to the list
				// create a bread crumb container
				var breadCrumb = document.createElement("span");
				breadCrumb.setAttribute("class", "breadCrumb");
				
				// add a greater than to the left hand side
				if (crumbCount > 0)
				{
					breadCrumb.appendChild(document.createTextNode(breadCrumbSeparator));
				}
				
				// determine the crumb label
				// first use the crumb itself
				var crumbLabel = crumbs[crumbIndex].replace(/_/g, " ").replace(".html", "").capitalize();
				
				// second look for a generic label
				if ((breadCrumbLabels[crumbs[crumbIndex]] != null))
				{
					crumbLabel = breadCrumbLabels[crumbs[crumbIndex]];
				}
				
				// third look for a specific label
				if ((breadCrumbLabels[currentPath] != null))
				{
					crumbLabel = breadCrumbLabels[currentPath];
				}
				
				// add the text
				if ((crumbIndex + 1 < crumbs.length) &&
					(crumbs[crumbIndex + 1] != "index.html") &&
					(crumbs[crumbIndex + 1] != ""))
				{
					// create a new link
					var linkTag = document.createElement("a");
					linkTag.href = currentPath;
					linkTag.appendChild(document.createTextNode(crumbLabel));
					breadCrumb.appendChild(linkTag);
				}
				else
				{
					// add the text together
					breadCrumb.appendChild(document.createTextNode(crumbLabel));
				}
				theBreadCrumbBar.appendChild(breadCrumb);
				
				// increment our count of crumbs
				crumbCount++;
			}
		}
	}
	else if (attempts < 5)
	{
		// try again in a few seconds
		attempts++;
		setTimeout("displayBreadCrumbs(" + attempts + ");", 1000);
	}
}

// add a handy function to the string class
String.prototype.capitalize = function()
{
	return this.replace(/\w+/g, function(a)
	{
		return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
	});
};

// set us up to display bread crumbs
displayBreadCrumbs(1);
