
   function initialize() {
    initMap();
  }
  
 
    function initMap() {
      var myOptions = {
        zoom: oldZoom,
        center: myLocation,
        mapTypeId: google.maps.MapTypeId.TERRAIN
      };
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  
      geoXml = new geoXML3.parser({
        zoom: true,
        processStyles: true,
        markerOptions: {map: map, shadow: null},
        infoWindowOptions: {pixelOffset: new google.maps.Size(0, 12)},
        singleInfoWindow: true,
        createMarker: addMarker,
        afterParse: parsed,
        failedParse: failed
      });
	  
      // geoXml.parse('data/wikipedia_nearest.kml.php?maxRows=10&lat=' + myLocation.lat().toFixed(6) + '&lng=' + myLocation.lng().toFixed(6));
	  if (west && east && north && south) {
	  	if (catid) {
	  		geoXml.parse('http://www.museumserver.nl/servlet/soortmuseum.kml?z='+oldZoom + '&w='+west+'&e='+east+'&n='+north+'&s='+south+'&catid='+catid);
		} else {
			if (museumid) {
				geoXml.parse('http://www.museumserver.nl/servlet/'+kmlfile+'?z='+oldZoom + '&w='+west+'&e='+east+'&n='+north+'&s='+south+'&museumid='+museumid);
			} else {
				if (zoekterm) {
					geoXml.parse('http://www.museumserver.nl/servlet/'+kmlfile+'?z='+oldZoom + '&w='+west+'&e='+east+'&n='+north+'&s='+south+'&zoekterm='+zoekterm);
				} else {
					geoXml.parse('http://www.museumserver.nl/servlet/'+kmlfile+'?z='+oldZoom + '&w='+west+'&e='+east+'&n='+north+'&s='+south);
				}
			}
		}
	  } else {
	  	if (catid) {
		  	geoXml.parse('http://www.museumserver.nl/servlet/soortmuseum.kml?z='+oldZoom+'&catid='+catid);
		} else {
			if (zoekterm) {
	    		geoXml.parse('http://www.museumserver.nl/servlet/'+kmlfile+'?z='+oldZoom+'&zoekterm='+zoekterm);
			} else {
				geoXml.parse('http://www.museumserver.nl/servlet/'+kmlfile+'?z='+oldZoom);
			}
		}
	  }
    };

    function parsed() {
      geoXml.options.afterParse = geoXml.options.failedParse = null;
      geoXml.options.zoom = false;

      // Attach events to refresh the marker display whenever the map moves
      setTimeout(setupMoveHandler, 1000);
      google.maps.event.addListener(map, 'dragstart',      mapDragStart);
      google.maps.event.addListener(map, 'dragend',        mapDragEnd);
      google.maps.event.addListener(map, 'zoom_changed',   mapZoomChanged);
      oldZoom = map.getZoom();
    };

    function failed() {
      parsed();
      mapBoundsChanged();
    };

    function setupMoveHandler() {
     // moveHandler = google.maps.event.addListener(map, 'bounds_changed', mapBoundsChanged);
	  moveHandler = google.maps.event.addListener(map, 'bounds_changed', scheduleDelayedCallback);
    };

	function fireIfLastEvent()
	{
	   if (lastEvent.getTime() + 450 <= new Date().getTime())
	   {
	       mapBoundsChanged();
	   }
	}
	
	function scheduleDelayedCallback()
	{
	   lastEvent = new Date();
	   setTimeout(fireIfLastEvent, 500);
	}
	
	// event.addListener(map, "bounds_changed", scheduleDelayedCallback);
	

	
	
    function mapDragEnd() {
      mapBoundsChanged();
      setupMoveHandler();
    };

    function mapDragStart() {
      google.maps.event.removeListener(moveHandler);
    };

    function mapZoomChanged() {
	 // alert("zoom changed " + map.getZoom() + "(" + oldZoom + ")");
	  // 
      //if (map.getZoom() != oldZoom) {
        for (var m = markers.length - 1; m >= 0; m--) {
          removeMarker(m);
        }
      //}
      oldZoom = map.getZoom();
    };

    function removeMarker(m) {
      if (!!markers[m].infoWindow) {
        markers[m].infoWindow.close();
      }
      markers[m].setMap(null);
      markers.splice(m, 1);
    };

    function mapBoundsChanged() {
      //  mapMoveEnd: refresh the marker display after the map has moved

      if (!!geoXml.lastmarker && !!geoXml.lastmarker.infoWindow)
        return;
    
      // Get the map boundary coordinates
      var mapBounds = map.getBounds();

      if (!!mapBounds) {
        // Remove old markers from display
        for (var m = markers.length - 1; m >= 0; m--) {
          if (!mapBounds.contains(markers[m].getPosition())) {
            removeMarker(m);
          }
        }

        // Parameterize the geodata URL based on those boundaries 
   //     var url = 'data/wikipedia_bounds.kml.php?maxRows=10&west=' + 
   //     mapBounds.getSouthWest().lng().toFixed(6) + '&north=' + 
   //     mapBounds.getNorthEast().lat().toFixed(6) + '&east=' + 
   //     mapBounds.getNorthEast().lng().toFixed(6) + '&south=' +  
   //     mapBounds.getSouthWest().lat().toFixed(6);

   		if (catid) {
	        var url = 'http://www.museumserver.nl/servlet/soortmuseum.kml?catid='+catid+'&z='+oldZoom+'&w=' + 
	        mapBounds.getSouthWest().lng().toFixed(6) + '&n=' + 
	        mapBounds.getNorthEast().lat().toFixed(6) + '&e=' + 
	        mapBounds.getNorthEast().lng().toFixed(6) + '&s=' +  
	        mapBounds.getSouthWest().lat().toFixed(6);
		} else if (museumid) {
	        var url = 'http://www.museumserver.nl/servlet/'+kmlfile+'?z='+oldZoom+'&w=' + 
	        mapBounds.getSouthWest().lng().toFixed(6) + '&n=' + 
	        mapBounds.getNorthEast().lat().toFixed(6) + '&e=' + 
	        mapBounds.getNorthEast().lng().toFixed(6) + '&s=' +  
	        mapBounds.getSouthWest().lat().toFixed(6) + '&museumid='+museumid;
		} else if (zoekterm) {
	        var url = 'http://www.museumserver.nl/servlet/'+kmlfile+'?z='+oldZoom+'&w=' + 
	        mapBounds.getSouthWest().lng().toFixed(6) + '&n=' + 
	        mapBounds.getNorthEast().lat().toFixed(6) + '&e=' + 
	        mapBounds.getNorthEast().lng().toFixed(6) + '&s=' +  
	        mapBounds.getSouthWest().lat().toFixed(6) + '&zoekterm='+zoekterm;
		} else {
	        var url = 'http://www.museumserver.nl/servlet/'+kmlfile+'?z='+oldZoom+'&w=' + 
	        mapBounds.getSouthWest().lng().toFixed(6) + '&n=' + 
	        mapBounds.getNorthEast().lat().toFixed(6) + '&e=' + 
	        mapBounds.getNorthEast().lng().toFixed(6) + '&s=' +  
	        mapBounds.getSouthWest().lat().toFixed(6);
   		}
		//var url = 'http://www.museumserver.nl/servlet/museum.kml?z=1';
		
        // Load the KML - new markers will be added when it returns
        geoXml.parse(url);
      }
    };

    function addMarker(placemark) {
      var coordinates = new google.maps.LatLng(placemark.point.lat, placemark.point.lng);
      for (var m = markers.length - 1; m >= 0; m--) {
        if (markers[m].getPosition().equals(coordinates)) {
          return;
        }
      }

      var marker = geoXml.createMarker(placemark);
      markers.push(marker);
    };
