// JavaScript Document launches google map - BrightonMap.js

    //<![CDATA[

    if (GBrowserIsCompatible()) {
      var gmarkers = [];
      var gicons = [];

// can add your own pins by adding gicons["golf"] = new GIcon(G_DEFAULT_ICON,"filename.png"); //
// standard google chart pins added to the end letter to show, back color, fore color "http://www.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000" //
      gicons["greatpints"] = new GIcon(G_DEFAULT_ICON,"../images/contentImages/mapPinA.png");
      gicons["cheapeats"] = new GIcon(G_DEFAULT_ICON,"../images/contentImages/mapPinB.png");
      gicons["poshmeals"] = new GIcon(G_DEFAULT_ICON,"../images/contentImages/mapPinC.png");
	  gicons["citysurprises"] = new GIcon(G_DEFAULT_ICON,"../images/contentImages/mapPinD.png");

      // A function to create the marker and set up the event window
      function createMarker(point,name,html,category) {
        var marker = new GMarker(point,gicons[category]);
        // === Store the category and name info as a marker properties ===
        marker.mycategory = category;                                 
        marker.myname = name;
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        gmarkers.push(marker);
        return marker;
      }

      // == shows all markers of a particular category, and ensures the checkbox is checked ==
      function show(category) {
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mycategory == category) {
            gmarkers[i].show();
          }
        }
        // == check the checkbox ==
        document.getElementById(category+"box").checked = true;
      }

      // == hides all markers of a particular category, and ensures the checkbox is cleared ==
      function hide(category) {
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mycategory == category) {
            gmarkers[i].hide();
          }
        }
        // == clear the checkbox ==
        document.getElementById(category+"box").checked = false;
        // == close the info window, in case its open on a marker that we just hid
        map.closeInfoWindow();
      }

      // == a checkbox has been clicked ==
      function boxclick(box,category) {
        if (box.checked) {
          show(category);
        } else {
          hide(category);
        }
        // == rebuild the side bar
        makeSidebar();
      }

      function myclick(i) {
        GEvent.trigger(gmarkers[i],"click");
      }


      // == rebuilds the sidebar to match the markers currently displayed ==
      function makeSidebar() {
		var html = "";
        for (var i=0; i<gmarkers.length; i++) {
          if (!gmarkers[i].isHidden()) {
            html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>';
          }
        }
        document.getElementById("side_bar").innerHTML = html;
      }


      // create the map
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
     
// added latitude and longitude found from http://www.tomanthony.co.uk/demo/geocode_uk_postcode/ //
		// last figure after brackets is scale //
      map.setCenter(new GLatLng(50.826378, -0.148401), 13);

      // Read the data
      GDownloadUrl("../living/brightonmapdata.xml", function(doc) {
        var xmlDoc = GXml.parse(doc);
        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 address = markers[i].getAttribute("address");
          var name = markers[i].getAttribute("name");
          var html = "<b class='mapInfotitle'>"+name+"<\/b><p class='mapInfo'>"+address;
          var category = markers[i].getAttribute("category");
          // create the marker
          var marker = createMarker(point,name,html,category);
          map.addOverlay(marker);
        }

        // == show or hide the categories initially ==
        show("greatpints");
        hide("cheapeats");
		hide("poshmeals");
        hide("citysurprises");
		
        // == create the initial sidebar ==
        makeSidebar();
      });
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
    //]]>