var info = [];
var gmarkers = [];
var htmls = [];
var i = 0;

var map;

// A function to create a tabbed marker and set up the event window
function createTabbedMarker(point,html1,html2,html3,label1,label2,label3) {

	markerOpts = {};

	var baseIcon = new GIcon();
	baseIcon.shadow = "http://rwi-wordpress.webhotel.net/rockwool/gfx/gmaps/map_shadow_01.png";
	baseIcon.iconSize = new GSize(15, 20);
	baseIcon.shadowSize = new GSize(1, 1);
	baseIcon.iconAnchor = new GPoint(7, 20);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	baseIcon.infoShadowAnchor = new GPoint(12, 25);
	var icon = new GIcon(baseIcon);
	icon.image = "http://rwi-wordpress.webhotel.net/rockwool/gfx/gmaps/rlogo_15x20px.png";

	markerOpts.icon = icon;

	var marker = new GMarker(point, markerOpts);
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,html1), new GInfoWindowTab(label2,html2)]);
	});
	return marker;
}


function createTabbedInfoMarker(point,html1,label1) {

	markerOpts = {};

	var baseIcon = new GIcon();
	baseIcon.shadow = "http://rwi-wordpress.webhotel.net/rockwool/gfx/gmaps/map_shadow_01.png";
	baseIcon.iconSize = new GSize(15, 20);
	baseIcon.shadowSize = new GSize(1, 1);
	baseIcon.iconAnchor = new GPoint(7, 20);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	baseIcon.infoShadowAnchor = new GPoint(12, 30);
	var icon = new GIcon(baseIcon);
	icon.image = "http://rwi-wordpress.webhotel.net/rockwool/gfx/gmaps/rlogo_15x20px.png";

	markerOpts.icon = icon;

	var marker = new GMarker(point, markerOpts);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,html1)]);
	});
	return marker;
}


function loadmap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));

		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GSmallMapControl());
//		map.addControl(new GOverviewMapControl());
//		map.addControl(new GScaleControl());
//		map.removeMapType(G_SATELLITE_MAP);
//		map.removeMapType(G_HYBRID_MAP);

		map.enableScrollWheelZoom();
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();

		map.setCenter(new GLatLng(0,0),0);

		// Create a bounds objects
		var bounds = new GLatLngBounds();
		var point;
		var marker;

		for (var i = 1; i < references.length; i++)
		{
			point = new GLatLng(references[i][0], references[i][1]);
			bounds.extend(new GLatLng(references[i][0], references[i][1]));
//			marker = createTabbedInfoMarker(point, '<div style="width:250px; border:1px solid #ccc; padding:10px; margin-bottom:10px;"><p>Find den nærmeste forhandler af bygningsisolering i dit område<\/p><form action="\/rockwool\/?key=1&amp;kid=1&amp;land=Denmark&amp;locale=da&amp;css=http:\/\/rwi-wordpress.webhotel.net\/rockwool\/css\/clean_layout.css" method="post" target="_self"> Din adresse:<br \/> <input type="text" name="bruger_adresse" value="" size="35" class="googleInput" \/> <br \/>Postnummer:<br \/><input type="text" name="postnr" value="" size="35" class="googleInput" \/><br \/><br \/><input type="submit" name="" value="Send" class="submit" \/> <input type="hidden" name="action" value="find_forhandler" \/> <\/form><\/div>', 'Afstand');
			marker = createTabbedMarker(point, '<div style="overflow: hidden; clear: both; width: 200px; min-height: 65px;"><p style="font-size: 90%; line-height: 110%;"><a href="?nodeId=' + references[i][9] + '"><img width="50%" height="50%" style="margin-right: 8px; float: left; margin-bottom: 6px;" src="' + references[i][3] + '" alt="" /></a>' + references[i][4] + '<br /></p></div>', '<div style="width: 200px; overflow: hidden; clear: both;"><p style="font-size: 90%; line-height: 110%;">' + references[i][6] + '<br />' + references[i][7] + references[i][8] + '<br /></p></div>', '', references[i][2], references[i][5]);
			map.addOverlay(marker);
		}

		// Position map at centre of bounds and set zoom to include include them all
		map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

//		map.setCenter(new GLatLng(55.6527980332, 9.4482421875), 5);

	}

}

loadmap();

