Ok... Here's the jist of what you'd want to do.
In your HTML, you'd have your link and image:
Code:
...
<a href="url.lnk" id="imageLink"><img src="image.type" alt="blah" id="imagePath" /></a>
...
These would have default values, just incase JavaScript doesn't load.
Next, you can do this JavaScript where ever, just make sure you do it after the DOM has loaded (eg: window.onload). So you'd have function, and an array of image paths and links. To make it easier on myself, I'll do two arrays just because I'm not positive if 2-dimensional arrays work like they do in PHP.
Code:
var imagePaths = new Array();
imagePaths[0] = 'images/0.jpg';
imagePaths[1] = 'images/1.jpg';
imagePaths[2] = 'images/2.jpg';
var imageLinks = new Array();
imageLinks[0] = 'http://site1.url/';
imageLinks[1] = 'http://site2.url/';
imageLinks[2] = 'http://site3.url/';
function rndImage() {
var randomNum = (Math.round(Math.random()*2));
document.getElementById('imagePath').src = imagePaths[randomNum];
document.getElementById('imageLink').src = imageLinks[randomNum];
}
window.onload = rndImage;
This should work, though I haven't tested it.