	//how many ad spots are there?
	adSpots=inUse.length;

	// preload images
	preLoad=new Array();
	for (i=0;i<adArray.length;i++){
		preLoad[i]=new Image();
		preLoad[i].src=adArray[i].image;
	}

	//count number of duplicate ads
	function countDups(){
		valuesChecked=new Array();
		dupCount=0;
		for(i=0;i<inUse.length;i++){//loop through used values
			//loop to see if we've searched for 'i' value
			alreadyChecked=0;
			for(c=0;c<valuesChecked.length;c++){
				if(valuesChecked[c]==inUse[i])alreadyChecked=1;
			}
			valuesChecked.push(inUse[i]);
			//if we haven't already checked value for dups, do so
			if(!alreadyChecked){
				for(j=0;j<inUse.length;j++){
					if(inUse[j]==inUse[i] && j!=i){
						dupCount++;
					}
				}
			}
		}
		return dupCount;
	}

	//generate random numbers
	function getRand(){
		var rNum=100;//set rand # to high # so while loop will run initially
		maxDup=inUse.length-adArray.length;//how many duplicate ads should be allowed
		if(maxDup==0)maxDup=1;
		else if(maxDup<0)maxDup=0;
		else if(maxDup>0)maxDup++;
		tryNew=0;//flag to determine if we need to try a different rnd number
		while(rNum>adArray.length-1 || tryNew){//create rnd# (0-47) and see if it's a duplicate
			rNum=Math.floor(Math.random()*48);
			tryNew=0;
			for(i=0;i<inUse.length;i++){
				if(inUse[i]==rNum && countDups()>=maxDup){
					tryNew=1;
					break;
				}
			}
		}
		return rNum;
	}

	//functions to start rotating ads
	//check duplicates, make sure 'whichSpot' gets reset with global max val
	function changeAd(whichSpot){
		if(document.getElementById){
			elementId='ad'+whichSpot;
			linkVar='adLink'+whichSpot;
			inUseIndex=whichSpot-1;
			if(document.getElementById(elementId)){
				adIndex=getRand();
				document.getElementById(elementId).src=adArray[adIndex].image;
				eval(linkVar+"=adArray["+adIndex+"].link");
				inUse[inUseIndex]=adIndex;
			}
			nextNum=whichSpot+1;
			if(nextNum>adSpots)nextNum=1;
		}
		setTimeout("changeAd(nextNum)",3000);
	}
	setTimeout("changeAd(1)",3000);