function createBaseIcon(shadowPath)
{
	//Create a base icon
	var baseIcon = new GIcon();
	baseIcon.shadow = shadowPath;
	baseIcon.iconSize = new GSize(34, 40);
	baseIcon.shadowSize = new GSize(49, 44);
	baseIcon.iconAnchor = new GPoint(17, 42);
	baseIcon.infoWindowAnchor = new GPoint(17, 40);
	baseIcon.infoShadowAnchor = new GPoint(18, 39);
	return baseIcon;
}

function createIcon(baseIcon, iconPath)
{
	// Create a new marker icon
	var icon = new GIcon(baseIcon);
	icon.image = iconPath;
	return icon;
}

function createMarker(point, baseIcon, iconPath, infoText) 
{
	//Create a marker for mapped points
	var icon = createIcon(baseIcon, iconPath);
	var marker = new GMarker(point, icon);
	
	//Add an event listener
    GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(infoText);});
    return marker;
}

//Add markers based on the xml file
function createLocationsMapSingleMarker(lat, lng, zoomLevel, icon, infoText) 
{
	if (GBrowserIsCompatible()) 
	{
		//Create the map with the controls we want
		var map = new GMap2(document.getElementById("DetailLocationMap_map"));
		map.addControl(new GSmallMapControl());
		
		//Centre the map on the current location
        map.setCenter(new GLatLng(lat, lng), zoomLevel);
		
		//Create the icon
		var baseIcon = createBaseIcon("/images/global/maps/shadow.png");
		var iconPath = "/images/global/maps/" + icon + ".png";
		
		//Now add a marker to the map for this location
        var point = new GLatLng(lat, lng);
		var marker = createMarker(point, baseIcon, iconPath, infoText);
		map.addOverlay(marker);		
		
        //Open the info window that relates to the current item
		marker.openInfoWindowHtml(infoText);
        
	}
	else
	{

		//Do something different as their browser doesnt support google maps
		//TODO
            
	}

}

function createLocationsMapFromXml(centreLat, centreLng, zoomLevel, xmlFileName)
{
	if (GBrowserIsCompatible()) 
	{
		//Create the map with the controls we want
		var map = new GMap2(document.getElementById("DetailLocationMap_map"));
		map.addControl(new GSmallMapControl());
			
		//Create the base icon
		var baseIcon = createBaseIcon("/images/global/maps/shadow.png");
			
		//Centre the map on the current location
		map.setCenter(new GLatLng(centreLat, centreLng), zoomLevel);
	        
		//Create pointers for the map from the xml file
		GDownloadUrl(xmlFileName, function(data, responseCode) 
		{
			//Parse the xml file
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) 
			{
				//Add a new marker for each element
				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
										parseFloat(markers[i].getAttribute("lng")));
				var iconPath = "/images/global/maps/" + markers[i].getAttribute("icon") + ".png";
				var infoText = markers[i].getAttribute("info");
				var detailedInfoText = GXml.value(markers[i].getElementsByTagName("infowindow")[0]);
				if (detailedInfoText!="")
				{
					infoText=detailedInfoText;
				}
				var marker = createMarker(point, baseIcon, iconPath, infoText);
				map.addOverlay(marker);	
			}
		});
	}
	else
	{

		//Do something different as their browser doesnt support google maps
		//TODO
            
	}
}