///////////////////////////////////////////////////////////////////////////////
// rentworx - Google specific ajax routines


var _gmap = null;
function mapIt(mapDivId, width, height, street, city, state, zip)
{
    document.getElementById(mapDivId).style.width = width + 'px';
   	document.getElementById(mapDivId).style.height = height + 'px';
	var address = street + ', ' + city + ', ' + state + ', ' + zip;

	_gmap = new google.maps.Map2(document.getElementById(mapDivId));

	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(address,
		function(point) {
			if (!point)
			{
				// just to the town
				var geocoder2 = new GClientGeocoder();
				var address2 = city + ', ' + state + ', ' + zip;
				geocoder2.getLatLng(address2,
					function(point) {
						if (!point)
						{
							alert('Could not find map for this address');
						}
						else
						{
							var balloonHtml = 'Unknown street' + '<br />' + city + ', ' + state + ', ' + zip;
							_gmap.setCenter(point, 14);
							var marker = new GMarker(point);
							_gmap.addOverlay(marker);
							marker.openInfoWindowHtml(balloonHtml);
						}
					}
				);
			}
			else
			{
				var balloonHtml = street + '<br />' + city + ', ' + state + ', ' + zip;
				_gmap.setCenter(point, 14);
				var marker = new GMarker(point);
				_gmap.addOverlay(marker);
				marker.openInfoWindowHtml(balloonHtml);

			}
		}
	);

	_gmap.addControl(new GMapTypeControl());
	_gmap.addControl(new GLargeMapControl());
	_gmap.addControl(new GScaleControl());
}

function displayMapWindow(windowId, mapWindowId, width, height, addr)
{
	var map_width = width - 20;
	var map_height = height - 45;

	var centerY = getScreenCenterY();
	var centerX = getScreenCenterX();
	var l = centerX - Math.round(width/2);
	var t = centerY - Math.round(height/2);

	hideFloatingDiv('fav_window', 'favWindowOff');
	displayFloatingDiv(windowId, 'winTitle', 'Rental Home Map', width, height, l, t, 'mapWindowOn');
	mapIt(mapWindowId,map_width, map_height, addr.street, addr.city, addr.state, addr.zip);
}

