this is 1 way of doing it.
I generate a random starting pic for each window and then cycle the images for that window. the number of images in each window can vary.
as each new image appears, I assign the image’s link to the <a> tag for that image.
you could stream line the code a bit, but I have kept things simple by using separate functions for each window at this stage.
hopefully the comments in the code explain what I have done.
if you need more help, simply post back 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
img {border: none}
</style>
<script type="text/javascript">
//paths to the images
var imgPaths1 = ['pic1.jpg','pic2.jpg','pic3.jpg','pic4.jpg','pic5.jpg','pic6.jpg'];
var imgPaths2 = ['pic1.jpg','pic2.jpg','pic3.jpg'];
var imgPaths3 = ['pic1.jpg','pic2.jpg','pic3.jpg','pic4.jpg','pic5.jpg'];
//links for each image
var urls_1 = ['url1','url2','url3','url4','url5','url6'];
var urls_2 = ['url1','url2','url3'];
var urls_3 = ['url1','url2','url3','url4','url5'];
//preload the images for more fluent swapping later on
var imgO_1 = new Array();
var imgO_2 = new Array();
var imgO_3 = new Array();
for(var i=0; i < imgPaths1.length; i++) {
imgO_1[i] = new Image();
imgO_1[i].src = imgPaths1[i];
}
for(var i=0; i < imgPaths2.length; i++) {
imgO_2[i] = new Image();
imgO_2[i].src = imgPaths2[i];
}
for(var i=0; i < imgPaths3.length; i++) {
imgO_3[i] = new Image();
imgO_3[i].src = imgPaths3[i];
}
//generate a random pic index for each window
var index1 = Math.floor((Math.random()*imgPaths1.length));
var index2 = Math.floor((Math.random()*imgPaths2.length));
var index3 = Math.floor((Math.random()*imgPaths3.length));
//3 swap image functions
function swapImagesWin1() {
if(++index1 > imgPaths1.length-1) {
index1 = 0;
}
//assign the new image to this <img>
imgObj1.src = imgPaths1[index1];
//assign the link url for this <img>
imgObj1.parentNode.href = urls_1[index1];
setTimeout(swapImagesWin1,2000);
}
function swapImagesWin2() {
if(++index2 > imgPaths2.length-1) {
index2 = 0;
}
imgObj2.src = imgPaths2[index2];
imgObj2.parentNode.href = urls_2[index2];
setTimeout(swapImagesWin2,2000);
}
function swapImagesWin3() {
if(++index3 > imgPaths3.length-1) {
index3 = 0;
}
imgObj3.src = imgPaths3[index3];
imgObj3.parentNode.href = urls_3[index3];
setTimeout(swapImagesWin3,2000);
}
window.onload=function() {
imgObj1 = document.getElementById("imgBk1");
imgObj2 = document.getElementById("imgBk2");
imgObj3 = document.getElementById("imgBk3");
swapImagesWin1();
swapImagesWin2();
swapImagesWin3();
}
</script>
</head>
<body>
<div>
<a href="">
<img id="imgBk1" src="" alt="" />
</a>
</div>
<div>
<a href="">
<img id="imgBk2" src="" alt="" />
</a>
</div>
<div>
<a href="">
<img id="imgBk3" src="" alt="" />
</a>
</div>
</body>
</html>