//Declare Variables

var path = "http://galesupport.com/primarysources";
var href = document.location.href;  //grabs URL
var ttl = document.title;  //grabs title

rExp = / . | ~ | \* /g;
ttl = ttl.replace(rExp," - ")

var hSplit = href.split("/");   //splices URL
var tSplit = ttl.split(" - ");  //splices Title
var tLength = tSplit.length

/*	Doug's reference room does not follow the appropriate directory convension of
*	/YYYYMM/ and instead breaks the directories apart like /YYYY/MM/.  To fix the
*	breadcrumb problem we pop the extra directory off the end of the hSplit which
*	is the path array. But only for the "Doug's Student Reference Room" crumb.
*/
//for(n=0; n<tLength; n++){ if(tSplit[n] == "Doug's Student Reference Room"){ hSplit.pop(); } }

//For Reference Reviews breadcrumb
if (tSplit[1]=="Reference Reviews" && hSplit[3] == "reference" && (hSplit[4] == "peter" || hSplit[4] == "lawrence" || hSplit[4] == "doug" || hSplit[4] == "wendy"))
{
	hSplit.pop();
}

if(tSplit[tLength-1]=="Home") {
	//creates linked bread crumbs
	for (var i=3;i<(hSplit.length-1);i++) {
		path+="<a href=\""+href.substring(0,href.indexOf(hSplit[i-1])+hSplit[i-1].length)+"/\">"+tSplit[i-3]+"</a>  :  ";
	}
	
	//creates current unlinked current page
	if(tSplit[i-2]=="Home") {
		i=hSplit.length-3;
		path+=tSplit[i-1];
	}
}
else {
	for (var i=2;i<(hSplit.length-1);i++) {
		path+="<a href=\""+href.substring(0,href.indexOf(hSplit[i])+hSplit[i].length)+"/\">"+tSplit[i-2]+"</a>  :  ";
	}

	//creates current unlinked current page
	i=hSplit.length-1;
	path+=  tSplit[i-2] ;
}
		  
//find out if we want to display a custom breadcrumb trail

//var cSplit = href.split("?");

//var cSplit2 = cSplit[1].split("=");
//var cFrom = cSplit[0]
//if (cFrom == "from") {
//		customPath = 1
//		frompage = csplit2[1];
//}

//if (customPath == 1) {
		//path="<a href = '/'>Gale : <a href='/public_librarians/'>Public Librarians</a>  :  Page Name Here";
//}

//Ready for Display

//creates custom breadcrumbs for dynamically generated pages

if(hSplit[3]=="servlet" && tSplit[1]=="Free Resources") {
		var url="<a href='/'>Gale</a> : <a href='/free_resources/'>Free Resources</a> : <a href='/reference/'>Reference Reviews</a> : Archive";
} else if(hSplit[3]=="servlet" && tSplit[1]=="Catalog"){
		var url="<a href='http://www.galeschools.com'>Gale Schools</a> : <a href='/servlet/SearchPageServlet?region=9&imprint=k12'>Catalog</a>";
} else {
		var url = path;
}
// End 
