
	var map;
	var geocoder; 
	var mapZoom;
	var mapType;
	var mapTypeS;
	var mapAddress;


 function load(lat, lng, address, type)
    {
		//alert('lat: ' + lat + '; lng: ' + lng + '; address: ' + address);
		mapAddress = address;
		mapTypeS = type;

		switch (mapTypeS)
		{
			case "office":
				mapZoom = 15;
				mapType = G_NORMAL_MAP;
				break;
			case "property":
				mapZoom = 10;
				mapType = G_HYBRID_MAP;
				break;
		}
		
		// Create new map object
		map = new GMap2(document.getElementById("map"));
		
		if (lng != 0 || lat != 0)
		{	
			setMapProperties(new GLatLng(lat, lng));	
		}
		else 
		{
			// Create new geocoding object
			geocoder = new GClientGeocoder();
			// Retrieve location information, pass it to addToMap()
			geocoder.getLocations(address, addToMap);
		}
    }

   function addToMap(response)
   {
      // Retrieve the object
	  if (response != null && response.Placemark != null && response.Placemark[0] != null)
	  {
		place = response.Placemark[0];
		
		// Retrieve the latitude and longitude
		setMapProperties(new GLatLng(place.Point.coordinates[1],
                          place.Point.coordinates[0]));
	  }
	  else
	  {
		document.getElementById("map").style.display = "none";
		document.getElementById("map_link").style.display = "none";
	  }
   }
   
   function setMapProperties(mapCenter)
   {
   		if (mapCenter != null)
		{
		    // Center the map on this point

			map.setCenter(mapCenter, mapZoom);
			map.setMapType(mapType);
			
			// Create a marker
			marker = new GMarker(mapCenter);

			// Add the marker to map
			map.addOverlay(marker);
			
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());

			switch (mapTypeS)
			{
				case "office":
					// Our info window content
					var infoTabs = [
					  new GInfoWindowTab(
						"Directions", 
						'<form action="http://maps.google.com/maps" method="get" target="_blank"><fieldset><legend>Get Directions:</legend><label for="saddr">Your address:</label><input type="text" name="saddr" id="saddr" value="" /><br /><br /><input type="submit" value="Get Directions" /><input type="hidden" name="daddr" value="' + 
							mapAddress + 
							'" /><input type="hidden" name="hl" value="en" /></p></form>')
					];

			        GEvent.addListener(marker, "click", function() {
			          marker.openInfoWindowTabsHtml(infoTabs);
			        });
					
					break;
				case "property":
					$$('div#map div span')[0].setStyle({ disply:'block',color:'gray' });
					$$('div#map div span')[0].parentNode.setStyle({ width:'70%' });
					break;
			}
		}
   }