var map 	= null;
var myPano 	= null;

function setGoogleMapCenter(lat, lng, zoom)
{
	map.setCenter(new GLatLng(lat, lng), zoom);
}



function performGoogleMapCleanUp()
{
	streetViewElem = document.getElementById("streetViewBox");

	if(streetViewElem.style.display != 'none'){
		
		new Effect.SlideUp("streetViewBox");
	}
}

function showGoogleStreetView(point)
{

	myPano = new GStreetviewPanorama(document.getElementById("streetView"));
	myPano.setLocationAndPOV(point);
	
	streetViewElem = document.getElementById("streetViewBox");
	
	if(streetViewElem.style.display == 'none'){
		
		new Effect.SlideDown("streetViewBox");
	}
}



function createMarker(point, html, mapID, showStreetView)
{
	var marker = new GMarker(point);
		
	// Show this markers index in the info window when it is clicked
	GEvent.addListener(marker, "click", 
		
		function() {

			marker.openInfoWindowHtml(html);

			if(showStreetView == true){
				
				showGoogleStreetView(point);	
				
			}
		});

		
	return marker;
};



function loadMapCenterByCityAndState(city, state) 
{
  
  geocoder = new GClientGeocoder();
  
  var address = city+', '+state;
  
  if (geocoder) {
    geocoder.getLatLng(
      address,
      
	  function(point) {
        
		if (!point) {
        
		  alert("Location not found. Sorry... Please try again later.");
        
		} else {
          map.setCenter(point, 13);
        }
      }
    );
  }
}



function plotMapPoint(location, mapID)
{
  geocoder = new GClientGeocoder();
  
  var address = location;
  
  if (geocoder) {
    geocoder.getLatLng(
      address,
      
	  function(point) {
        
		if (point) {
		
		  // Plot Point
		  var marker = createMarker(point, location, mapID, true);
          
		  map.addOverlay(marker);
        }
      }
    );
  }
}



function loadPropertyMap(city, state) {
  
  if (GBrowserIsCompatible()) {
    
	map = new GMap2(document.getElementById("propertyMap"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());

    if(city && state){
		
		loadMapCenterByCityAndState(city, state);
		
	}else{
		
		setGoogleMapCenter(37.4419, -122.1419, 13);
    }
  }
}

