
	google.load("maps", "2.x");
    google.load("jquery", "1.3.2");

	
	function initialize() {

		function createMarker(point, betrieb) {
						 
      		var myIcon = new GIcon();
      		myIcon.image = "http://www.mammascreening-bonn-rhein-sieg-euskirchen.de/fileadmin/marker/" +betrieb['icon'];
      		
      		myIcon.shadow = "";
      		myIcon.iconSize = new GSize(betrieb['iconWidth'], 49);
      		myIcon.shadowSize = new GSize(0, 0);
      		myIcon.iconAnchor = new GPoint(15, 42);
      		myIcon.infoWindowAnchor = new GPoint(5, 1);
    		
      		markerOptions = { icon:myIcon };

      		
      		var marker = new GMarker(point, markerOptions);
      		
			/* GEvent.addListener(marker, "click", function() {
				
				map.openInfoWindowHtml(point, '<p><b>' + betrieb['standort'] + '</b><br/>' + betrieb['zeitraum'] + '</p>');
			}); */
			return marker;
		}
		
		function createStandort(betrieb) {
			geocoder.getLatLng(
	  			betrieb['adresse'],
				function(point) {
					if (!point) {
						alert("Adresse " +  betrieb['adresse'] + " nicht gefunden!");
					} else {
						bounds.extend(point);
						map.addOverlay(createMarker(point, betrieb));
						map.setCenter(bounds.getCenter());
						map.setZoom(map.getBoundsZoomLevel(bounds)); 	
					}
				}
	  		);
		}
			
		if (GBrowserIsCompatible()) {
        	var map = new GMap2(document.getElementById("map_canvas"));
        	map.setCenter(new GLatLng(0,0),0);
    		var geocoder = new GClientGeocoder();
        	var bounds = new GLatLngBounds();
        	
        	for (var i in betriebe) {
            	if (betriebe[i]['latitude']!=0 && betriebe[i]['longitude']!=0) {

            		/*
            		var point = new  GLatLng(betriebe[i]['latitude'],betriebe[i]['longitude']);
            		bounds.extend(point);

            		map.addOverlay(createMarker(point, betriebe[i]));
            		*/
            		
            		createStandort(betriebe[i]);

            		
            	}
        	}
        	 
        	      
			// map.setCenter(bounds.getCenter());
			// map.setZoom(map.getBoundsZoomLevel(bounds)); 		
			map.addControl(new GSmallMapControl());
			map.addMapType(G_PHYSICAL_MAP);
			map.setMapType(G_PHYSICAL_MAP);
			$('div.map_type_button').css('font-weight', 'normal');
			$('div#map_type_physical').css('font-weight', 'bold');
			map.removeMapType(G_HYBRID_MAP);
			// map.addControl(new GMapTypeControl());
							   
		}
		
		$('div#map_type_normal').click(function() {
			map.setMapType(G_NORMAL_MAP);
			$('div.map_type_button').css('font-weight', 'normal');
			$(this).css('font-weight', 'bold');
		});
		
		$('div#map_type_physical').click(function() {
			map.setMapType(G_PHYSICAL_MAP);
			$('div.map_type_button').css('font-weight', 'normal');
			$(this).css('font-weight', 'bold');
		});
		
		$('div#map_type_satellite').click(function() {
			map.setMapType(G_SATELLITE_MAP);
			$('div.map_type_button').css('font-weight', 'normal');
			$(this).css('font-weight', 'bold');
		});
		
		$('div.map_type_button').css('opacity', 0.8); 
		if(jQuery.browser.msie) $('div.map_type_button').css('width', '82px');
		
		$('div.map_type_button').hover(
				function () {
					$(this).css('background', '#eee');
				}, 
				function () {
					$(this).css('background', '#fff');
				}
		);
	}

	google.setOnLoadCallback(initialize);