function markerAdditionDisabler(){
	addmarker = false;
}

function createMarker(point, type) {
  var f = new GIcon();
  if(type=="green")
  {
	  f.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
	f.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
  }else{
	  f.image = mapIcon + type
            + ".png";
 	 f.shadow = mapIcon + type
            + "s.png";
			}
 // f.iconSize = new GSize(12,20);
  //f.shadowSize = new GSize(22,20);
  f.iconAnchor = new GPoint(6,20);
  f.infoWindowAnchor = new GPoint(6,1);
  f.infoShadowAnchor = new GPoint(13,13);

  newMarker = new GMarker(point,
    {icon: f,
     draggable: true});

  return newMarker;
}

// Create the Google Map to be used.
function createMap() {
  if (!GBrowserIsCompatible()) {
    alert('Your browser is not compatible with the Google Maps API');
    return;
  }
  document.map = new GMap2(document.getElementById("map"));
  marker = null;
      
      // ============================================================
      // ====== Create a copyright entry =====
      var copyright = new GCopyright(1,
          new GLatLngBounds(new GLatLng(bottom, left),new GLatLng(top, right) ),minZoom, mapSource);


      // ============================================================
      // ====== Create a copyright collection =====
      // ====== and add the copyright to it   =====
      var copyrightCollection = new GCopyrightCollection('Map Data:');
      copyrightCollection.addCopyright(copyright);
      

      // ============================================================
      // == Write our own getTileUrl function ========    
      CustomGetTileUrl=function(tile,zoom){
		var ymax = 1 << zoom;
		var y = ymax - tile.y -1;
	  	return  mapUrl+build+"/"+stair+"/"+zoom+"/"+tile.x+"/"+y+".jpg"
      }


      // ============================================================
      // ===== Create the GTileLayer =====
      // ===== adn apply the CustomGetTileUrl to it
      var tilelayers = [new GTileLayer(copyrightCollection,minZoom,maxZoom)];
      tilelayers[0].getTileUrl = CustomGetTileUrl;
      
      
      // ============================================================
      // ===== Create the GMapType =====
      // ===== and add it to the map =====
      var custommap = new GMapType(tilelayers, new GMercatorProjection(18), mapSource);
      document.map.addMapType(custommap);
      document.map.setCenter(new GLatLng(centlat,centlng), minZoom, custommap);
	  document.map.addControl(new GLargeMapControl());
	  
	  GEvent.addListener(document.map,"move", function() {
           checkBounds();
		} );
      

	  
/*use different mode to enable/disable the following function*/
if(addmarker == true){
    GEvent.addListener(document.map, "click", function(custommap, point) {
													   
		document.getElementById('txtLatitude').value = point.y.toFixed(6);
    	document.getElementById('txtLongitude').value = point.x.toFixed(6);


    	if (marker == null) {
      	marker = createMarker(point, "green");
      	marker.enableDragging();
		
		
      	GEvent.addListener(marker, "drag", function() {
        	document.getElementById('txtLatitude').value = marker.getPoint().y.toFixed(6);
        	document.getElementById('txtLongitude').value = marker.getPoint().x.toFixed(6);
      	});
		

      	document.map.addOverlay(marker);
    	} else {
      	marker.setPoint(point);
    	}
	 
  	});
}
}

function checkBounds() {
    // Get some info about the current state of the map
    var C = document.map.getCenter();
    var lng = C.lng();
    var lat = C.lat();
    var B  = document.map.getBounds();
    var sw = B.getSouthWest();
    var ne = B.getNorthEast();
    // Figure out if the image is outside of the boundaries
    // created by our custom projection object.
    var new_lat = lat;
    var new_lng = lng;
	
    if (sw.lat() < bottom) {
        new_lat = lat - (sw.lat() + top);
    }
    else if (ne.lat() > top+1.5) {
        new_lat = lat - (ne.lat() + bottom-1.5);
    }
    if (sw.lng() < left-2) {
        new_lng = lng - (sw.lng() + right+2);
    }
    else if (ne.lng() > right+5) {
        new_lng = lng - (ne.lng() + left-5);
    }
	
    if (new_lat != lat || new_lng != lng) {
        document.map.setCenter(new GLatLng(new_lat,new_lng));
    }
}