/**
 * @author davereid
 * 
 * 
 */


function set_navigation(map)
{
	if (map.tab != '') {
		var img = document.getElementById(map.tab + '_img');
		if (img != null) {
		
			var current_image = img.src;
			var selected_image = current_image.replace("_off.gif", "_on.gif");
			img.src = selected_image;
			img.className = "active";
		}
		var ahref_nav = document.getElementById(map.tab);
		
		if (ahref_nav != null) {
			ahref_nav.className = "active";
		}
	}
	if (map.subtab !== '') {
		var ahref = document.getElementById(map.subtab);
		
		if (ahref != null) {
			ahref.className = "active";
		}
	}
	if (map.footer !== '') {
		var ahref = document.getElementById(map.footer);
		
		if (ahref != null) {
			ahref.className = "active";
		}
	}	
	if(map.breadcrumb !='')
	{
		var bc = document.getElementById('breadcrumb');
		bc.innerHTML = map.breadcrumb;
	}
}




function generate_navigation(url)
{

	if (url =='')
	{
		return;
	}
	
	var found = false;
	for (i=0;i<aM.length;i++)
	{
		if(aM[i].key == url || aM[i].key == url + '/')
		{
			found = true;
			break;
		}
	}
	if (found)
	{
		set_navigation(aM[i]);
		return;
	}
	else{
		var tmp = url.split('/');	
		var outA = tmp.slice(0, tmp.length-1);
		var out = outA.join('/');
		
		generate_navigation(out)
	}
}


function init_navigation(){
	
		


	var rootpath = "/";
	
	var ucfirst = 1; // if set to 1, makes "directory" default to "Directory"
			
	// Grab the page's url and break it up into directory pieces
	
	var pageurl = (new String(document.location));
	var protocol = pageurl.substring(0, pageurl.indexOf("//") + 2);
	pageurl = pageurl.replace(protocol, ""); // remove protocol from pageurl
	var rooturl = pageurl.substring(0, pageurl.indexOf(rootpath) + rootpath.length); // find rooturl
	if (rooturl.charAt(rooturl.length - 1) == "/") //remove trailing slash
	{
		rooturl = rooturl.substring(0, rooturl.length - 1);
	}
	pageurl = pageurl.replace(rooturl, ""); // remove rooturl fro pageurl
	if (pageurl.charAt(0) == '/') // remove beginning slash
	{
		pageurl = pageurl.substring(1, pageurl.length);
	}
	
//	var page_ar = pageurl.split(sectionsep);
	//var currenturl = protocol + rooturl;
	//var allbread = precrumb + "<a href=\"" + currenturl + "\">" + rootname + "</a>" + postcrumb; // start with root
	//var allbread = '';
	
	
	generate_navigation(pageurl);



}
