/* The arrays */
var tandartsen_lengte = new Array();
var tandartsen_breedte = new Array();
var tandartsen_name = new Array();
var tandarts_link = new Array();
var tandarts_content = new Array();
var tandarts_adres = new Array();
var tandarts_postcode = new Array();
var tandarts_woonplaats = new Array();
var tandarts_tel = new Array();

var lastWindow;
var map;
var geocoder;


function initialize() {
	geocoder = new google.maps.Geocoder();
	setTimeout("map = init();",100);
	
}
function init(){
  	
	// Create a new map with some default settings
    var myLatlng = new google.maps.LatLng(53.218424, 6.5775871);
    var myOptions = {
      zoom: 10,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
    infoWindow = new google.maps.InfoWindow();
    google.maps.event.addListener(map, 'click', function() {
      infoWindow.close();
    });

	// Initialize Fluster and give it a existing map
	var fluster = new Fluster2(map);
	
	var a_tandarts = tandartsen_lengte.length;
		for(var i = 0; i < a_tandarts; i++){
		
		var marker = new google.maps.Marker({
				position: new google.maps.LatLng(tandartsen_lengte[i], tandartsen_breedte[i]),
				title: tandartsen_name[i]
		});

		 var contentString = "<div style='color:black;'><strong>" + tandartsen_name[i] + " </strong><br />" + tandarts_adres[i] + "<br />"+tandarts_postcode[i]+" "+tandarts_woonplaats[i]+"<br />"+tandarts_tel[i]+"<br /><a href='"+ tandarts_link[i]+ "'>Details</a></div>";
		 var infowindow = new google.maps.InfoWindow({
		       content: contentString,
		       maxWidth: 200
		  });

		fluster.addMarker(marker);
		addInfoWindow(marker, map, contentString);
	}
	
	// Set styles
	// These are the same styles as default, assignment is only for demonstration ...
	fluster.styles = {
		// This style will be used for clusters with more than 0 markers
		0: {
			image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m1.png',
			textColor: '#FFFFFF',
			width: 53,
			height: 52
		},
		// This style will be used for clusters with more than 10 markers
		10: {
			image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m2.png',
			textColor: '#FFFFFF',
			width: 56,
			height: 55
		},
		20: {
			image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m3.png',
			textColor: '#FFFFFF',
			width: 66,
			height: 65
		}
	};
	// Initialize Fluster
	// This will set event handlers on the map and calculate clusters the first time.
	fluster.initialize();
	return map;
}

function initialize2() {
	tandartsen_lengte = new Array();
	tandartsen_breedte = new Array();
	tandartsen_name = new Array();
	tandarts_link = new Array();
	tandarts_content = new Array();
	tandarts_adres = new Array();
	tandarts_postcode = new Array();
	tandarts_woonplaats = new Array();
	tandarts_tel = new Array();
	map = "";
	//map.clearOverlays();

	
	setTimeout("map = init2();",100);
	
}
function init2(){
  	
	// Create a new map with some default settings
    var myLatlng = new google.maps.LatLng(52.0912623, 5.12227478);
    var myOptions = {
      zoom: 7,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
    infoWindow = new google.maps.InfoWindow();
    google.maps.event.addListener(map, 'click', function() {
      infoWindow.close();
    });

	// Initialize Fluster and give it a existing map
	var fluster = new Fluster2(map);
	
	var a_tandarts = tandartsen_lengte.length;
		for(var i = 0; i < a_tandarts; i++){
		
		var marker = new google.maps.Marker({
				position: new google.maps.LatLng(tandartsen_lengte[i], tandartsen_breedte[i]),
				title: tandartsen_name[i]
				
		});

		 var contentString = "<div><strong>" + tandartsen_name[i] + " </strong><br />" + tandarts_adres[i] + "<br />"+tandarts_postcode[i]+" "+tandarts_woonplaats[i]+"<br />"+tandarts_tel[i]+"<br /><a href='"+ tandarts_link[i]+ "'>Details</a></div>";
		 var infowindow = new google.maps.InfoWindow({
		       content: contentString,
		       maxWidth: 200
		  });

		fluster.addMarker(marker);
		addInfoWindow(marker, map, contentString);
	}
	
	// Set styles
	// These are the same styles as default, assignment is only for demonstration ...
	fluster.styles = {
		// This style will be used for clusters with more than 0 markers
		0: {
			image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m1.png',
			textColor: '#FFFFFF',
			width: 53,
			height: 52
		},
		// This style will be used for clusters with more than 10 markers
		10: {
			image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m2.png',
			textColor: '#FFFFFF',
			width: 56,
			height: 55
		},
		20: {
			image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m3.png',
			textColor: '#FFFFFF',
			width: 66,
			height: 65
		}
	};
	// Initialize Fluster
	// This will set event handlers on the map and calculate clusters the first time.
	fluster.initialize();
	return map;
}

function reloadInit(lengte,breeedte,zoom){
	var locations = new google.maps.LatLng(lengte, breeedte);
    map.setCenter(locations);
    map.setZoom(zoom);
}

function removeMarkers(){
	
}



function addTandarts(lengte,breedte,naam,tlink,adres,postcode,woonplaats,tel){
	 // window.alert('J');
	  arr = new Array();
	  image = 'beachflag.png';
	  //var adres = new google.maps.LatLng(lengte,breedte);
	  
	  tandartsen_lengte.push(lengte);
	  tandartsen_breedte.push(breedte);
	  tandartsen_name.push(naam);
	  tandarts_link.push(tlink);
	  tandarts_adres.push(adres);
	  tandarts_postcode.push(postcode);
	  tandarts_woonplaats.push(woonplaats);
	  tandarts_tel.push(tel);
}

function codeAddress(adress,id) {
    var address = adress;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
       // map.setCenter(results[0].geometry.location);
       // window.alert(results[0].geometry.location);
        	phpNaarDiv('go','/action/custom/ajax.code_caress.php',false,'&productid='+id+'&lengte=' + results[0].geometry.location);
      } else {
        //alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }

function addInfoWindow(marker, map, message){ 
		    /* set balloon */
		    var infowindow = new google.maps.InfoWindow(
		    {
		          content: message
		    });    
		     
		    /* add listener to marker */
		    google.maps.event.addListener(marker, 'click' ,function(){
		        infowindow.open(map,marker);
		     
		    if(lastWindow) { lastWindow.close(); lastWindow = null; }
		        lastWindow = infowindow;
		    });
		};
