I updated my post. Now it says "link is not defined" "thisLink[link].scopeObject = new Image();" It's important that the link remains though because it is a property of linkObj that holds the current link. I use the [] as a property rather than dot notation due to the looping ability it provides.
<script type="text/javascript">
window.onload = init;
var linkObj = new Object();
var listItems = new Object();
function init() {
for(var i=0; i < document.links.length; i++) {
var link = document.links[i];
linkObj[link] = link;
setupClick(linkObj);
}
}
function setupClick(thisLink) {
thisLink[link].scopeObject = new Image();
thisLink[link].scopeObject.src = thisLink[link].id + "Img.png";
thisLink[link].onclick = rollClick;
}
function rollClick() {
var list = document.getElementById("target").childNodes;
for(var i=0; i < list.length; i++) {
if(list[i].nodeName == "LI") {
var id = list[i] + i;
listItems[id] = id;
}
}
for(id in listItems){
if(listItems[id].indexOf(this[link].id) > -1) {
listItem[id].style.backgroundImage = this[link].scopeObject.src;
}
}
}
</script>
<ul id="target">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<div id="mainContent">
<div id="navLinks">
<ul>
<li><a href="#" id="0">Home</a></li>
<li><a href="#" id="1">About</a></li>
<li><a href="#" id="2">Products</a></li>
<li><a href="#" id="3">Contact</a></li>
</ul>