var map = null;
var geocoder = null;

function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl()); 
    map.addControl(new GMapTypeControl()); 
    map.setCenter(new GLatLng(52.2296, 21.0122), 14);
    map.enableScrollWheelZoom();
    geocoder = new GClientGeocoder();
    //GEvent.addListener(map, "click", clicked);
  }
}

function showAddress(address) {
  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          alert("We're sorry but '" + address + "' cannot be found on Google Maps. Please try again.");
        } else {
 	     map.panTo(point);
 	     map.addOverlay(new GMarker(point));
      }
    });
  }
}

function getAddress() {
  var doc = document.getElementById("kontakt")
  if( doc != null) {
    var regexp = /ul\. .+warszaw/i
    var addr = regexp.exec(doc.innerHTML.replace(/<br>/g," ").replace(/\n/g, " "));
    if( addr != null) {
      addr += "a";
      return addr
    }
  }
}

window.onload = function() {
  initialize();
  showAddress(getAddress());
}
