function number_format(a, b, c, d) {
	 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
	 var e = a + '';
	 var f = e.split('.');
	 var i;
	 var j;
	 var h;

	 if (!f[0]) {
	  f[0] = '0';
	 }
	 if (!f[1]) {
	  f[1] = '';
	 }
	 if (f[1].length < b) {
	 	g = f[1];
			for (i=f[1].length + 1; i <= b; i++) {
		    	g += '0';
	  		}
		f[1] = g;
	}
 	if(d != '' && f[0].length > 3) {
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j+=3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = d + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	c = (b <= 0) ? '' : c;
return f[0] + c + f[1];
}


function start_timer(t)  {
	setTimeout('appear_listing()', t);
}
	
function fade_listing()  {
	Effect.Fade('listing_container');
	appear_listing();
}


function appear_listing()  {
	var idx = parseInt(document.getElementById('index').value);

	if (idx >= l.length)  {
		idx = 0;
	}

	document.getElementById('index').value = idx+1;
	document.getElementById('listing_price').innerHTML = number_format(l[idx]['ListPrice'], 0, '.', ',');
	document.getElementById('bedroom').innerHTML = l[idx]['BdrmQT'];
	document.getElementById('bathrooms').innerHTML = l[idx]['BthQt'];
	document.getElementById('halfbath').innerHTML = l[idx]['BATH12'];
	document.getElementById('address').innerHTML = l[idx]['HSN'] +' '+ l[idx]['AddrSt'];
	document.getElementById('city').innerHTML = l[idx]['CitySV'] +', '+ l[idx]['ZipCode'];
	document.getElementById('mlsnum').innerHTML = l[idx]['LN'];
	document.getElementById('description').innerHTML = l[idx]['RM1'].substring(0, 150) +'...';
	document.getElementById('mlsImg').src = 'http://208.180.191.57/mlsphotos/'+ l[idx]['LN'] +'.jpg';

	document.getElementById('feature_learn_more').href = 'listings.htm?action=details&Type=MLS_Residential&LN='+ l[idx]['LN'];
	

	Effect.Appear('listing_container');
	setTimeout('fade_listing()', 7500);
}