// JavaScript Document

//this script uses side nav data for the current section from sidenav_data_xxx.js. 
//it also uses the variable currentPage which is also used by the sidenav script and exists in the head of every page.


//find this page in the sidenav data array for this section and extract its path
//the array sideNavData[] exists in sidenav_data_xxx.js
for(idx=0; idx < sideNavData.length; idx=idx + 3){
	if(sideNavData[idx] == currentPage){
		currentNavPath = sideNavData[idx + 2];
		break;
	}
}

//now parse the navigation path for this page
crumbPages = currentNavPath.split("/");

//add the current page to the end of that path
crumbPages[crumbPages.length] = currentPage;

//now build the crumb trail array
//even entries are page names, odd entries links to those pages

//all pages have home in the path so its the first entry
crumbPath = new Array("Home","/");

//second entry in the path is the section title - sideNavTitle is in sidenav_data.js
//note: section titles don't currently have pages associated with them
crumbPath[2] = sideNavTitle;
crumbPath[3] = "#"; //using # as a default but this entry will not be used by crumbtrail

//now get the links for the rest of the crumb trail pages
crumbPathIndex = 4;
for(idx=0; idx < crumbPages.length; idx++){
	crumbPath[crumbPathIndex] = crumbPages[idx];
	for(idx2=0; idx2 < sideNavData.length; idx2=idx2 + 3){
		if(sideNavData[idx2] == crumbPages[idx]){
			crumbPath[crumbPathIndex + 1] = sideNavData[idx2 + 1];
			crumbPathIndex = crumbPathIndex + 2;
			break;
		}
	}
}

//now build tag for crumb trail
var crumbTag = "";
for(idx=0; idx < crumbPath.length - 2; idx=idx + 2){
	if(idx == (crumbPath.length - 4)){
		if(idx == 2){
			crumbTag += crumbPath[idx];
		} else {
			crumbTag += "<a href=\"" +  crumbPath[idx + 1] +"\" class=\"crumbTrailLink\">" +  crumbPath[idx] +"</a>";
		}
	} else {
		if(idx == 2){
			crumbTag += crumbPath[idx] +"&nbsp;&nbsp;>&nbsp;&nbsp;";
		} else {
			crumbTag += "<a href=\"" +  crumbPath[idx + 1] +"\" class=\"crumbTrailLink\">" +  crumbPath[idx] +"</a>&nbsp;&nbsp;>&nbsp;&nbsp;";
		}
	}
}



