// JavaScript Document

function initialize() {
      	if (GBrowserIsCompatible()) {
 		    var geocoder = null;
			var map = new GMap2(document.getElementById("kaart"));
			



			map.setCenter(new GLatLng(51.5315691, 4.459848), 12); //Zoom in op Roosendaal
			
			var crossLayer = new GTileLayer(new GCopyrightCollection(""), 0, 15);
			crossLayer.getTileUrl =  function(tile, zoom) {
			  return "./include/tile_crosshairs.png";
			}
			crossLayer.isPng = function() {return true;}	
			// Create a new map type incorporating the tile layer
			var layerTerCross = [ G_PHYSICAL_MAP.getTileLayers()[0],
								  crossLayer ];
			var mtTerCross = new GMapType(layerTerCross,
										  G_PHYSICAL_MAP.getProjection(), "Ter+");	
			map.addMapType(G_PHYSICAL_MAP);
			map.addMapType(mtTerCross);        
			var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,40));			
			map.addControl(new GLargeMapControl(),topLeft)	
			var mapControl = new GHierarchicalMapTypeControl();	
			// Set up map type menu relationships
			mapControl.clearRelationships();
			mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
			mapControl.addRelationship(G_PHYSICAL_MAP, mtTerCross, "Crosshairs");
	  
			// Add control after you've specified the relationships
			map.addControl(mapControl);			
			
			var lastmarker=null;
			
			var baseIcon = new GIcon(G_DEFAULT_ICON);
			baseIcon.shadow = false;
			baseIcon.iconSize = new GSize(12, 17);
			baseIcon.iconAnchor = new GPoint(5, 8);
			baseIcon.infoWindowAnchor = new GPoint(9, 2);
			var Icon = new GIcon(baseIcon);	
			Icon.image = "/img/gif/GoogleMapsIcon.gif";
			
			// Set up our GMarkerOptions object
			markerOptions = { icon:Icon };

			
			/************************************************************************************************/
			//Repeat voor elk object 
			
			for(var i=0;i<StraatArray.length;i++){			    
				/*straat = StraatArray[i];
			 	nummer = StraatNRArray[i];
			 	plaats = PlaatsArray[i];
				var address = straat + " " + nummer + ", " + plaats ;*/
				MakeObject(StraatArray[i] + " " + StraatNRArray[i],PlaatsArray[i], FotoArray[i], LinksArray[i], CoordsArray[i]);			  	
			}
			//Einde repeat
			/************************************************************************************************/
		}
    
		function MakeObject(adres,plaats,foto,url,coords){
			if(coords==''){
				geocoder = new GClientGeocoder();
				if (geocoder) {
					geocoder.getLatLng(
						adres + ", " + plaats + ", Nederland",
						function(point) {
							if (!point) {
								//alert(adres + ", " + plaats + ", Nederland" + " not found");
							} else {
								addMarker(point, adres, plaats, foto, url);
							}
						}
					);
				}
			}else{
				coords = coords.split(',');
				if($type(coords)=='array'){
					coords = new GLatLng(coords[0].toFloat(), coords[1].toFloat());
					addMarker(coords, adres, plaats, foto, url);
				}
			}
		}
		
		function addMarker(point, adres, plaats, foto, url){
			var marker = new GMarker(point, markerOptions);
			map.addOverlay(marker);
			GEvent.addListener(marker, "click", function() {
				lastmarker = marker; // save the global reference
				marker.openInfoWindowHtml("<div class=\"GoogleMapsItem\"><h2 style=\"margin:0 0 5px 0;\">Vermunt Makelaardij</h2><div style=\"border:1px solid #000;width:90px;height:67px;float:left;margin:2px 5px 5px 0;\"><a href=\"/"+url+"\" title=\"Bekijk de woning: " + adres + "\"><img src=\"" + foto + "\" alt=\"Bekijk de woning: " + adres + "\" title=\"Bekijk de woning: " + adres + "\" border=\"0\" width=\"90\" height=\"67\" /></a></div><div>" + adres + "<br />" + plaats + "<div style=\"clear:left;\"></div><a href=\"/"+url+"\" title=\"Bekijk de woning: " + adres + "\">Bekijk deze woning &raquo;</a></div></div>");
			});
		}
	}

window.addEvent('domready', function(){
	 initialize()
});

