//<![CDATA[

if (GBrowserIsCompatible()) {
  var side_bar_html = "";
  var gmarkers = [];
  var htmls = [];
  var i = 0;
  
  // Create some custom icons
  
  // This icon uses the same shape as the default Google marker
  // So we can use its details for everything except the image 
  var IVCicon = new GIcon();
  IVCicon.image = "../images/icon-map-normal.png";
  IVCicon.shadow = "../images/icon-map-shadow.png";
  IVCicon.iconSize = new GSize(60, 60);
  IVCicon.shadowSize = new GSize(60, 60);
  IVCicon.iconAnchor = new GPoint(30, 30);
  IVCicon.infoWindowAnchor = new GPoint(30, 15);
  IVCicon.infoShadowAnchor = new GPoint(60, 60);
	
  // An array of GIcons, to make the selection easier
  var icons = [];
  icons[0] = IVCicon;

  // the icon information is passed to this function
  function createMarker(point,name,html,icontype) {
	var marker = new GMarker(point,icons[icontype]);
	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(html);
	});
	// save the info we need to use later for the side_bar
	gmarkers[i] = marker;
	htmls[i] = html;
	// add a line to the side_bar html
	side_bar_html += '<a href="javascript:myclick(' + i + ')">Please click here to view the ' + name + ' office</a><br>';
	i++;
	return marker;
  }

  function myclick(i) {
	gmarkers[i].openInfoWindowHtml(htmls[i]);
  }

  var map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(51.806863,-1.859766),7);

  var request = GXmlHttp.create();
  request.open("GET", "../custom.xml", true);
  request.onreadystatechange = function() {
	if (request.readyState == 4) {
	  var xmlDoc = GXml.parse(request.responseText);
	  // obtain the array of markers and loop through it
	  var markers = xmlDoc.documentElement.getElementsByTagName("marker");
	  
	  for (var i = 0; i < markers.length; i++) {
		// obtain the attribues of each marker
		var lat = parseFloat(markers[i].getAttribute("lat"));
		var lng = parseFloat(markers[i].getAttribute("lng"));
		var point = new GLatLng(lat,lng);
		var html = markers[i].getAttribute("html");
		var label = markers[i].getAttribute("label");
		var icontype = parseInt(markers[i].getAttribute("icontype"));
		// create the marker
		var marker = createMarker(point,label,html,icontype);
		map.addOverlay(marker);
	  }
	  // put the assembled side_bar_html contents into the side_bar div
	  document.getElementById("map-sidebar").innerHTML = side_bar_html;
	}
  }
  request.send(null);
}

else {
  alert("Sorry, the Google Maps API is not compatible with this browser");
}
// This Javascript is based on code provided by the
// Blackpool Community Church Javascript Team
// http://www.commchurch.freeserve.co.uk/   
// http://econym.googlepages.com/index.htm

//]]>