/**

 * Created by Theis Iversen, 20-10-2008

**/

var BMap = new Class({

	denmark: new GLatLngBounds(new GLatLng(54.71, 7.778), new GLatLng(57.82, 13.06)),

	poly: false,

	initialize: function(map) {

		this.map		= new GMap2(map);

		this.markers	= [];

		

		this.map.setCenter(this.denmark.getCenter(), this.map.getBoundsZoomLevel(this.denmark));
		
		this.map.setMapType(G_NORMAL_MAP);

		this.map.enableScrollWheelZoom();

		this.map.addControl(new GSmallZoomControl());

		this.map.addControl(new GMenuMapTypeControl());

		this.map.enableContinuousZoom();

	},

	createIcon: function(img) {

		var icon = new GIcon(G_DEFAULT_ICON);

		icon.shadow = true;

		if (img[0] && img[1] && img[2]) {

			icon.image = img[0];

			icon.iconSize = new GSize(img[1], img[2]);

			icon.iconAnchor = new GPoint(img[1]/2, img[2]);

		}

		return icon;

	},

	addMark: function(id, l, img, info) {

		var marker = new GMarker(l, {icon:this.createIcon(img), draggable:false, bouncy:false, dragCrossMove:false});

		GEvent.addListener(marker, "click", function() {

			marker.openInfoWindow(new Element("div").setHTML("<div style='font-size:10px;font-family:Verdana'>"+info+"<br><a href='index.php?option=com_jumi&fileid=3&Itemid=114&rejseid=1&open="+id+"'>Se dagbog</a></div>"));

		}.bind(this));

		

		this.markers.push(marker);

		this.map.addOverlay(marker);

		return marker;

	},

	paint: function() {

		this.map.closeInfoWindow();

		

		var points = [];

		this.markers.each(function(i) {

			points.push(i.getLatLng());

		}.bind(this));

		

		this.map.addOverlay(this.poly = new GPolyline(points, "#0000ff", 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;

	}

});

