var objGoogle =
{
	objMap: null,
	aCommunities: null,
	objSWF: null,

	Load: function()
	{
		if (!GBrowserIsCompatible()) return false;

		var ndMain = document.getElementById('mainImage');

		objGoogle.objMap = new GMap2(document.getElementById('map'));
		objGoogle.objMap.setCenter(new GLatLng(40, -83), 10);
		objGoogle.objMap.addControl(new GSmallMapControl());

		RemoteScript('/remote/map.community.php', ({'ResponseFunction' : objGoogle.Response_AddPointData, 'Method' : 'GET'}));

		var ndLink, aLinks = document.getElementById('mapnavigation').getElementsByTagName('a');
		for (var nIndex = 0; aLinks[nIndex]; ++nIndex)
		{
			ndLink = aLinks[nIndex];
			ndLink.onmouseover = objGoogle.Zoom;
		}

	   objGoogle.objSWF = new SWFObject('communities.swf', 'ourcommunities', '800', '466', '8', '#ffffff');
	   objGoogle.objSWF.write('mainImage');

		ndMain.style.visibility = 'visible';

		return true;
	},

	Zoom: function(e)
	{
		e = e || window.event;
		var ndLink = e.target || e.srcElement;

		var nID = ndLink.id.split('-')[1];
		for (var nIndex = 0; objGoogle.aCommunities[nIndex]; ++nIndex)
		{
			var objCommunity = objGoogle.aCommunities[nIndex];
			if (objCommunity.id == nID)
			{
				objGoogle.objMap.panTo(new GLatLng(objCommunity.nLatitude, objCommunity.nLongitude));
				break;
			}
		}

		return true;
	},

	Response_AddPointData: function(sResponse)
	{
		if (sResponse === false) return false;

		objGoogle.aCommunities = eval(sResponse);
		for (var nIndex = 0; objGoogle.aCommunities[nIndex]; ++nIndex)
		{
			var objCommunity = objGoogle.aCommunities[nIndex];

			var objPoint = new GLatLng(objCommunity.nLatitude, objCommunity.nLongitude);
			var objMarker = new GMarker(objPoint);
			objGoogle.objMap.addOverlay(objMarker);

			var sHTML = '<div class="img-holder"><img src="' + objCommunity.sThumbnailImage + '" width="60" height="60" /></div><div class="community-name">' + objCommunity.sName + '</div><div class="community-location">' + objCommunity.sCity + ', ' + objCommunity.sState + '</div>';
			if (objCommunity.bApartments || objCommunity.bCondos || objCommunity.bHouses)
			{
				sHTML += '<div class="models-container">';
				if (objCommunity.bApartments) sHTML += '<div class="community-models"><strong class="bold">Apartments</strong> starting at $' + objCommunity.nPriceApartment + '/mo</div>';
				sHTML += '<div class="community-models"><strong class="bold">Condos</strong> starting at $' + objCommunity.nPriceCondo + '</div>';
				sHTML += '<div class="community-models"><strong class="bold">Houses</strong> starting at $' + objCommunity.nPriceHouse + '</div>';
				sHTML += '</div>';
			}

			// GEvent.addListener(objMarker, 'click', function() { objMarker.openInfoWindowHtml('Testing 123'); });
		}
		return true;
	}
};

window.onload = objGoogle.Load;