function fLoadMapData(sURL,jMap,sIdentifier) {
	// note that jMap is a jQuery object
	// to get to the DOM object use jMap[0] - this is OK because only one will be passed in
	function fCreateItems(oXML) {

    function gInitialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(jMap[0]);
        map.setCenter(new GLatLng(52.4,-3.5), 7);
        map.setUIToDefault();
      }
      return map;
    }
		
		
		function fXMLtoArray(oXML,sItems) {
			// load all the XML into an array
			var aItems=new Array();
			var sItem=''; // a test string
			
			// for all the items
			$(oXML).find(sItems).each(function() {
				var aItem=new Array();
				
				// push on an array of all the children (assuming they're a text node)
				$(this).children().each(function() {
					aItem[this.nodeName]=$(this).text();
					sItem+=(this.nodeName+'='+$(this).text()+'\n');
				});
				aItems.push(aItem);
				sItem+='\n\n';
			});		
			
			return aItems;	
		}
		
		var aItems=new Array();
		aItems=fXMLtoArray(oXML,sIdentifier);
		
		var oMap=gInitialize();
    for(var i=0;i<aItems.length; i++) {
	    try {
    	  var aLatLong=aItems[i]['latlong'].split(',');
	    	var latlng = new GLatLng(aLatLong[0],aLatLong[1]);
	    	var oMarker=new GMarker(latlng);
	    	oMap.addOverlay(oMarker);
	    	var sHTML='<h1>'+aItems[i]['name']+'</h1>'+aItems[i]['addr1']+'<br />'+aItems[i]['addr2']+'<br />'+aItems[i]['postcode'];
	    	oMarker.bindInfoWindowHtml(sHTML);
	    } catch(e) {
	    	// do nothing - this is probably some data missing in the XML file
	    }
	  } 
    //jMap.hide();
		//jMap[0].map=oMap;
	}
	
	function fLoadError(oXMLHttpRequest, sTextStatus, oErrorThrown) {
		alert('an error has occurred '+sTextStatus);
	}
	
	var oReq=$.ajax({url: sURL, cache: false, success: fCreateItems, dataType: 'xml', timeout:5000, error:fLoadError});
}

function fCreatePubsMap(bSuccess, oPopup, sType) {
	fLoadMapData('../geodata-pubs.xml',$(oPopup.content),'pub');	
}

function fCreateButchersMap(bSuccess, oPopup, sType) {
	fLoadMapData('../geodata-butchers.xml',$(oPopup.content),'butcher');	
}
