//dependencies:
//location_info comes from php 

google.load("maps", "2.x");
//google.load("jquery", "1.3.1"); //very interesting, but not ready to do this just yet (8/28/09)

function SC_getGoogleMarker($googleLocation, $locationName, $locationAddress, $markerDimensions, $markerPath)
{
  //optional parameter for automatic display of info window
  var auto_display = arguments[5]!==false;
  
  //add a map point for the property
  //template icon approach not really necessary, but will be useful for more than one icon on map
  var icd = $markerDimensions;
  var custIcon = new GIcon(G_DEFAULT_ICON);
  custIcon.iconSize = new GSize(icd[0], icd[1]);
  custIcon.shadowSize = new GSize(0, 0);
  custIcon.iconAnchor = new GPoint(icd[0]/2, icd[1]);
  var marker_icon = new GIcon(custIcon, $markerPath);
  var marker_title = '<strong>'+$locationName+'</strong><br />'+$locationAddress;
  var marker = new GMarker($googleLocation, marker_icon);
  if(auto_display){
    marker.openInfoWindowHtml('<div style="white-space:nowrap;">'+marker_title+'</div>');
  }
  GEvent.addListener(marker, 'click', function(){ 
	  marker.openInfoWindowHtml('<div style="white-space:nowrap;">'+marker_title+'</div>');
	});
	
	return marker;
}

$(function(){
    if(GBrowserIsCompatible()){
      //create map and set center location
      var map = new GMap2(document.getElementById('map'));
      var main_google_loc = new GLatLng(location_info.lat, location_info.lon);
      map.setCenter(main_google_loc, 16, G_HYBRID_MAP);
    
      //add some controls
      map.addControl(new GMapTypeControl(1));
			map.addControl(new GLargeMapControl());
			map.addControl(new GScaleControl(256));
			
			//add location marker
			map.addOverlay(SC_getGoogleMarker(main_google_loc, location_info.name, location_info.full_address, location_info.map_icon_dimensions, location_info.map_icon_path));
      
      //add office marker
      
      if(typeof(office_location_info) != 'undefined'){
        var office_google_loc = new GLatLng(office_location_info.lat, office_location_info.lon);
  			map.addOverlay(SC_getGoogleMarker(office_google_loc, office_location_info.name, office_location_info.full_address, office_location_info.map_icon_dimensions, office_location_info.map_icon_path, false));
      }
  		
		}else{
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
});

