
var linksNumber=3; /* This is the number of links to be shown and matches the HTML */

var myimages=[
'Images/ads_1.jpg','Images/ads_2.jpg',
'Images/ads_3.jpg','Images/ads_4.jpg',
'Images/ads_5.jpg','Images/ads_6.jpg',
'Images/ads_7.jpg','Images/ads_8.jpg',
'Images/ads_9.jpg','Images/ads_10.jpg'
];

var imagelinks=[
'page1.php','page2.php',
'page3.php','page4.php',
'page5.php','page6.php',
'page7.php','page8.php',
'page9.php','page10.php'
];

var c,n;

function randomImgdisplay() 
{
	var k=0;
	var ary0=[];
	var ary1=[];

	for(c=0;c<myimages.length;c++) 
	{
		ary0[c]=c; /* Pre-populate 'ary0' with numbers 0 to 11 */
	}

	while(ary0.length>0) 
	{

		n=Math.floor(Math.random()*ary0.length); /* Get a random 'ary0' index number */
		ary1[k]=ary0[n]; /* Add 'ary0' value to 'ary1' */
		k++;
		ary0.splice(n,1); /* Remove that element from the 'ary0'. The array gets shorter with each iteration */

	}

	for(c=0;c<linksNumber;c++)
	{
		document.getElementById('pic'+c).src=myimages[ary1[c]]; /* replace the image positions */
		document.getElementById('lnk'+c).href=imagelinks[ary1[c]]; /* replace the link positions */
	}

}

if(window.addEventListener)
{
	window.addEventListener('load',randomImgdisplay,false);
}
else 
{
	if(window.attachEvent)
	{
		window.attachEvent('onload',randomImgdisplay);
	}
}
var intervalId = window.setInterval(randomImgdisplay,5000);
