var geo = new GClientGeocoder();
var nextAddress = 0;
var delay = 100;
var map;

function initial() 
{
    
 if (GBrowserIsCompatible() && address != "")
 {     
      map = new GMap2(document.getElementById("map_canvas"));
      map.addControl(new GLargeMapControl()); 
      map.setCenter(new GLatLng(50.036405, 5.695092), 4);
      theNext();
 }
}
function getAddress(search,next) {
        geo.getLocations(search, function (result)
          { 
            // If that was successful
            if (result.Status.code == G_GEO_SUCCESS) {
              // Lets assume that the first marker is the one we want
              var p = result.Placemark[0].Point.coordinates;
              var lat=p[1];
              var lng=p[0];
              var point = new GPoint(lng,lat);
              map.addOverlay(createMarker(point, nextAddress));         
            }
            // ====== Decode the error status ======
            else {
              // === if we were sending the requests to fast, try this one again and increase the delay
              if (result.Status.code == G_GEO_TOO_MANY_QUERIES) {
                nextAddress--;
                delay++;
              } 
            }
            next();
          }
        );
      }
 function theNext() {
        if (nextAddress < address.length) {
          setTimeout("getAddress('"+address[nextAddress]+"',theNext)", delay);
          nextAddress++;
        }        
      }
function FensterOeffnen (Adresse) {
  MeinFenster = window.open(Adresse, "_self", "width=1024,height=768,left=0,top=0,scrollbars=yes");
  MeinFenster.focus();
 }

 function createMarker(point, index) {
          var marker = new GMarker(point);
          GEvent.addListener(marker, "mouseover", function() {
            marker.openInfoWindowHtml("<div align='center'><b>"+name[index-1]+"</b><BR><BR>"+address[index-1]+"</div>");  
          });
          GEvent.addListener(marker, "mouseout", function() {
            marker.closeInfoWindow();});          
          GEvent.addListener(marker, "click", function() {
            FensterOeffnen(url[index-1]);});  
          return marker;
        }
registerEventListener(window, 'load', initial);
registerEventListener(window, 'unload', GUnload);
