/**
 * @author Theo Bakker, WHELP.nl
 * @title 31
 */

//load Google Map
function load() {
  if (GBrowserIsCompatible()) {
  	var map = new GMap2(document.getElementById("map"));
	var geocoder = new GClientGeocoder();
	//geocoder.setBaseCountryCode("NL");

	//add controls
    map.addControl(new GMapTypeControl());
    map.addControl(new GSmallZoomControl()); // Groot zoom/beweeg control

	//create randomnumber to prevent caching and retrieve xml file
	var randomnumber=Math.floor(Math.random()*11111)
    GDownloadUrl("http://www.webstudio88.nl/data.xml?random="+randomnumber, function(data, responseCode) {
    var xml = GXml.parse(data);

	//store markers in markers array
    var markers = xml.documentElement.getElementsByTagName("marker");

	// create marker icon
	var icon = new GIcon();
	icon.image = "http://www.webstudio88.nl/afbeeldingen/icon.png";
	icon.iconSize = new GSize(24, 23);
	icon.iconAnchor = new GPoint(5, 23);
	icon.infoWindowAnchor = new GPoint(5, 1);

	//loop over the markers array
    for (var i = 0; i < markers.length; i++) {
		var address = markers[i].getAttribute("address");
		var html = markers[i].getAttribute("html");
		showAddress(map,geocoder,address,html,icon);
		
    } //close for loop

	  }
	); //close GDownloadUrl

//Create marker and set up event window
function createMarker(point,html,icon){
  var marker = new GMarker(point,icon);
	var strHTML = "<iframe SCROLLING='no' src=http://www.webstudio88.nl/google_maps_frames/" + html + " frameborder=0 border=0 height=50 width=190></iframe>";
	GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(strHTML);
    });	
  return marker;
}

//showAddress
function showAddress(map,geocoder,address,html,icon) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " niet gevonden");
      } else {
        map.setCenter(point, 14);
		htmlText = '<div id="gmapmarker" style="white-space: nowrap;"><div class="tx_lumogooglemaps_pi1_infobox"><b>Totaalgroep B.V.</b><br>Deventerseweg 22<br>2994 LD Barendrecht <br><br>Tel. 010 480 50 93 </div>';
        var marker = createMarker(point,html,icon);
        map.addOverlay(marker);
		map.addControl(new GMapTypeControl());
		
		
		map.openInfoWindowHtml(map.getCenter(), "<iframe SCROLLING='no' src=http://www.webstudio88.nl/google_maps_frames/" + html + " frameborder=0 border=0 height=50 width=190></iframe>", GSize(0, -10));
			

	    		
      }
    }
  );
}





  } //close GBrowserIsCompatible
} //close load
