var addresses = new Array();

var map = null;
var geocoder = null;
var gdir;

var icon = new GIcon();
var this_url = location.href;
var merknaam = this_url.split("/");
icon.image = 'http://www.fixet.nl/google/images/icon.png';
icon.iconSize = new GSize(25,33);
icon.iconAnchor = new GPoint(25,33);
icon.infoWindowAnchor = new GPoint(1,1);

 function getPlaats(naam,zoom) {
      if (geocoder) {
		  geocoder.getLatLng(
          naam,
          function(point) {
            if (!point) {
              alert(adres+' '+postcode+' '+plaats + " niet gevonden.");
            } else {
              map.setCenter(point,zoom);
            }
          }
        );
      }
    }
	
	
	function createMarker(point,html) 
	{
		// Set up our GMarkerOptions object
		markerOptions = { icon:icon };
			
		  var marker = new GMarker(point,markerOptions);
		  GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		  });
		  return marker;
	}	
	
	  function showAddressInit(naam,adres,postcode,plaats,telefoon,zoom) 
	  {
      if (geocoder) {
		  geocoder.getLatLng(
          adres+' '+plaats,
          function(point) {
            if (!point) {
              alert(adres+' '+postcode+' '+plaats + " niet gevonden.");
            } else {
              var marker = createMarker(point,generateHtml(naam,adres,postcode,plaats,telefoon));
              map.addOverlay(marker);
				  if(zoom == 'Y')
				{
					  map.setCenter(point,9);
				}
				map.setUIToDefault();

            }
          }
        );
      }
    }
	
   function showAddresses(id) {
      if (geocoder) {
		 map = new GMap2(document.getElementById("map_canvas"));
		  geocoder.getLatLng(
          addresses[id][1]+' '+addresses[id][3],
          function(point) {
            if (!point) {
              alert(adres+' '+postcode+' '+plaats + " niet gevonden.");
            } else {
              map.setCenter(point,10);
			  map.setUIToDefault();
 			var marker = createMarker(point,generateHtml(addresses[id][0],addresses[id][1],addresses[id][2],addresses[id][3],addresses[id][4]));
             map.addOverlay(marker);
            marker.openInfoWindowHtml(generateHtml(addresses[id][0],addresses[id][1],addresses[id][2],addresses[id][3],addresses[id][4]));
				
				
				var ia = 0;
				for(var index in addresses) 
				{
					if(typeof(addresses[index][0]) != 'undefined') 
					{
						//alert(addresses[index][0]);
						showAddressInit(addresses[index][0],addresses[index][1],addresses[index][2],addresses[index][3],addresses[index][4]);
					}
					
					//ia++;
				}
				
            }
          }
        );
      }
    }	
	
function generateHtml(naam,adres,postcode,plaats,telefoon)
{
	var html = " dit is een test";
	
	html = '<table class="plat" cellspacing="0" style="width:250px">';
	html = html +'<tr>';
	html = html +'<td colspan="2"><span class="kopje_locaties">' + naam + '</span></td>';
	html = html +'</tr>';
	html = html +'<tr>';
	html = html +'<td colspan="2">';
	html = html +'' + adres + '<br>';
	html = html +'' + postcode + ' ' +plaats+ '<br>';
	html = html +'Tel. '+ telefoon;
	html = html +'</td>';
	html = html +'</tr>';
	html = html +'</table>';
	
	return html;
}

