// JavaScript Document

function machTwIconBuchstabeFortlaufend() {
  //alert(sidebarZeichen);
  var icon           = new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/marker" + sidebarZeichen + ".png");
  icon.printImage    = "http://maps.google.com/mapfiles/marker"+sidebarZeichen+"ie.gif";
  icon.mozPrintImage = "http://maps.google.com/mapfiles/marker"+sidebarZeichen+"ff.gif";
  sidebarZeichen     = String.fromCharCode(sidebarZeichen.charCodeAt(0) + 1);
  return icon;
}

function gotoAdress(address) {
	if (geocoder) {
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					alert(address + " konnte auf der Karte leider nicht gefunden werden.");
				} else {
					//alert(point);
					map.panTo(point);
				}
			}
		)
	}
}

function AddAdressToMap(address,firma) {
	if (geocoder) {
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					//alert(address + " not found");
					sidebarZeichen = String.fromCharCode(sidebarZeichen.charCodeAt(0) + 1);
				} else {
					bounds.extend(point);
					//alert(bounds);
					map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
					//var marker = new GMarker(point);
					var icon = machTwIconBuchstabeFortlaufend();
				    var marker = new GMarker(point, {icon:icon});
					
					GEvent.addListener(marker, "click", function() {
						marker.openInfoWindowHtml("<b>"+firma+"</b><br/>"+address);
					});
					map.addOverlay(marker);
				}
			}
		)
	}
}

function initialize() {
      if (GBrowserIsCompatible()) {
		sidebarZeichen="A";
        map = new GMap2(document.getElementById("map_canvas"));
        //map.setCenter(new GLatLng(50.732704, 7.096311), 13);
        //map.setUIToDefault();
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GLargeMapControl());
		geocoder = new GClientGeocoder();
		bounds = new GLatLngBounds();
		markereintraege= document.getElementsByName('eintrag');
		//alert(markereintraege.length);
		for (var i = 0; i < markereintraege.length; ++i) {
			
			AddAdressToMap(markereintraege[i].value,markereintraege[i].alt);
		}
		
		//alert(bounds);
		//map.setCenter (bounds.getCenter(),13);
	}
}


	


