	var map;
	var controlButton;
	var mainmap;
	var flag = new Array();
 	var marker_pin = new Array();
 	flag = [0,0,0,0,0,0];
	
        var baseIcon = new GIcon();
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";

        var icon = new GIcon(baseIcon);		
		var pins = new Array();
		pins = ["0","http://img126.imageshack.us/img126/4350/iconr1lc7.png","http://img162.imageshack.us/img162/456/iconr2lh1.png","http://img162.imageshack.us/img162/656/iconr3wg8.png","http://img162.imageshack.us/img162/2631/iconr4hz7.png","http://img162.imageshack.us/img162/9528/iconr5jk4.png","http://img162.imageshack.us/img162/8963/iconr6th9.png","http://img162.imageshack.us/img162/5116/iconr7hc0.png","http://img162.imageshack.us/img162/108/iconr8cr9.png","http://img162.imageshack.us/img162/8697/iconr9kx2.png","http://img162.imageshack.us/img162/8974/iconr10nb9.png","http://img118.imageshack.us/img118/4292/iconr11ps5.png","http://img118.imageshack.us/img118/7448/iconr12sj6.png","http://img118.imageshack.us/img118/809/iconr13an2.png","http://img118.imageshack.us/img118/999/iconr14tj6.png","http://img118.imageshack.us/img118/4080/iconr15ek3.png","http://img118.imageshack.us/img118/3889/iconr16pv0.png","http://img118.imageshack.us/img118/9210/iconr17bg5.png","http://img382.imageshack.us/img382/4864/iconr18pr7.png","http://img382.imageshack.us/img382/361/iconr19fe0.png","http://img382.imageshack.us/img382/8717/iconr20lt0.png"];
		
	function ZoomOutControl() {}
	ZoomOutControl.prototype = new GControl;
	ZoomOutControl.prototype.initialize = function(map) {
	  var button = this;
	  button = document.createElement("div");
	  button.style.width = "150px";
	  button.style.height = "17px";
	  button.style.border = "1px solid black";
	  button.style.background = "white";
	  button.style.cursor = "pointer";
	  button.style.color = "#000000";
	  button.style.font = "9pt Arial";
	  button.appendChild(document.createTextNode("Zoom Out to World Map"));
	  map.getContainer().appendChild(button);

	  GEvent.addDomListener(button, "click", function() {load_map();});
	  return button;
	};
	ZoomOutControl.prototype.getDefaultPosition = function() {return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(425, 7));};
	ZoomOutControl.prototype.getPanel = function() {return button;};


	function show_infowindow(i) {
          if(mainmap == 1) marker_pin[i].openInfoWindowHtml("<b class=a2>"+xml.documentElement.getElementsByTagName("name")[i].childNodes[0].nodeValue+"</b><br><b class=a4>"+xml.documentElement.getElementsByTagName("date")[i].childNodes[0].nodeValue+"</b><br><b class=a2>"+xml.documentElement.getElementsByTagName("circuit")[i].childNodes[0].nodeValue+"</b><br><input type='button' value='View Satellite Image' onclick=\"javascript: view_satellite_image("+i+");\"><br><br><b class=a2>Race Results:</b> <a class=a1 href=\""+xml.documentElement.getElementsByTagName("wikiurl")[i].childNodes[0].nodeValue+"\" target=\"_blank\">Wikipedia</a>, <a class=a1 href=\""+xml.documentElement.getElementsByTagName("f1url")[i].childNodes[0].nodeValue+"\" target=\"_blank\">F1.com</a>");

	}

	function view_satellite_image(i) {
		map.clearOverlays();
        map.setCenter(new GLatLng(eval(xml.documentElement.getElementsByTagName("lat")[i].childNodes[0].nodeValue), eval(xml.documentElement.getElementsByTagName("lng")[i].childNodes[0].nodeValue)), eval(xml.documentElement.getElementsByTagName("mapzoom")[i].childNodes[0].nodeValue));
        map.setMapType(G_SATELLITE_MAP);
		controlButton = new ZoomOutControl();
		map.addControl(controlButton);
		mainmap = 0;
		document.getElementById("heading").innerHTML = "<a class=\"a3\" href=\""+xml.documentElement.getElementsByTagName("wiki2")[i].childNodes[0].nodeValue+"\" target=\"_blank\">"+xml.documentElement.getElementsByTagName("circuit")[i].childNodes[0].nodeValue+"</a>, "+xml.documentElement.getElementsByTagName("country")[i].childNodes[0].nodeValue;
		document.getElementById("details").innerHTML = "<br><b><a class=\"a7\" href=\""+xml.documentElement.getElementsByTagName("wiki1")[i].childNodes[0].nodeValue+"\" target=\"_blank\">"+xml.documentElement.getElementsByTagName("name")[i].childNodes[0].nodeValue+"</a></b> - "+xml.documentElement.getElementsByTagName("year")[i].childNodes[0].nodeValue;
		document.getElementById("flags").innerHTML = "<IMG SRC=\""+xml.documentElement.getElementsByTagName("flag")[i].childNodes[0].nodeValue+"\" height=\"75\" width=\"125\" border=\"0\">"
    }

	function load_pin(i) {
		icon.image = pins[i];
		marker_pin[i] = new GMarker(new GLatLng(eval(xml.documentElement.getElementsByTagName("lat")[i].childNodes[0].nodeValue), eval(xml.documentElement.getElementsByTagName("lng")[i].childNodes[0].nodeValue)), icon);
		map.addOverlay(marker_pin[i]);
		GEvent.addListener(marker_pin[i], "click", function() {	view_satellite_image(i); });
		GEvent.addListener(marker_pin[i], "mouseover", function() {	show_infowindow(i); });
		if (i%2 == 0)
			gplist += '<tr style="cursor:pointer;background:#003366" onmouseover ="show_infowindow('+i+')" onclick="view_satellite_image('+i+')">';
		else
			gplist += '<tr style="cursor:pointer;background:#225588" onmouseover ="show_infowindow('+i+')" onclick="view_satellite_image('+i+')">';
		gplist += '<td width="30" height="20">&nbsp;'+i+'. </td><td width="140" class="a11">'+xml.documentElement.getElementsByTagName("date")[i].childNodes[0].nodeValue+'</td><td width="140" class="a11">'+xml.documentElement.getElementsByTagName("name")[i].childNodes[0].nodeValue+'</td></tr>';
	}
	
    function load_map() {
		map.setCenter(new GLatLng(37.4419, 12.1419), 2);
		map.setMapType(G_NORMAL_MAP);
		map.removeControl(controlButton);
		gplist = "";
		gplist += '<table cellpadding="0" cellspacing="0" border="0">';
		for (var i = 1; i < xml.documentElement.getElementsByTagName("gp").length; i++) load_pin(i);
		gplist += '</table>';
		document.getElementById("gplist").innerHTML = gplist;
		mainmap = 1;
		document.getElementById("heading").innerHTML = '<a class="a3" href="http://en.wikipedia.org/wiki/List_of_Formula_One_circuits" target="_blank">List of Formula One Circuits</a>';
		document.getElementById("details").innerHTML = '<a class="a7" href="http://en.wikipedia.org/wiki/History_of_Formula_One" target="_blank">History of Formula One</a>';
		document.getElementById("flags").innerHTML = '<IMG border="0" height="1" width="1">';
	}

	function init_map(f1xml) {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GMapTypeControl());
        map.addControl(new GLargeMapControl());
		map.addMapType(G_PHYSICAL_MAP);
		map.setCenter(new GLatLng(37.4419, 12.1419), 2);		
		map.enableGoogleBar(); 			
		GDownloadUrl(f1xml, function(data, responseCode) {
			xml = GXml.parse(data);
			load_map();
		});
	}
