var mapIcon
var map
var bounds
//Load the map into the DIV provided
function MapLoad(){
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(42.931761862112516,1.0546875), 1);
		bounds = new GLatLngBounds();
		var largeMapControl = new GLargeMapControl();
		var largeMapControlPosition = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
		map.addControl(largeMapControl, largeMapControlPosition);
        
		var largeMapTypeControl = new GMapTypeControl();
		var largeMapTypeControlPosition = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10));
		
		map.addControl(largeMapTypeControl, largeMapTypeControlPosition);
	}
}

function AddNewPoint(lat,long,team_id,team_name,team_slug,team_username){
	// Create an icon for the team and add it to the map
	mapIcon = new GIcon();
	mapIcon.image = "/images/team_logos/" + team_id + ".png"
	mapIcon.shadow = "";
	mapIcon.iconSize = new GSize(32, 32);
	mapIcon.shadowSize = new GSize(0, 0);
	mapIcon.iconAnchor = new GPoint(16, 16);
	mapIcon.infoWindowAnchor = new GPoint(30, 2);
	markerOptions = {icon:mapIcon};
    var marker = new GMarker(new GLatLng(lat,long), markerOptions);
	
	//Add and event listener
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml("<div class=\"mapWindow\"><a href=\"/"+team_slug+"\"><img src=\"/images/team_logos/" + team_id + ".png\" alt=\""+team_name+" logo\" /></a><div class=\"title\">" + team_name + "</div><div class=\"description\">For more information on " + team_name + " visit the teams area.</div><div class=\"link\">[<a href=\"/"+team_slug+"\">" + team_name + " area</a>]</div></div>");});

	map.addOverlay(marker);
	bounds.extend(marker.getPoint());
	map.setZoom(map.getBoundsZoomLevel(bounds))+1;
	map.setCenter(bounds.getCenter());
}


function AddKML(url){
	var geoXml = new GGeoXml(url);
    map.addOverlay(geoXml);
	bounds = new GLatLngBounds();
	map.setZoom(5);
	map.setCenter(bounds.getCenter());
}

function SetMapCenter(x,y,z){
	map.setCenter(new GLatLng(y,x), z);	
}