// JavaScript Document

// create the list (rank-2 array) of filenames
// for the images and the corresponding href's
// for the containing anchors
// list can grow to whatever size is needed
var imgInfo = [
['http://www.hiddeninthesand.com/images/twitter_sidebarAd.gif', 'http://www.twitter.com/hiddeninthesand'],
['http://www.hiddeninthesand.com/images/toolbar_sidebarAd.gif', 'http://hits.forumtoolbar.com/']
];

function changeImg() {
// how many images available?
var last = imgInfo.length;
// randomly select an image index
var idx = Math.floor( last * Math.random());
// get the source for the image
var src = imgInfo[idx][0];
// get the href for the image's anchor
var href = imgInfo[idx][1];
var d = document;
// get a reference to the image element
var img = d.getElementById( 'chgImg');
// update the image's src attribute
img.src = src;
// get a reference to the anchor element
var link = d.getElementById( 'chgLink');
// update the anchor's href attribute
link.href = href;
}

// every time the page is loaded, change the image
window.onload = changeImg;
