var gMap = {
  map: null,
  infoWindow: null,
  geocoder: null
};
gMap.closeInfoWindow = function() {
  gMap.infoWindow.close();
};
gMap.openInfoWindow = function(marker) {
  var markerLatLng = marker.getPosition();
  gMap.infoWindow.setContent([address].join(''));
  gMap.infoWindow.open(gMap.map, marker);
};
gMap.init = function() {

 gMap.geocoder = new google.maps.Geocoder();
    var myOptions = {
   		zoom: 8,
   		mapTypeControl: true,
      	mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
      	navigationControl: true,
    	navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
	    mapTypeId: google.maps.MapTypeId.ROADMAP
  	};
  	gMap.map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	gMap.codeAddress(address);
 	gMap.infoWindow = new google.maps.InfoWindow();
  
  	google.maps.event.addListener(gMap.map, 'click', gMap.closeInfoWindow);
};

gMap.codeAddress = function(address) {
	if (gMap.geocoder) {
		gMap.geocoder.geocode( { 'address': address}, function(results, status) {
        	if (status == google.maps.GeocoderStatus.OK) {
          		gMap.map.setCenter(results[0].geometry.location);
				gMap.makeMarker(results[0].geometry.location);
		  		gMap.map.setZoom(14)
        	} else {
          		alert("Geocode was not successful for the following reason: " + status);
        	}
      	});
	}
};
gMap.makeMarker = function(location) {
  var marker = new google.maps.Marker({
              		map: gMap.map, 
              		position: location
          		});
	google.maps.event.addListener(marker, 'click', function() {
    	gMap.openInfoWindow(marker);
  	});
};

