    var BMap = new Class({
		denmark: new GLatLngBounds(new GLatLng(54.71, 7.778), new GLatLng(57.82, 13.06)),
		poly: false,
		initialize: function(map, view, readonly) {
			this.map		= new GMap2(map);
			this.view		= view;
			this.markers	= [];
			this.points		= [];
			this.length		= 0;
			this.readonly	= readonly;
			
			this.map.setCenter(this.denmark.getCenter(), this.map.getBoundsZoomLevel(this.denmark));
			this.map.enableScrollWheelZoom();
			if (this.readonly) {
				this.map.addControl(new GSmallZoomControl());
				this.map.addControl(new GMenuMapTypeControl());
			} else {
				this.map.disableDoubleClickZoom();
				this.map.addControl(new GLargeMapControl());
				this.map.addControl(new GMapTypeControl());
			}
			this.map.enableContinuousZoom();
			
			if (!this.readonly) GEvent.addListener(this.map, "click", function(o, l) {
				if (o) return;
				
				this.addMark(l);
				this.paint();
			}.bind(this));
		},
		createIcon: function() {
			var icon = new GIcon(G_DEFAULT_ICON, "gui/flag_blue.png");
			icon.shadow = false;
			return icon;
		},
		addMark: function(l) {
			var marker = new GMarker(l, {icon:this.createIcon(), draggable:!this.readonly, bouncy:!this.readonly, dragCrossMove:!this.readonly});
			if (!this.readonly) {
				GEvent.addListener(marker, "dragstart", this.paint.bind(this));
				GEvent.addListener(marker, "drag", this.paint.bind(this));
				GEvent.addListener(marker, "dragend", function(){this.paint()}.bind(this));
			}
			GEvent.addListener(marker, "click", function() {
				var html = new Element("div").setHTML("<strong>"+marker.distance.toFixed(3).replace(".",",")+" km</strong> fra startpunkt<br /><br />");
				if (!this.readonly) html.adopt(new Element("a", {href:"javascript:void(0)"}).setText("Fjern punkt").addEvent("click", function(event) {
					this.map.removeOverlay(marker);
					this.markers.remove(marker);
					this.paint();
				}.bind(this)));
				
				marker.openInfoWindow(html);
			}.bind(this));
			
			this.markers.push(marker);
			this.map.addOverlay(marker);
			return marker;
		},
		search: function(query) {
			new GClientGeocoder().getLatLng(query, function(ll) {
				if (!ll) alert("Det var ikke muligt at finde locationen");
				else this.map.setCenter(ll, 14);
			}.bind(this));
		},
		undo: function() {
			var last;
			if (last = this.markers.pop()) this.map.removeOverlay(last);
			this.paint();
		},
		clear: function() {
			this.markers = [];
			this.map.clearOverlays();
			this.paint();
		},
		toQueryString: function() {
			var qs = "";
			this.markers.each(function(i) {
				qs += "&p[]="+i.getLatLng().toUrlValue();
			});
			return qs;
		},
		paint: function(nocalc) {
			this.map.closeInfoWindow();
			
			if (!nocalc) {
				var lastobj = null;
				var n = 0;
				this.length = 0;
				
				this.points = [];
				this.markers.each(function(i, index) {
					this.points.push(i.getLatLng());
					i.distance = (this.length += (lastobj ? i.getLatLng().distanceFrom(lastobj.getLatLng())/1000 : 0));
					i.setImage(index ? "gui/flag_blue.png":"gui/flag_green.png");
					lastobj = i;
					n = index;
				}.bind(this));
				
				if (lastobj && n) lastobj.setImage("gui/logomarker.png");
				
				this.view.setDistance(this.length);
			}
			
			if (this.poly) this.map.removeOverlay(this.poly);
			this.map.addOverlay(this.poly = new GPolyline(this.points, "#00a5d9", 3, .8));
		},
		fitScreen: function() {
			if (this.poly) {
				var bounds = this.poly.getBounds();
				this.map.setCenter(bounds.getCenter(), Math.max(0, this.map.getBoundsZoomLevel(bounds)-1));
			}
			return this;
		}
	});
	
	var View = new Class({
		initialize: function(distance) {
			this.distance = distance;
			this.setDistance(0);
			return this;
		},
		setDistance: function(v) {
			if (this.distance) this.distance.setText(v.toFixed(1).replace(".",","));
			return this;
		}
	});
