	/*	Breadcrumbs script by KatieK.
	Displays heirarchical site structure as naviation aid.
	June 21, 2007
	
	Heirarchy always begins at domain or subdomain.  
	Can configure the string that separates the different directories, as well as the name of your homepage.
	*/

//  Configurables.
var sep = " / ";					//  String to separate directory names
var homeName = "Resume";		//  Name of home page.

//  global variables
var dirNames = [];		//  Directory names
var pageFullUrl;		//  Current URL of the page.
var pageProtocol;		//  http: or https: or even, theoretically, ftp:
var pageDomain;			//  widemile.com or subdomain.widemile.com


function formatDirName(stringIn)
//  This function does many things to format the directory names into user friendly display names.  
{	
	var stringOut = stringIn;	//  The 'fixed' string to be returned.
	var acroIn;					//  String passed into acronym fixer

	//  Trim the first character if not a number or letter.

	//  Capitalize only the first character.  (Concatinate the first char, capitalized, with the sub-string from the second character to the end.)  
	stringOut = stringOut.charAt(0).toUpperCase() + stringOut.substring(1, stringOut.length) ;
	
	//  Uppercase the acronymns
	acroArray = ["html", "php", "asp", "css"];
	acroIn = stringOut;
//	acroIn = acroIn.toLowerCase();		//  ensure that the passed-in string is lower case for comparison with the array variables
	//  loop through the array & look for matches
	for ( j = 0; j < acroArray.length; j++ )
	//  If the passed in string matches an acroArray element, return it's uppercase value.
		{ if ( acroIn.toLowerCase() == acroArray[j] )
			 { stringOut = acroIn.toUpperCase(); }
		}

	//  More custom string replacements which cannot easily be generalized
	if ( stringOut.toLowerCase() == "javascript" )  //  "javascript" into "JavaScript"
	   { stringOut = "JavaScript"; }
	if ( stringOut.toLowerCase() == "html" )  //  "html" into "X/HTML"
	   { stringOut = "X/HTML"; }
	if ( stringOut.toLowerCase() == "graphics_design" )  //  "graphics_design" into "Graphics Design"
	   { stringOut = "Graphics Design"; }
	if ( stringOut.toLowerCase() == "web_design" )  //  "web_design" into "Web Design"
	   { stringOut = "Web Design"; }

	return stringOut;
}


function makeURL(l)
//  Returns an absolute URL based on the passed in index of global array dirNames[]
//  l indicates the deepest (the limit) into dirNames[] we should search.
{
	var theURL = "";		//  URL String to be returned
	var m = 0;				//  counter for reading from inside dirNames[]

	//  Prepare an absolute URL to the current page.
	if ( dirNames[l] )
	{ theURL = pageProtocol + "//" + pageDomain; }

	while ( dirNames[l] )
	{ 
	  theURL = theURL + "/" + dirNames[m];
	  m++;
	  l--;
	}

	return theURL;
}

function writeBreadcrumbs()
//	Writes the breadcrumbs
{	//  Populate the page URL, protocol & domain variables.  
		pageFullUrl = location.href;
		pageProtocol = location.protocol;
		pageDomain = location.hostname;
	
	//  Scrub beginning and end of string.  
		pageShortUrl = pageFullUrl.replace(pageProtocol + "//", "");			//  Remove the protocol and the "//" from the url
		pageShortUrl = pageShortUrl.replace(pageDomain, "");					//  Remove the domain from the url
	
	//  If a leading or trailing "/" exists on the URL, remove it.
		if ( pageShortUrl.charAt(0) == "/" )	
		   { pageShortUrl = pageShortUrl.substring(1); }
		if ( pageShortUrl.charAt(pageShortUrl.length - 1) == "/" )	
		   { pageShortUrl = pageShortUrl.substring(0,pageShortUrl.length - 1); }
	
		//  Split (explode) URL string into an array, separated by "/"
		dirNames = pageShortUrl.split("/");
		//  Remove the last element from the array, since that's the current file name.
		dirNames.pop();
	
		document.write("<div id=\"breadcrumbs\">");
	
		//  Write the 'home' link.
		document.write("<a href=\"" + pageProtocol + "//" + pageDomain  + "\">" + homeName + "</a>" + sep);
	
		i = 0;
		while ( dirNames[i] )
		{ 
		  document.write("<a href=\"");
		  document.write(makeURL(i));
		  document.write("\">");
		  document.write(formatDirName(dirNames[i]));
		  document.write("</a>");
		  document.write(sep);
		  i++;
		}
	
		document.write(nav_title);
		
		//  Close the breadcrumbs div
		document.write("</div>");
}
