var navElementName = 'sideNav';

/*
function hiliteMenu() {
	var navSection = document.getElementById(navElementName);
	
	var links = navSection.getElementsByTagName("a");

	var docLoc = document.location.href.toLowerCase();
	
	// strip hashes and query strings from the document location string
	//var locPattern = /([^#\?]+)[#\?].*$/;
	//var locResult = locPattern.exec(docLoc);
	//if(locResult != null) { docLoc = RegExp.$1; }
			
	var hotLink;
	
	for(var i=0; i < links.length; i++) {
	
	    if( docLoc.toLowerCase().indexOf(links[i].href.toLowerCase()) >= 0) {
	        hotLink = links[i];
			break;
		}
		
	}
	
	if(hotLink != null) {
	
		hotLink.className = "active";
		cascadeActiveState(hotLink);
		
	}
}
*/

function highlight() {

    loc = document.location.href;
    loc = loc.substring(loc.lastIndexOf('/') + 1);
    
    navSection = document.getElementById('sideNav');
    links = navSection.getElementsByTagName("a");
    
    //document.writeln(loc);
    
    for (i = 0; i < links.length; i++) {
    
        lnk = new String(links[i]);
        lnk = lnk.substring(lnk.lastIndexOf('/') + 1);

        //document.writeln(loc + '<br />' + lnk + '<br /><br />');
    
        if ( loc == lnk ) {
               
            links[i].className = 'active';
        
            if ( links[i].parentNode != null ) { 
        
                // Executing recursive method that will 'bubble-up' and activate any parent li and ul elements                           
                activate(links[i].parentNode); 
                
                // Activating UL child nodes of this node
                if ( links[i].parentNode.hasChildNodes() ) {                                
                
                    for ( j = 0; j < links[i].parentNode.childNodes.length; j++ ) {                    
                        if ( links[i].parentNode.childNodes[j].tagName == 'UL' ) { links[i].parentNode.childNodes[j].className = 'active'; }                    
                    }                
                    
                }                
                
            }
            
            return;
            
        }
                            
    }

}

function activate(node) {   

    if (node.tagName == 'LI') {
    
        node.className = 'active';
        
        if (node.parentNode != null) {
            activate(node.parentNode);
        }
    
    }
    
    else if (node.tagName == 'UL') {
    
        node.className = 'active';
        
        if (node.parentNode != null) {
            activate(node.parentNode);
        }
        
    }
    
    else {
        return;
    }                

}


if( window.addEventListener ) {
	window.addEventListener("load", highlight, false);
} 

else if( window.attachEvent ) {
	window.attachEvent("onload", highlight);
}             

/*
function cascadeActiveState(elem) {

	var parent = elem != null ? elem.parentNode : null;
	
	if(parent == null || parent.id == navElementName) {
		return;
    } 
	
	else if(parent.tagName == 'LI') {
	    parent.className = 'active';
	    cascadeActiveState(parent);	    		
	} 
	
	else if(parent.tagName == 'UL') {	    
	    cascadeActiveState(parent);
	} 
	
	else {
		return; // ok, not necessary, but makes the logic clearer
	}
	
	//alert(parent.tagName + " - " + parent.className + " - " + parent.id);
}

if(window.addEventListener) {
	window.addEventListener("load",hiliteMenu,false);
} 

else if( window.attachEvent ) {
	window.attachEvent("onload",hiliteMenu);
}
*/