function addNormalClass() { 
this.className = 'normal'; 
} 

function highlightTarget() { 
// Collect the relevant items: 
var anchors = document.getElementsByTagName('a'); 
// Loop through them: 
for (var j=0;j<anchors.length;j++) { 
if (anchors[j].className == 'hilite') { 
// If one of them has a class name of 'highlighted,' change it to 'normal': 
anchors[j].className = 'normal'; 
} 
} 

// What is the url of the clicked link? 
var url = this.href; 
// Get everything after the '#' in the link--that's our id 
var elementId = url.substring(url.lastIndexOf('#') + 1); 
// Get the element: 
var currentTarget = document.getElementById(elementId); 
// Change its classname: 
currentTarget.className = 'hilite'; 
} 

function buildContentsArray() { 
// First collect all the links to contents and the contents they link to: 
var contentsLinks = document.getElementById('links').getElementsByTagName('a'); 
var anchors = document.getElementById('bookmarks').getElementsByTagName('a'); 

// Loop through the links: 
for (var i=0;i<contentsLinks.length;i++) { 
// Call a function when the links are clicked AND when a highlighted article is clicked: 
contentsLinks[i].onclick = highlightTarget; 
anchors[i].onclick = addNormalClass; 
} 
} 

window.onload = buildContentsArray; 


