/*
dg-Breadcrumbs v1.0
by David Gaeddert, Flint Hills Design (www.flinthillsdesign.com)
July 13, 2010

Copyright 2010, David Gaeddert

This script creates a series of location breadcrumb links (eg. Home > Folder > Page)
based on the location of the current page, using jQuery. It breaks down the web address and recompiles
the breadcrumbs based on the folders containing the current page.

In order for this script to function make sure
both jQuery and this script are included within the <head> tag of any page using it.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script src="/PATH/TO/SCRIPT/dg-breadcrumbs.js" type="text/javascript"></script>

Place <div id="breadcrumbs"></div> within the <body> where you want the breadcrumbs displayed.
You can then style the breadcrumbs using #breadcrumbs {} in your styles.

Please read the comments in the code in order to customize the script to your needs.
*/

var jQueryBread = jQuery.noConflict();
jQueryBread(document).ready(function(){
	//User options
	var homeName = 'Home'; //Displayed as the first breadcrumb link, back to the site root
	var divider = ' &gt; '; //Displayed between each breadcrumb
	//----
	
	var linkStart = '<a href="' + window.location.protocol + "//" + window.location.host + "/";
	var homepage = '<a href="' + window.location.protocol + "//" + window.location.host + '">' + homeName + '</a>';
	jQueryBread("#breadcrumbs").html(homepage);
	var linkpath = window.location.pathname.split("/");
	if (linkpath.slice(linkpath.length-1,linkpath.length)==''){linkpath.pop();}
	
	// The following removes the current page from the breadcrumb links if it is an index.php or index.html
	// this way it will show the directory that the index is in as the last breadcrumb
	// COMMENT THIS NEXT LINE OUT IF the "for(var i=1; i<linkpath.length; i++)" statement is changed to "i<linkpath.length-1;"
	if (linkpath.slice(linkpath.length-1,linkpath.length)=='index.php' | 'index.html'){linkpath.pop();}

	//If you don't want to show current page in the breadcrumbs, comment out the line ^^above^^ and
	// change "i<linkpath.length;" to "i<linkpath.length-1"
	for(var i=1; i<linkpath.length; i++) {
				var pageName = linkpath[i];
				var recompiledString = linkpath.slice(1,[i+1]).toString().replace(/,/g,"/");
				
				// If you want to replace what is displayed for certain folder or page names
				// then put the original name (pageName == 'HERE')
				// and put what you want displayed { pageName = 'HERE' }
				//   These lines can be duplicated if necessary
				if (pageName == 'Cutaway'){ pageName = 'Parcel Van'; }
				if (pageName == 'DryFreight'){ pageName = 'Dry Freight'; }	
				if (pageName == 'Plumbers'){ pageName = 'Plumber'; }
				if (pageName == 'Van'){ pageName = 'Truck Bodies'; }
				if (pageName == 'Trailer'){ pageName = 'Trailers'; }	
				if (pageName == 'SlidingBow'){ pageName = 'Sliding Bow'; }
				if (pageName == 'Mover'){ pageName = 'Moving Vans'; }
				if (pageName == 'Lawn'){ pageName = 'Lawn Maintenance'; }
				if (pageName == 'Platform'){ pageName = 'Flatbed / Stake'; }
				if (pageName == 'Reefer'){ pageName = 'Refrigerated Truck Bodies'; }
				
				pageName = pageName.replace(/(.php\b|.html\b)/gi,'');
				jQueryBread("#breadcrumbs").append(divider + linkStart + recompiledString + '">' + pageName + '</a>');
				
				//This capitalizes the first letter of the displayed pageName
				jQueryBread("#breadcrumbs a").attr('style','text-transform:capitalize;');
			}
});
