function Maps ( c ) {
	this.c = c;

	this.printMaps = function (y) {
		document.write('<div id="map" style="height: '+y+'px;"></div>');
		this.loadMaps("x");
	}
	
	this.loadMaps = function (country) {
		var point = new GLatLng(56.0,10.83013);
		var zoomLevel = 6;
		
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map"));
			var geocoder = new GClientGeocoder();
			map.addControl(new GSmallMapControl());
			map.setCenter(point, zoomLevel, G_HYBRID_MAP);
			
			
			var randomnumber=Math.floor(Math.random()*11111);
			var icon = new GIcon();
			icon.image = "/images/mapPointer.png";
			icon.iconSize = new GSize(10, 10);
			icon.iconAnchor = new GPoint(0, 5);
			icon.infoWindowAnchor = new GPoint(5, 1);

			GDownloadUrl("/circuits.xml?random="+randomnumber, function(data, responseCode) {
				var xml = GXml.parse(data);
				if ( xml.documentElement ) {
					var markers = xml.documentElement.getElementsByTagName("marker");
					
					for (var i = 0; i < markers.length; i++) {
						var id = markers[i].getAttribute("id");
						/*var address = markers[i].getAttribute("address");
						var html = markers[i].getAttribute("html");*/
						var address = markers[i].childNodes[1].childNodes[0].nodeValue;
						if ( markers[i].childNodes[3] )
							var html = markers[i].childNodes[3].childNodes[0].nodeValue;
						else
							var html = '';
						var mpoint = new GLatLng(markers[i].getAttribute("x") , markers[i].getAttribute("y") );
						showAddress(id,map,geocoder,mpoint,address,html,icon);
					}
				}
			});
		}
	}
	
	this.createMarker = function (id,point,html,icon){
		var marker = new GMarker(point, icon);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml ( html );
		});
		GEvent.addListener(marker, "click", function() {
			m.getC().setCircuitFilter ( id );
		});
		return marker;
	}
	
	this.selectCountry = function (c){
		this.loadMaps ( c );
	}
	
	this.getC = function ( ) {
		if ( this.c != null )
			return this.c;
	}
}

function showAddress (id,map,geocoder,point,address,html,icon) {
	var marker = m.createMarker(id,point,'<p class="balloon"><strong>'+html+'</strong><br/>'+address+'</p>',icon);
	map.addOverlay(marker);
	map.addControl(new GMapTypeControl());
}
