(function($) {
	$.fn.karte = function(options) {
		var settings = {
			"zoom": 17,
			"offsetLat": -0.001,
			"offsetLon": -0.001,
			"icon1": "img/dummy/lobo-marker.gif;100;50;51.22711671830238;6.815085411071777",
			"icon2": "img/dummy/kw-flingern-marker.gif;150;113;51.22515210770799;6.809334754943848",
			"icon3": "img/dummy/creative-discount-marker.gif;120;62;51.22732903113775;6.816844940185547"
		};
		return this.each(function() {
			// If options exist, lets merge them
			// with our default settings
			if (options) {
				$.extend(settings, options);
			}
			// Plugin code here
			var map = null;
			var icon_counter = 0;
			/*
			* Verwenden Sie den google.maps.* Namespace für alle Klassen, Methoden und Eigenschaften, die Sie zurzeit im Google Maps-API verwenden,
			* und der den G-Präfix durch diesen Namespace ersetzt. Führen Sie die Initialisierung Ihrer Objekte mithilfe von google.setOnLoadCallback() durch.
			* Beispielsweise ist das GMap2-Objekt google.maps.Map2 zugeordnet, wenn Sie den Google AJAX-API-Loader verwenden:
			*/
			google.load("maps", "2.x");
			 
			 // Call this function when the page has been loaded
			function initialize() {
				map = new google.maps.Map2(document.getElementById("map"));
				//map.setUIToDefault();
				map.removeMapType(G_SATELLITE_MAP);
				map.removeMapType(G_HYBRID_MAP);
				map.removeMapType(G_PHYSICAL_MAP);
				map.removeControl(new google.maps.LargeMapControl());
				map.disableDoubleClickZoom();
				map.disableScrollWheelZoom();
				$.each(options, function(index, value) {
					if (index.indexOf("icon") > -1) {
						var a = value.split(";");
						var icon_path = a[0];
						var icon_width = a[1];
						var icon_height = a[2];
						var lat = parseFloat(a[3]);
						var lon = parseFloat(a[4]);
						var point = new google.maps.LatLng(lat, lon);
						icon_counter++;
						if (icon_counter == 1) {
							map.setCenter(new google.maps.LatLng(lat+parseFloat(options.offsetLat), lon+parseFloat(options.offsetLon)), options.zoom);
							map.savePosition(); 
							GEvent.addListener(map, "dblclick", function() {
								map.returnToSavedPosition();
							});
							GEvent.addListener(map, "resize", function() {
								map.returnToSavedPosition();
							});
						}
						var icon = new google.maps.Icon(G_DEFAULT_ICON);
						icon.image = icon_path;
						icon.iconSize = new google.maps.Size(icon_width, icon_height);
						icon.shadowSize = new google.maps.Size(0, 0);
						icon.iconAnchor = new google.maps.Point(100, 100);
						
						markerOptions = {
							icon: icon
						};
						map.addOverlay(new GMarker(point, markerOptions));
					}
			    });
			}
         
			function codeAddress() {
				var address = document.getElementById("address").value;
				if (geocoder) {
					geocoder.geocode( { 'address': address}, function(results, status) {
						if (status == google.maps.GeocoderStatus.OK) {
							map.setCenter(results[0].geometry.location);
							var marker = new google.maps.Marker({
								map: map, 
								position: results[0].geometry.location
							});
						} else {
							alert("Geocode was not successful for the following reason: " + status);
						}
					});
				}
			}
         
			google.setOnLoadCallback(initialize);
		})
	}
})(jQuery);





