 if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  var imgindex = 0;
  var listingArray = new Array(); 
  xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4){
			//alert("success");
			var listings=JSON.parse(xmlhttp.responseText);
			for(var i = 0; i < listings.listings.length; i++){
				listingArray.push("<div style='padding:6px;font-family:Arial,Helvetica,sans-serif;font-size:12px;overflow:hidden; line-height:20px;'><a href = '"+listings.listings[i].link+"'><img src = '"+listings.listings[i].pic+"' width='198px'></a><br><b>City:</b>"+listings.listings[i].city+"<br>"+listings.listings[i].bed+" <b>bed/</b>"+listings.listings[i].bath+"<b>bath</b><br><b>Price:</b> $"+listings.listings[i].price+"<br><div width='198px'>"+listings.listings[i].desc+"<a href='"+listings.listings[i].link+"'>[more]</a></div></div>");
				//alert("<img src = '"+listings.listings[i].pic+"'>");
			}
			imgindex = Math.floor(Math.random()*listings.listings.length);
			//alert(imgindex);
			document.getElementById("featuredListingDiv").innerHTML = listingArray[imgindex];
		}
  }
  xmlhttp.open("GET","featuredlisting.php",true);
  xmlhttp.send();
  
function featuredListingPrev(){
	imgindex--;
	if(imgindex<0) imgindex = listingArray.length-1
	document.getElementById("featuredListingDiv").innerHTML = listingArray[imgindex];
}
function featuredListingNext(){
	imgindex++;
	if(imgindex>listingArray.length-1) imgindex = 0
	document.getElementById("featuredListingDiv").innerHTML = listingArray[imgindex];
}
