	var map = null;
    var geocoder = null;
    var gmarkers = [];
    
    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(44.097742, -70.208554), 12);
        map.setUIToDefault();
        geocoder = new GClientGeocoder();
        for(i=0;i<aptData.length;i++){
        	showAddress(aptData[i]);
        }
      }
    }

    function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
	}
    
    function showAddress(aptData) {
      if (geocoder) {
      	
      	var infocontents = aptData[1]+'<form id="dir-form-'+aptData[2]+'" class="dir-form" style="height:36px;padding:0;clear:both;margin:0;width:250px;" action="http://maps.google.com/maps" method="get"><input style="margin:0;color:#666;padding:3px;" type="text" size="20" maxlength="40" name="saddr" id="saddr" value="From" onfocus="this.select();this.value=\'\'" /> <input value="Directions" type="submit" style="margin:0;padding:0;"/><input type="hidden" name="daddr" value="'+aptData[0]+'"/></form>';
      	
        geocoder.getLatLng(
          aptData[0],
          function(point) {
            if (!point) {
//              alert(address + " not found");
            } else {
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.bindInfoWindowHtml(infocontents);
              if(document.getElementById("map_legend_list")){
	              GEvent.addListener(marker, "click", function() {
			          marker.openInfoWindowHtml(infocontents);
			       });
			       gmarkers.push(marker);
			        // add a line to the side_bar html
		        
		       		document.getElementById("map_legend_list").innerHTML += '<li style="padding-bottom:4px;"><a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + aptData[3] + '</a></li>';
		       		
		       } else {
			   		map.setCenter(point, 13);
              		marker.openInfoWindowHtml(infocontents);
		       }
		       
            }
          }
        );
      }
    }
