/*
	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();
// generic labels

breadCrumbLabels["/"] = "Home";
// specific labels
breadCrumbLabels["/index.htm"] = "Welcome to the USITC";

breadCrumbLabels["/site_map/"] = "USITC Site Map";
breadCrumbLabels["/press_room/about_usitc.htm"] = "About the International Trade Commission";

breadCrumbLabels["/calendar/index.htm"] = "This Week's Calendar of Events";
breadCrumbLabels["/calendar/future.htm"] = "Upcoming Calendar Events";


breadCrumbLabels["/docket_services/"] = "Docket Services";
breadCrumbLabels["/docket_services/codingmanual.htm"] = "EDIS Coding Manual";
breadCrumbLabels["/docket_services/dailyfilingreport.htm"] = "EDIS Daily Filing Report";
breadCrumbLabels["/docket_services/edis_announcement.htm"] = "EDIS E-Filing Announcements";
breadCrumbLabels["/docket_services/faq.htm"] = "Frequently Asked Questions (FAQ)";
breadCrumbLabels["/docket_services/staff.htm"] = "Staff";
breadCrumbLabels["/docket_services/who_we_are.htm"] = "Who We Are";

breadCrumbLabels["/employment/benefits.htm"] = "Benefits";
breadCrumbLabels["/employment/Hiring_Process.htm"] = "Hiring Process";
breadCrumbLabels["/employment/HolidaySchedule.htm"] = "Holiday Schedule";
breadCrumbLabels["/employment/Employee_Forms.htm"] = "Personnel Forms";
breadCrumbLabels["/employment/Security.htm"] = "Security Eligibility";
breadCrumbLabels["/employment/Virtual_Tour.htm"] = "Virtual Tour";
breadCrumbLabels["/employment/Worklife_Program.htm"] = "Worklife Program";


breadCrumbLabels["/ethics/summary_ethics_advice.htm"] = "Summary of Ethics Advice";
breadCrumbLabels["/ethics/usitc_ethics_guide.htm"] = "Summary of Ethics Guide";

breadCrumbLabels["/equal_employment/"] = "Office of Equal Employment Opportunity";
breadCrumbLabels["/equal_employment/NoFearActData.htm"] = "No Fear Act Data";
breadCrumbLabels["/equal_employment/AfricanAmericanPrograms.htm"] = "African American Employment Programs";
breadCrumbLabels["/equal_employment/AsianAmericanPrograms.htm"] = "Asian American/Asian Pacific Programs";
breadCrumbLabels["/equal_employment/FederalWomensProgram.htm"] = "Federal Women's Program";
breadCrumbLabels["/equal_employment/Hispanic_Latino.htm"] = "Hispanic/Latino Program";
breadCrumbLabels["/equal_employment/NativeAmericansPrograms.htm"] = "Native American Programs";
breadCrumbLabels["/equal_employment/Disabilities.htm"] = "Persons with Disabilities";


breadCrumbLabels["/intellectual_property/int_prop_publications.htm"] = "337 Publications";

breadCrumbLabels["/oig/"] = "Office of Inspector General";
breadCrumbLabels["/oig/oig_hotline.htm"] = "OIG Hotline";

breadCrumbLabels["/press_room/"] = "Press Room";
breadCrumbLabels["/press_room/news_release_index.htm"] = "News Releases";
breadCrumbLabels["/press_room/news_release/2009/news_release_2009.htm"] = "2009 News Releases";
breadCrumbLabels["/press_room/news_release/2008/news_release_2008.htm"] = "2008 News Releases";
breadCrumbLabels["/press_room/bios.htm"] = "The Commissioners Biography Page";
breadCrumbLabels["/press_room/aranoff.htm"] = "Chairman Shara L. Aranoff";
breadCrumbLabels["/press_room/pearson.htm"] = "Vice Chairman Daniel R. Pearson";
breadCrumbLabels["/press_room/okun.htm"] = "Deanna Tanner Okun";
breadCrumbLabels["/press_room/lane.htm"] = "Charlotte R. Lane";
breadCrumbLabels["/press_room/williamson.htm"] = "Irving A. Williamson";
breadCrumbLabels["/press_room/pinkert.htm"] = "Dean A. Pinkert";
breadCrumbLabels["/press_room/quick_facts.htm"] = "Quick Facts";
breadCrumbLabels["/press_room/gen_info.htm"] = "What the USITC Is and Isn't";
breadCrumbLabels["/press_room/annual_report.htm"] = "Annual Reports";
breadCrumbLabels["/press_room/comm_photos.htm"] = "Commissioner Photos";

breadCrumbLabels["/publications.htm"] = "USITC Publications Archive";

breadCrumbLabels["/ind_econ_ana/"] = "Research and Analysis";
breadCrumbLabels["/research_and_analysis/CommissionPubs.htm"] = "Commission Publications";
breadCrumbLabels["/research_and_analysis/seminars_economics_archive.htm"] = "Economics Analysis Seminar Series Archive";
breadCrumbLabels["/research_and_analysis/seminars_industry_archive.htm"] = "Industry Analysis Seminar Series Archive";
breadCrumbLabels["/research_and_analysis/seminars_economics.htm"] = "Economics Analysis Seminar Series";
breadCrumbLabels["/research_and_analysis/seminars_industry.htm"] = "Industry Analysis Seminar Series";
breadCrumbLabels["/research_and_analysis/office_economics.htm"] = "Office of Economics";
breadCrumbLabels["/research_and_analysis/office_industry.htm"] = "Office of Industry";
breadCrumbLabels["/research_and_analysis/staff_products.htm"] = "Staff Publications";
breadCrumbLabels["/research_and_analysis/What_We_Are_Working_On.htm"] = "What We Are Working On";

breadCrumbLabels["/secretary/apo_forms_and_redbook.htm"] = "APO Forms and Redbook";
breadCrumbLabels["/secretary/fed_reg_notices/service_lists/"] = "APO Service Lists";
breadCrumbLabels["/secretary/foia/"] = "Freedom of Information Act (FOIA) Home Page";
breadCrumbLabels["/secretary/"] = "Office of the Secretary";



breadCrumbLabels["/secretary/rules/"] = "USITC Rules of Practice and Procedure";

breadCrumbLabels["/secretary/fed_reg_notices/meetings/index.htm"] = "Commission Votes";
breadCrumbLabels["/secretary/fed_reg_notices/hearings.htm"] = "Commission Hearings";

breadCrumbLabels["/secretary/foia/"] = "Freedom of Information Act (FOIA) Home Page";
breadCrumbLabels["/secretary/foia/foia_faq.htm"] = "FOIA Frequently Asked Questions";
breadCrumbLabels["/secretary/foia/foia_requests.htm"] = "How to File a FOIA Request";
breadCrumbLabels["/secretary/foia/EO13392.htm"] = "Improving Agency Disclosure of Information (EO 13392)";
breadCrumbLabels["/secretary/foia/foia_readingroom.htm"] = "FOIA Public Reading Room";
breadCrumbLabels["/secretary/foia/foia_ereadingroom.htm"] = "FOIA Electronic Reading Room";
breadCrumbLabels["/secretary/foia_ereadingroom.htm"] = "Electronic Reading Room";
breadCrumbLabels["/secretary/rules/rules_public_comment.htm"] = "Recent Notices Seeking Public Comment";
breadCrumbLabels["/secretary/rules/historical_rules.htm"] = "Historical Rules-Related Notices";
breadCrumbLabels["/secretary/fed_reg_notices/"] = "Federal Register Notices";


breadCrumbLabels["/trade_remedy/"] = "Import Injury";
breadCrumbLabels["/trade_remedy/index.htm"] = " ";
breadCrumbLabels["/trade_remedy/opinions_index.htm"] = "Trade Remedy Publications ";
breadCrumbLabels["/trade_remedy/ad_cvd_orders.htm"] = "AD/CVD Duty Orders ";
breadCrumbLabels["/trade_remedy/731_ad_701_cvd/investigations/active_index.htm"] = "Antidumping and Countervailing Duty Investigations";
breadCrumbLabels["/trade_remedy/sunset_reviews.htm"] = "Five-year (Sunset Reviews)";
breadCrumbLabels["/trade_remedy/global_safeguards.htm"] = "Global and Special Safeguard Investigations";
breadCrumbLabels["/trade_remedy/byrd_amendment.htm"] = "Byrd Amendment";
breadCrumbLabels["/trade_remedy/question.htm"] = "Generic Questionnaires";
breadCrumbLabels["/trade_remedy/731_ad_701_cvd/understanding_ad_cvd.htm"] = "Understanding AD-CVD Investigations ";
breadCrumbLabels["/trade_remedy/understanding_sunset.htm"] = "Understanding Five-year Sunset Reviews ";
breadCrumbLabels["/trade_remedy/understanding_safeguard.htm"] = "Understanding Global Safeguard Investigations ";
breadCrumbLabels["/trade_remedy/pub_opinion_index_safeguards.htm"] = "Commission Opinions on Global Safeguard Investigations ";
breadCrumbLabels["/trade_remedy/731_ad_701_cvd/pub_opinion_index.htm"] = "Commission Opinions on AD-CVD Investigations ";

breadCrumbLabels["/tariff_affairs/hts_bychapter_index.htm"] = "Harmonized Tariff Schedule by Chapter";



//breadCrumbLabels["images/"] = "Images Folder";

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;
		var theProtocol = "";
		var theSite = "";
		
		// strip out the protocol from the path
		theProtocol = thePath.substring(0, thePath.indexOf("://") + 3);
		thePath = thePath.substring(thePath.indexOf("://") + 3);
		
		// strip out the site name
		theSite = thePath.substring(0, thePath.indexOf(sitePrefix));
		thePath = thePath.substring(thePath.indexOf(sitePrefix));
		
		// strip out the site prefix
		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;
		
		// add a "home" link
		// create a bread crumb container
		var breadCrumb = document.createElement("span");
		breadCrumb.setAttribute("class", "breadCrumb");
		
		// determine the crumb label
		// first use the default
		var crumbLabel = "Home";
		
		// second look for a generic label
		if ((breadCrumbLabels[sitePrefix] != null))
		{
			crumbLabel = breadCrumbLabels[sitePrefix];
		}
		
		// third look for a specific label
		if ((breadCrumbLabels[currentPath] != null))
		{
			crumbLabel = breadCrumbLabels[currentPath];
		}
		
		// add the text
		// check to see if there are any crumbs after this one
		if ((0 < crumbs.length) &&
			(crumbs[0] != "index.html") &&
			(crumbs[0] != ""))
		{
			// create a new link
			var linkTag = document.createElement("a");
			linkTag.href = theProtocol + theSite + 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++;
		
		// 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
				// check to see if there are any crumbs after this one
				if ((crumbIndex + 1 < crumbs.length) &&
					(crumbs[crumbIndex + 1] != "index.html") &&
					(crumbs[crumbIndex + 1] != ""))
				{
					// create a new link
					var linkTag = document.createElement("a");
					linkTag.href = theProtocol + theSite + 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);
