// -------------------------------------------------------------
// Function that is called on the ONLOAD.
// -------------------------------------------------------------
function InitNavigation(){

	// Left Section Navigation
	ShowNavLocationIndicator("nav_horizontal","active","first","last");
	// Top Primary Navigation
	ShowNavLocationIndicator("nav_vertical","active","first","last");
}




// -------------------------------------------------------------
// Function that loops through a LIST object and assigns a class
// to an element showing your Location on the site.
// -------------------------------------------------------------
function ShowNavLocationIndicator(div_id,active_class,first_class,last_class,ul_obj,inRecursion){

	// Misc Variables
	_recur  = new Array();
	ul  	= null;
	str     = "";
	nodePos = 0;
	_browserVarient = (document.all)?1:2;

	// Get nav DIV & then UL/OL
	if(div_id){
		div = document.getElementById(div_id);
		if(!div){ return; }

		if(div.nodeName.toLowerCase()=="div"){
			// Get the UL/OL
			for(n=0;n<div.childNodes.length;n++){
				if(div.childNodes[n].nodeType==1 && (div.childNodes[n].nodeName.toLowerCase()=="ul" || div.childNodes[n].nodeName.toLowerCase()=="ol")){ ul = div.childNodes[n]; break; }
			}
		}else{
			ul = div;
		}
	} else if(ul_obj){
		ul = ul_obj;
	}

	// Can't find nav specified
	if(!ul){ return; }
	

	// Lets loop through the UL/OL element and it's children.
	for(x=0;x<ul.childNodes.length;x++){
		// There is nothing in this child, move on.
		if(!ul.childNodes[x].innerHTML){ continue; }

		// Special cases for the FIRST and LAST elements that get
		// an extra class assigned.
		_extraClass = "";
		if(nodePos==0 && first_class){ _extraClass=" "+first_class; }
		if(x>=ul.childNodes.length-_browserVarient && last_class){ _extraClass=last_class; }

		// Check for invalid items
		if(!ul.childNodes[x]){ continue; }
		if(!ul.childNodes[x].firstChild){ continue; }

		// Grab the HREF of the element and compare it to the URL you
		// are currently residing on. If a match, assign the ACTIVE CLASS!
		nodeHref = ul.childNodes[x].firstChild;
		if(nodeHref.nodeType==3){ 
			// find the LI
			for(tmp=0;tmp<ul.childNodes[x].childNodes.length;tmp++){
				if(ul.childNodes[x].childNodes[tmp].attributes){
					nodeHref = ul.childNodes[x].childNodes[tmp]; 
					break;
				}
			}
		}
		if(!nodeHref.attributes){ continue; }
		if(!nodeHref.attributes.href){ continue; }
		if(!nodeHref.attributes.href.value){ continue; }
		
		itemHref = nodeHref.attributes.href.value;
		browHref = location.href;

		// Trim off HTML page
		hrArray  = itemHref.split("/");
		trash    = hrArray.pop();
		itemHref = hrArray.join("/");
		// Trim off HTML page
		hrArray  = browHref.split("/");
		trash    = hrArray.pop();
		browHref = hrArray.join("/");


		if(browHref.toLowerCase().indexOf(itemHref.toLowerCase())>-1){ ul.childNodes[x].className=((_extraClass)?_extraClass+" ":"")+active_class; }
		else if(_extraClass){
			ul.childNodes[x].className=_extraClass;
		}
		
		// Next node!
		nodePos++;

		// Recurse through othere
		if(ul.childNodes[x]){
			newUL = ul.childNodes[x];
			for(y=0;y<newUL.childNodes.length;y++){
				if(newUL.childNodes[y]){ 
					if(newUL.childNodes[y].nodeName.toLowerCase()=="ul" || newUL.childNodes[y].nodeName.toLowerCase()=="ol"){
						_recur.push(newUL.childNodes[y]);
						//ShowNavLocationIndicator(null,active_class,first_class,last_class,newUL.childNodes[y]);
					}
				}
			}
		}
	}
	
	if(!inRecursion){
		recursive_ShowNavLocationIndicator(null,active_class,first_class,last_class,_recur);
	}
}

function recursive_ShowNavLocationIndicator(div_id,active_class,first_class,last_class,_recurArray){
	for(r=0;r<_recurArray.length;r++){
		ShowNavLocationIndicator(div_id,active_class,first_class,last_class,_recurArray[r],true);
	}
}

// -------------------------------------------------------------
// Function that allows us to add to the ONLOAD event of an 
// HTML page, even if there is already an ONLOAD assigned
// -------------------------------------------------------------
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}


// -------------------------------------------------------------
// Add to the ONLOAD feature of any page this JS is included on
// -------------------------------------------------------------
addEvent(window, 'load', InitNavigation);
