// JavaScript Document

	var map;
    var geocoder;
    function load() {
      if (GBrowserIsCompatible()) {
        geocoder = new GClientGeocoder();
        map = new GMap2(document.getElementById('map'));
	    CustomGetTileUrl=function(a,b){
          var f;
		  if(b>11){f = "http://crmap.com/maps/"+(a.x)+"_"+(a.y)+"_"+(b)+".gif";}
		  else {f = G_PHYSICAL_MAP.getTileLayers()[0].getTileUrl(a,b);}
		  return f;	  
	    }
//create the GTileLayer
      var tilelayers = [new GTileLayer(new GCopyrightCollection("MapCR.com"),7,16)];
      tilelayers[0].getTileUrl = CustomGetTileUrl;
      tilelayers[0].getCopyright = function(a,b) {
	  var copy;
	  if(b>11) {copy = {prefix:"&copy;2009 ", copyrightTexts:["Toucan Maps"]};}
	  else {copy = {prefix:"Terrain&copy;2008 ", copyrightTexts:["LeadDog Consulting, Europa Technologies"]};}
	    return copy;
      }
//create the GMapType based on G_SATELLITE_MAP
      var custommap = new GMapType(tilelayers, G_SATELLITE_MAP.getProjection(), "Map");
      map.addMapType(custommap);
// == Add logo as a custom control
      var logoposition = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(2,32));
      logoposition.apply(document.getElementById("logo"));
      map.getContainer().appendChild(document.getElementById("logo"));
	  map.addMapType(G_PHYSICAL_MAP);
      map.removeMapType(G_HYBRID_MAP);
      map.removeMapType(G_NORMAL_MAP);

      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
	  map.addControl(new GScaleControl());

	  var omc_size = new GSize(160, 110);
	  var omc = new GOverviewMapControl(omc_size);
      omc.setMapType(custommap);
      map.addControl(omc);

	  map.setCenter(new GLatLng(10.01894, -84.2134), 8, custommap);
	  

// == Listen for map click and show local markers
	  var lastmarker;
	  // == Add showall button as a custom control
      var showall = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(2,396));
      showall.apply(document.getElementById("showall"));
      map.getContainer().appendChild(document.getElementById("showall"));

//      GEvent.addListener(map,"click",function(overlay,point){if (!overlay) {showlocalMarker(point);	}   });
	
      }// could be the end of the if (GBrowserIsCompatible())
	  else {alert("Sorry, the Google Maps API is not compatible with this browser");}
      var starting='';
//	  var collection_override should be defined in the content field of the entry if you want to show a different collection on the map than the one that appears in the menu
	  if (typeof collection_override =="undefined") {
	  var query = document.URL;
      var urlparts = query.split("/");
      if (urlparts[3] == "collection") {
		starting = (urlparts[4]);
		var starting_collection = startingLocations(starting);
	  }//if (urlparts[0] == "collection")
	  else if (urlparts[3] == "travel-map") {
		starting = (urlparts[4]);
		var starting_collection = startingLocations(starting);
	  }//if (urlparts[0] == "collection")
	  }
	  else {
	  starting = collection_override;
	  var starting_collection = startingLocations(starting);
	  }

	  if (starting == '') {
        var query = location.search.substring(1);
        // split the rest at each "&" character to give a list of  "argname=value"  pairs
        var pairs = query.split("&");
        for (var i=0; i<pairs.length; i++) {
        // break each pair at the first "=" to obtain the argname and value
	      var pos = pairs[i].indexOf("=");
	      var argname = pairs[i].substring(0,pos).toLowerCase();
	      var value = pairs[i].substring(pos+1).toLowerCase();
          if (argname == "collection_id") {
		    starting = (value);
		    var starting_collection = startingLocations(starting);
		  }//end if (argname == "collection_id") 
		  else if (argname == "searchfor") {
		    searchfor = (value);
			//searchfor = '%' + searchfor + '%',
			//alert (searchfor);
		    var searching = searchforMarkers(searchfor);
		  }//end else if (argname == "searchfor")  
        }// end for (var i=0; i<pairs.length; i++) 
	  }//end if (starting = '')


    }//end of load()