
var adverts = new Array();
adverts[0] = {img: "http://www.offsets2000.com/images/offmainimgs/offmainimgs_f01.jpg", url: "#"};
adverts[1] = {img: "http://www.offsets2000.com/images/offmainimgs/offmainimgs_f02.jpg", url: "#"};
adverts[2] = {img: "http://www.offsets2000.com/images/offmainimgs/offmainimgs_f03.jpg", url: "#"};
adverts[3] = {img: "http://www.offsets2000.com/images/offmainimgs/offmainimgs_f04.jpg", url: "#"};
adverts[4] = {img: "http://www.offsets2000.com/images/offmainimgs/offmainimgs_f05.jpg", url: "#"};

// number of adverts to show on the page
var numAds = 4;

// id prefix for <img> and <a> tags
var img_prefix = "adImg";
var a_prefix = "adLink";

// this will be used to stop us showing the same ad more than once on the same page
var chosenAds = new Array();

// ------------------------------------------------
// choose which ads to show
function chooseAds()
{
	for(var i = 1; i <= numAds; i++)
	{
		var randNum = -1;
		while(randNum == -1 || alreadyPicked(randNum)) randNum = Math.floor ((Math.random() * adverts.length));
		
		var img = document.getElementById(img_prefix + i);
		if(! img) continue;
		var a = document.getElementById(a_prefix + i);
		if(! a) continue;

		chosenAds.push(randNum);
		
		img.src = adverts[randNum].img;
		a.href = adverts[randNum].url;
	}
}


// ------------------------------------------------
// has this advert already been picked to show?
function alreadyPicked(num)
{
	for(var i in chosenAds) if(num == chosenAds[i]) return true;
	
	return false;
}
