//<![CDATA[
var lodgingicon = new GIcon();
lodgingicon.image = "http://stage.utah.com/art/maps/red-marker.png";
lodgingicon.shadow = "http://stage.utah.com/art/maps/marker-background.png";
lodgingicon.iconSize = new GSize(20, 20);
lodgingicon.shadowSize = new GSize(20, 20);
lodgingicon.iconAnchor = new GPoint(9, 19);
lodgingicon.infoWindowAnchor = new GPoint(9, 10);
	
function load(clat, clong, zlevel) {
  if (GBrowserIsCompatible()) {				
var map = new GMap2(document.getElementById("gmap"));
map.addControl(new GSmallMapControl());
var geocoder = new GClientGeocoder();
map.setCenter(new GLatLng(clat, clong), zlevel);
var boundaryPoints = map.getBounds();

// Add event listener for movend or dragend or both. When the user quits moving the map, then make the ajax call to get
// properties within the bounds of the map
GEvent.addListener(map, "zoomend", function(){ boundaryPoints = map.getBounds(); getDevelopments(boundaryPoints); });
GEvent.addListener(map, "dragend", function(){ boundaryPoints = map.getBounds(); getDevelopments(boundaryPoints); });


// Creates a marker at the given point with the given number label
function createMarker(point, name, html) {
  var marker = new GMarker(point, { icon: lodgingicon, title: name });
  GEvent.addListener(marker, "mouseover", function() {
    marker.openInfoWindowHtml( html	);
  });
  return marker;
}				

function addMarker(id, name, startAtPrice, endAtPrice, latitude, longitude) {
  var html = '<span style="font: 14px arial"><b>' + name + '</b><br /><br />New Homes: ' + (startAtPrice!=0||endAtPrice!=0?'$'+(startAtPrice!='0'?startAtPrice:'') + (endAtPrice!='0'?(startAtPrice!='0'?'-':'')+endAtPrice:''):'TBD') + '<br /><br><a href="/display_builder_development.php?developmentId='+id+'">More information...</a>';
  html += '<br /></span>';
  if(latitude && longitude){ 
  	point = new GLatLng(latitude, longitude);
	if(point != null){
		map.addOverlay(createMarker(point, name, html));
	}
  } 
}

// get lodging addresses to mark
function getDevelopments(bounds){	
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var respText, respCode, timestamp, cdate;
	var ucdate = new Date();
	var timestamp = ucdate.getSeconds();
	var downloadUrl = '/getAreaDevelopmentList.php?nec='+northEast+'&swc='+southWest+'&time=' + timestamp;
	GDownloadUrl(downloadUrl, function(respText, respCode){ 
		//document.writeln('Response Code: ' + respCode + ' Response: ' + respText); 
		if(respCode = '200'){
			var data = respText.split("\n");
			query = data.shift();
			ids = data[0].replace(/^\s+|\s+$/g,"").split(';');
			names = data[1].replace(/^\s+|\s+$/g,"").split(';');
			startAtPrices = data[2].replace(/^\s+|\s+$/g,"").split(';');
			endAtPrices = data[3].replace(/^\s+|\s+$/g,"").split(';');
			latitudes = data[4].replace(/^\s+|\s+$/g,"").split(';');
			longitudes = data[5].replace(/^\s+|\s+$/g,"").split(';');
			// Add address layers to the map.
			if(ids){map.clearOverlays();for(var x = 0; x < ids.length; x++){addMarker(ids[x], names[x], startAtPrices[x], endAtPrices[x], latitudes[x], longitudes[x]);}}
		}})
}

getDevelopments(boundaryPoints);



  }
}
//]]>