/* Google Maps */

	var map 	 = null;
	var geocoder = null;

	function initialize() {
		if (GBrowserIsCompatible()) {
			map 	 = new GMap2($("map_canvas"));
			geocoder = new GClientGeocoder();
		}
	}

	function activateGoogleMaps() {
		// Init Googlemaps
		initialize();

		// Get current Adress-Objects form DOM
		var streetObj = $("address-street");
		var zipObj    = $("address-zip");
		var cityObj   = $("address-city");
		var companyObj= $$("div.address-company span.org");

		var streetContent = streetObj.innerHTML;
		var zipContent    = zipObj.innerHTML;
		var cityContent   = cityObj.innerHTML;
		var companyContent= companyObj.getText();
		//console.debug(companyContent);

		// Show current Adress with Google Maps
		if ( streetObj && zipObj && cityObj && companyObj) {
			if (window.webkit) {
				streetContent = streetObj.innerHTML;
				zipContent    = zipObj.innerHTML;
				cityContent   = cityObj.innerHTML;
				companyContent= companyObj.getText().toString();
			} else {
				streetContent = streetObj.getText();
				zipContent    = zipObj.getText();
				cityContent   = cityObj.getText();
				companyContent= companyObj.getText();
			}
			showAddress( streetContent, zipContent, cityContent, companyContent);
		} else {
			console.warn("DEV ERROR: No adress data found in html code!");
			console.warn("DEV ERROR: No adress was submited via JS to GoogleMaps!");
		}
	}

	function showAddress( street, zip, city, company) {
		var address = street + ", " + zip + " " + city;
		if (geocoder) {
			geocoder.getLatLng( address, function(point) {
				if (!point) {
					alert("Google Maps: Der Standort konnte leider nicht gefunden werden!");
				} else {
					map.addControl( new GSmallMapControl() );
					map.addControl( new GScaleControl()    );
					map.addControl( new GMapTypeControl()  );
					map.setCenter( point, 13 );
					var marker = new GMarker( point );
					map.addOverlay( marker );
					marker.openInfoWindowHtml('<div id="mapslogo"></div><div id="mapsadress"><h2 style="padding-left:0;">'+ company + '</h2><p>' + street+ '<br />' + city + ', ' + zip + '</p></div>');
				}
			});
		}
	}
