// Breadcrumbs script for a site in which the files are named as section_subsection1_subsection2....html

function getBreadcrumbLink(href, text)
{
	return ' &rsaquo;&rsaquo; <a href="' + href + '">' + text + "</a>";
}

// @param displayName the string that will be displayed as the current page name
// @return a breadcrumbs string based on an Array, for files seperated by "_"
function getUrlString(displayName)
{
	// Get Array of components of a URL separated by "/"
	var urlArray = window.location.toString().split("/");
	if (urlArray.length < 4)
	{
		return "";
	}
	
	// for live site remove urlArray[4]
	
	var stringURLOutput = '<a href="' + urlArray[0] + "//" + urlArray[2] + '/index.php">HOME</a>'; 
	
	// Form the path for the highest level directory
	var x = urlArray.length-5;
	var path = "";
	for (var i = 0; i < x; i++)
	{
		path += "../";
	}
	
	// Create the breadcrumb string through the path

	for (var i = 4; i < urlArray.length-1; i++)
	{
		stringURLOutput += getBreadcrumbLink(
			(path + urlArray[i] + ".php"),
			urlArray[i].toUpperCase()
		);
		
		// Adjust the path to go one level lower
		path = path.substring(0, path.length-3);
	}
	
	// Splits the last index of urlArray on "_"
	var stringArray = urlArray[urlArray.length-1].split("_");
	
	// Append to the breadcrumb string for the content pages up to the current page
	for (var i = 0; i < stringArray.length-1; i++)
	{
		stringURLOutput += getBreadcrumbLink(
			stringArray.slice(0, i+1).join("_") + ".php",
			stringArray[i].toUpperCase()
		);
	}
	
	// Append to the breadcrumb string the current page
	stringURLOutput += getBreadcrumbLink(
		stringArray.join("_"),
		displayName);
	
	return stringURLOutput;
}

