var map;
var geocoder;

$(document).ready(function(){
    GmapInitialize();
  
    showAddress('2571 S. Hemlock Rd, Green Bay, WI 54229');
    
    $(".map-link").click(function (e){
        e.preventDefault();
        showAddress(this.name);
        $("h4").removeClass("imhere");
        $(this).closest("h4").addClass("imhere");
    });
});

function GmapInitialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl())
        geocoder = new GClientGeocoder();
        // Create our "tiny" marker icon
        var baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.image = "/css/images/map-marker.png";
        baseIcon.iconSize = new GSize(30, 37);
        baseIcon.iconAnchor = new GPoint(15, 37);
        baseIcon.shadow = "/css/images/map-marker-shadow.png";
        baseIcon.shadowSize = new GSize(30, 37);
		
    		// Set up our GMarkerOptions object
    		markerOptions = { icon:baseIcon };
    		
    		var point = new GLatLng(44.538171,-87.866448);
    		map.setCenter(point, 13);
        var marker = new GMarker(point, markerOptions);
        map.addOverlay(marker);    		
    }
}

function showAddress(address) {
    map.clearOverlays();
    if (address == "wilton") {
      var point = new GLatLng(42.841383,-71.739038);
  		map.setCenter(point, 13);
      var marker = new GMarker(point, markerOptions);
      map.addOverlay(marker);
    } else {
      if (geocoder) {
          geocoder.getLatLng(
              address,
              function(point) {
                  if (!point) {
                      alert(address + " not found");
                  } else {
                      map.setCenter(point, 13);
                      var marker = new GMarker(point, markerOptions);
                      map.addOverlay(marker);
                      //marker.openInfoWindowHtml(address);
                  }
              }
          );
      }
    }
}