var htmls = [];
var markers = [];
var i = 0;
var resultDisplayed = -1;

function resultMap() {
    $("#map_canvas").width(760).height(300);
    googleMapsInitialize();
}

function resultMapSmall() {
    $("#map_canvas").width(540).height(300);
    googleMapsInitialize();
}

function googleMapsInitialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    map.addControl(new GLargeMapControl());
    map.setMapType(G_HYBRID_MAP);
    map.setCenter(new GLatLng(46.766663,8.299996), 7);

    for(m=0; m<i; m++) {
      if(markers[m]) {
          map.addOverlay(markers[m]);
	  // mouseover for the result rows
          result = $('#searchResult'+m);
	  var r = m;
          result.mouseover(function() { showResult(this) });
	}
      }
  }
}

function createMarker(point,html) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });
  markers[i] = marker;
  htmls[i] = html;
  i++;
}

function showResult(el) {
  i = el.id.substr(el.id.length-1, el.id.length);
  if(resultDisplayed == i) {
    return false;
  }
  markers[i].openInfoWindowHtml(htmls[i]);
  GEvent.addListener(markers[i], "infowindowclose", function() { resultDisplayed = -1 });
  resultDisplayed = i;
}
