var refreshTime=5000;			//5000ms=5 secs
var numAds=0;
var current_ad=0;
var ads=new Array();
var myCode='';
		
function getTheListings(){
	jsrsExecute('select_rs.php', displayListings, 'getMLS', '');
}
function displayListings(stuff){
	stuff=stuff.substring(0, (stuff.length-1));
	var adArray=stuff.split('|');
	numAds=adArray.length;
	for (var i=1; i<=numAds; i++){
		ads[i]=new makeAd();
	}	
	i=1;
	for (var a=0; a<adArray.length; a++){
		var adInfo=adArray[a].split('~');	
		ads[i].width="294";		
		ads[i].height="179";
		ads[i].src="prop_images/"+adInfo[0]+"_0.jpg";
		ads[i].href="prop_view.php?id="+adInfo[0];
		ads[i].alt="Listing #"+adInfo[0];
		i++;		
	}
	do{
		var n=Math.floor(Math.random()*(numAds+1)+1);
	} while (n>numAds);
	current_ad=n;
	myCode=getCode(n);
	document.getElementById('bannerAd').innerHTML=myCode;
}
function makeAd(){
	this.width='';
	this.height='';
	this.src='';
	this.href='';
	this.alt='';
}
function getCode(adNumber){
	var tempCode='';
	tempCode+=('<a href="'+ads[adNumber].href+'">\n');
	tempCode+=('<img class="rotate" src="'+ads[adNumber].src+'" width='+ads[adNumber].width+' height='+ads[adNumber].height);
	if (numAds>1){
		tempCode+=(' onLoad="setTimeout(\'newAd();\','+refreshTime+');"');
	}
	tempCode+=(' alt="'+ads[adNumber].alt+'" title="'+ads[adNumber].alt+'">\n');
	/*tempCode+=('<?php if (is_file(\"'+ads[adNumber].src+'\"){?><img class="rotate" src="'+ads[adNumber].src+'" width='+ads[adNumber].width+' height='+ads[adNumber].height);
	if (numAds>1){
		tempCode+=(' onLoad="setTimeout(\'newAd();\','+refreshTime+');"');
	}
	tempCode+=(' alt="'+ads[adNumber].alt+'" title="'+ads[adNumber].alt+'"><?php}else{continue;}?>\n');*/
	tempCode+=('</a>');
	return tempCode;
}
function newAd(){	
	current_ad++;
	if (current_ad>numAds) 
		current_ad=1;	
	myCode=getCode(current_ad);
	document.getElementById('bannerAd').innerHTML=myCode;
}
