/*
 * breadcrumb.js
 * 
 * njohnson@echoalley.com
 * adapted from source on WWW
 *
 * This file builds a breadcrumb trail based on the URL of
 * a page. It parses the string and takes everything between
 * the slashes (/) and assumes that the directory structure
 * mirrors the content structure. For instance,
 * 
 * http://www.echoalley.com/about_us/employee_profiles.php
 * 
 * becomes
 *
 * Home > About Us > Employee Profiles
 *
 * The last member of the breadcrumb trail is never a link because
 * it indicates the current page.
 *
 *
 *
*/

/*
 * Variables
 *
 * These control display of the breadcrumbs
 *
*/

var linkClass = ""; //style of the links
var textClass = ""; //style of plain text

//what is the file extension for the files on this site?
// comment all that are NOT used and add any new ones
var fileTypesAry = new Array (
	'.php',
	'.html',
	'.shtml',
	'.pl',
	'.cgi'
)

//do you want to display the filename on the page you are on?
// 1=yes, 0= no
var showFileName = 1;


/*
 * start the work
 *
*/

document.writeln('<!-- breadcrumb navigation -->');
document.writeln('<span class="'+textClass+'">');

//this is the top level page - the beginning of the breadcrumbs

document.writeln('<a href="/">Home</a> &gt;');

	var href = window.location.href;
	var pathName = window.location.pathname;
	var host = window.location.host;
	var c = 0;
	var u = 0;
	var ac = new Array();
	var acurl = new Array();
	var count = 0;
	
/*
 * Here we build two arrays from the URL. ac is the 'crumb,' acurl is the
 * link associated with it.
 * 
*/
	for(;;)
	{
		URL = unescape(href.substring(0,(href.lastIndexOf("/")) + 1))
		var addcr = href.replace(URL,"")
		if(addcr == host) break;
		URL = URL.slice(0,-1)
		var addurl = href;
		href = URL;
		
		//hide filename if required
		if (showFileName==0)
		{
			var x = fileTypesAry.length;
			for (y=0;y<x;y++)
			{
				fileExt = fileTypesAry[y];
				if(addcr == fileExt) continue;
			}
		}

		// Skip '/' if present in the last charecter in the URL
		if(addcr == "") continue;
		
		if(addcr == "index.shtml") continue;

		if(addcr == "index.php") continue;
		
		//if you would like to replace certain items in the URL with
		//other content, do it like this:
	    //if(addcr == "XXXzzz") addcr = addcr.replace("XXX","NNn");
		// addcr now is 'NNnzzz'
		
		count++;
      	ac[c++] = addcr;
		acurl[u++] =addurl;
		
		myVar = addcr;
	}

	i=0;
	crumbs[i++] = "Home";

	var msg;
	for(itemCount = ac.length-1; itemCount >=0; itemCount--)
	{
		// limit number of crumbs here
		if (i == 8) break;
		
		crumbs[i++] = ac[itemCount];
		setCrumbName();
		
		//display filename without link
		if(itemCount==0)
		{
			msg = ' ' + ac[itemCount];

		}
		//else display link
		else 
		{
			msg = '<a href="' + acurl[itemCount] +  '" class="'+linkClass+'">' + ac[itemCount] + '</a> &gt;'; 
		}
		document.writeln(msg);		
	}
	setCrumbName();
	document.writeln('</span>');

/*
 * function setCrumbName()
 *
 * this function takes the crumb and removes '_', '-', and file extensions
 * as well as capitalizing the first letter of the words.
*/
	function setCrumbName()
	{

		//Put function here to modify directory name values based on
		//hardcoded values.
		
		if (ac[itemCount] == "us") {
			ac[itemCount] = "Home";
			return;
		}
					
		if (ac[itemCount] == "uk") {
			ac[itemCount] = "UK";
			return;
		}
			
		if (ac[itemCount] == "oz") {
			ac[itemCount] = "OZ";
			return;
		}
	

		if (itemCount!=-1)
		{
			// replace "-" with the "_"
			regexp = eval("/" + "xxxxx" + "/g")
			ac[itemCount] = ac[itemCount].replace(regexp,"_")
			

	
			var strList = ac[itemCount].split("_");
			for(k=0;k<strList.length;k++)
			{
				var str = strList[k];
				var substr = (str.substring(0,1)).toUpperCase(); // Retrieves the first letter from the string list
				regexp = eval("/" + str.substring(0,1) + "/")
				str = str.replace(regexp,substr)
				regexp = eval("/" + strList[k] + "/")
				ac[itemCount] = ac[itemCount].replace(regexp,str)
		
			}
			
		// replace "_" with the blank space
		regexp = eval("/" + "_" + "/g")
		ac[itemCount] = ac[itemCount].replace(regexp," ");
		
		//alert(ac[itemCount]);
		
		//take out filename extensions
		if (itemCount==0)
		{
			var x = fileTypesAry.length;
			for (y=0;y<x;y++)
			{
				fileExt = fileTypesAry[y];
				string = ac[itemCount];
				//alert(string.substring(5, string.length));
				var excerpt = (string.substring(string.indexOf(fileExt), string.length));
				//alert('is '+excerpt+' equal to '+fileExt+'?');
				if(excerpt==fileExt) break
			}
		regexp = eval("/" + fileExt + "/g");
		ac[itemCount] = ac[itemCount].replace(regexp,"");
		//alert(ac[itemCount]);
		}
	}
}
