var numberOfLocations = 5  //Ensure this is updated to include the number of elements in the array

// Note: IE and Firefox give different values for the length property of this array (IE is one higher)
// hence the need to use this variable

var mapLocations = [

    { "markerCode":"A",
		  "name":"Weston Church",
		  "locationLat":51.90645,
			"locationLong":-2.53746,
      "path":"images/dummy.jpg",
			"imageWidth":125,
			"imageHeight":125},
				
    { "markerCode":"B",
		  "name":"Hope Mansell Church",
		  "locationLat":51.87415,
			"locationLong":-2.54553,
      "path":"images/dummy.jpg",
			"imageWidth":125,
			"imageHeight":125},
					
    { "markerCode":"C",
		  "name":"Weston Village Hall",
		  "locationLat":51.90485,
			"locationLong":-2.53457,
      "path":"images/dummy.jpg",
			"imageWidth":125,
			"imageHeight":125},
				
    { "markerCode":"D",
		  "name":"Hope Mansell Village Hall",
		  "locationLat":51.87520,
			"locationLong":-2.54354,
      "path":"images/dummy.jpg",
			"imageWidth":125,
			"imageHeight":125},
			
		{ "markerCode":"E",
		  "name":"Weston Cross Public House",
		  "locationLat":51.90793,
			"locationLong":-2.53886,
      "path":"images/dummy.jpg",
			"imageWidth":125,
			"imageHeight":125},  

];

		
function loadMap() {
      
    var map = new GMap2(document.getElementById("map_canvas"));
				
	  // set center co-ordinates
    map.setCenter(new GLatLng(51.895,-2.5352), 13);	
		
		//set map type
		map.setMapType(G_HYBRID_MAP);
			
	  // include zoom and movement capability
	  map.addControl(new GLargeMapControl());
				
	     // include satellite and hybrid options
    map.addControl(new GMapTypeControl());
      
			//******inserted adapted code from Google example
			
    // Create a base icon for all of our markers that specifies the
    // shadow, icon dimensions, etc.
    var baseIcon = new GIcon(G_DEFAULT_ICON);
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(20, 34);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);

    // Creates a marker whose info window displays the letter corresponding
    // to the given index.
    function createMarker(markerId, point, index, locationName) {
       // Create a lettered icon for this point using our icon class
       var letteredIcon = new GIcon(baseIcon);
       letteredIcon.image = "http://www.google.com/mapfiles/marker" + markerId + ".png";

       // Set up our GMarkerOptions object
       markerOptions = { icon:letteredIcon };
       var marker = new GMarker(point, markerOptions);

       GEvent.addListener(marker, "click", function() {map.panTo(point);
          map.setZoom(15); marker.openInfoWindowHtml(locationName);
       });
       return marker;
    }

    // Add markers to the map at the specified locations
    
    for (var i = 0; i < numberOfLocations; i++) {
        var point = new GLatLng(mapLocations[i]["locationLat"], mapLocations[i]["locationLong"]);
        map.addOverlay(createMarker(mapLocations[i]["markerCode"], point, i, mapLocations[i]["name"]));
    }
			
		//**************end insert
		   
		//*************************************************	
	  // make map instructions visible (CGC logic, not Google)
	  var msgNode=document.getElementById("mapinstructions");
	  msgNode.style.visibility = "visible";
		msgNode=document.getElementById("locationtable");
	  msgNode.style.visibility = "visible";
}
// emd of function loadMap
		
function setPosition(locationIndex)  {

    var map = new GMap2(document.getElementById("map_canvas"));
       	
	  var point = new GLatLng(mapLocations[locationIndex]["locationLat"], mapLocations[locationIndex]["locationLong"]);
			 
		map.setCenter(point,14);
			 
		// include zoom and movement capability
	  map.addControl(new GLargeMapControl());
				
	  // include satellite and hybrid options
	  var mapControl = new GMapTypeControl();
    map.addControl(mapControl);
			 
	  map.openInfoWindowHtml(point,mapLocations[locationIndex]["name"]);
		
}
// end of function setPosition	
