// functions

function itemCount(stringVar,delimeter)
// this function returns the number of items in the string, as marked by the delimiter character
{
matches = 0;
stringVarLength = stringVar.length;
	for (var P = 1; P <= stringVarLength; P++)
	{
		charVal = stringVar.charAt(P);
		if (charVal == delimeter) { matches = matches + 1; }
	}
matches = matches + 1;
return (matches);
}


function getItem(posNum,stringVar,delimeter)
{
// set variables
stringVarLength = stringVar.length;
matches = 0;
prevPos = 0;
currentPos = -1;

// end if  if delimeter is at first character (nothing before that!)
if ( (posNum == 1) && (stringVar.charAt(0) == delimeter) )
	{ zResult = ""; }
else
{
// continue on, find position in string based on delimiter
	for (var P = 1; P <= stringVarLength; P++)
	{
		if (stringVar.charAt(P) == delimeter)
			{
				prevPos = currentPos;
				currentPos = P;
				matches = matches + 1;
			}
		if (matches == posNum) {break}
	}

	if (P > stringVarLength)
		{
			prevPos = currentPos;
			currentPos = (P - 1);
		}
	prevPos = prevPos + 1;

	position = stringVar.substring(prevPos,currentPos);
}

	return (position);
}


// set up variables

thisURL = document.URL;
numURLparts = itemCount(thisURL,"/");
pageURLname = getItem(numURLparts,thisURL,"/");

pageURLpart = getItem(1,pageURLname,".");	// take off any file extensions

numLevels = itemCount(pageURLpart,"_");	// number of hierarchy levels



arrow = ' <span class="crumbArrows">&#187;<\/span> ';
trailLev1 = '<a href="index.shtml" class="crumbLink">Main Page<\/a>';
trailLev2 = "";
trailLev3 = "";
fullTrail = "";
// 2 hierarchy levels is the max


// **** 1 level = home + initial section (like about us, enterprise, or site map) ****
if (numLevels == 1)
{
	if (pageURLpart == "aboutus")		{ trailLev2 = 'About Us'; }
	if (pageURLpart == "services")		{ trailLev2 = 'Services'; }
	if (pageURLpart == "portfolio")		{ trailLev2 = 'Portfolio'; }
	if (pageURLpart == "news")		{ trailLev2 = 'News'; }
	if (pageURLpart == "contact")		{ trailLev2 = 'Contact Us'; }
	if (pageURLpart == "employment")	{ trailLev2 = 'Employment Opportunities'; }
	if (pageURLpart == "sitemap")		{ trailLev2 = 'Site Map'; }
	if (pageURLpart == "legal")		{ trailLev2 = 'Legal'; }

	fullTrail = trailLev1 + arrow + trailLev2;
}


// **** 2 levels = home + section + subsection ****
if (numLevels == 2)
{
	pagePart1 = getItem(1,pageURLpart,"_");

	if (pagePart1 == "aboutus")
	{
		trailLev2 = '<a href="aboutus.shtml" class="crumbLink">About Us<\/a>';

		pagePart2 = getItem(2,pageURLpart,"_");
		if (pagePart2 == "affiliations")		{ trailLev3 = 'Company Affiliations'; }
		if (pagePart2 == "mgmt")			{ trailLev3 = 'Management Team'; }
		if (pagePart2 == "licenses")			{ trailLev3 = 'Licenses &amp; Certifications'; }
	}


	if (pagePart1 == "services")
	{
		trailLev2 = '<a href="services.shtml" class="crumbLink">Services<\/a>';

		pagePart2 = getItem(2,pageURLpart,"_");
		if (pagePart2 == "environment")		{ trailLev3 = 'Environmental Services'; }
		if (pagePart2 == "geotech")			{ trailLev3 = 'Geotechnical Services'; }
	}


	if (pagePart1 == "portfolio")
	{
		trailLev2 = '<a href="portfolio.shtml" class="crumbLink">Portfolio<\/a>';

		pagePart2 = getItem(2,pageURLpart,"_");
		if (pagePart2 == "clients")		{ trailLev3 = 'Client List'; }
		if (pagePart2 == "projects")		{ trailLev3 = 'Project Gallery'; }

		if (pagePart2 == "vnewark")	{ trailLev3 = 'Case Study'; }
		if (pagePart2 == "hamiltonmkt")	{ trailLev3 = 'Case Study'; }
		if (pagePart2 == "allentown")	{ trailLev3 = 'Case Study'; }
		if (pagePart2 == "sgbronx")	{ trailLev3 = 'Case Study'; }
		if (pagePart2 == "njdep")	{ trailLev3 = 'Case Study'; }
		if (pagePart2 == "costco")	{ trailLev3 = 'Case Study'; }
		if (pagePart2 == "arbys")	{ trailLev3 = 'Case Study'; }
		if (pagePart2 == "lafarge")	{ trailLev3 = 'Case Study'; }
		if (pagePart2 == "sgphily")	{ trailLev3 = 'Case Study'; }
		if (pagePart2 == "mcdonalds")	{ trailLev3 = 'Case Study'; }
	}


	// news, employment, sitemap and sitemap only have 1 level, they don't come into play
	fullTrail = trailLev1 + arrow + trailLev2 + arrow + trailLev3;
}


// breadcrumb trail is built, now write it out

document.write('<span class="crumbBlock">' + fullTrail + '</span>');
