function Map(options) {
	
	    if(!options.elm) return;
        if(!GBrowserIsCompatible()) return;


		this.elm= options.elm;
		this.onClick=options.onClick;
		this.lt = options.lt;
		this.lg = options.lg;
		this.zoomLevel= options.zoomLevel;
		this.layers=options.layers;
		this.iconSize=options.iconSize;
		this.markersByKey={};
		this.icons={};

        this.map = new GMap2(this.elm);
        this.map.addControl(new GMapTypeControl());
        this.map.addControl(new GOverviewMapControl());
        this.map.addControl(new GSmallMapControl());
        this.map.setCenter(new GLatLng(this.lt, this.lg), this.zoomLevel||6);
        this.map.enableDoubleClickZoom();
		this.map.setMapType(G_NORMAL_MAP);
        this.mgr = new MarkerManager(this.map, {trackMarkers:true});
		this.setupLayers();
    
}

Map.prototype = {

	getIcon: function(images) {
      var icon = null;
      if (images) {
          icon = new GIcon();
          icon.image = images[0];
          icon.iconSize = new GSize(this.iconSize[0], this.iconSize[1]);
          icon.iconAnchor = new GPoint(this.iconSize[0] >> 1, this.iconSize[1] >> 1);
          icon.shadow =  images[1];
          icon.shadowSize = new GSize(this.iconSize[0], this.iconSize[1]);
      }
      return icon;
	},

    setupLayers:function () {

      for (var i = 0,ln=this.layers.length; i < ln; i++) {

        var layer = this.layers[i];

        var markers = [];
        for (var j = 0; j < layer["places"].length;j++) {

          var place = layer["places"][j];	
          var icon = this.getIcon(place["icon"]);
          var title = place["name"];
		
          var posn = new GLatLng(place["posn"][0], place["posn"][1]);
          var marker = this.createMarker(posn,title,icon,place["id"]); 
          markers.push(marker);
		  this.markersByKey[place["id"]]=marker;
        }
   		this.mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
      }
      this.mgr.refresh();
	},

   createMarker:function(posn, title, icon,i) {
      var marker = new GMarker(posn, {title: title, icon: icon, draggable:false });
	　marker.data = i;
	  marker.title=title;
	  var onClick=this.onClick||function(){};
	  var self=this;
 	  google.maps.Event.addListener(marker,  "click", function(overlay,latlng,overlaylatlng) {
			onClick.call(self,marker);
  	  });
      return marker;
   },

   deleteMarker:function() {
       var markerNum = parseInt(document.getElementById("markerNum").value);
       mgr.removeMarker(this.allmarkers[markerNum]);
   }, 

   clearMarkers:function() {
       mgr.clearMarkers();
   }

}
