// William Soutar Craigie Walk
function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(56.386597, -3.441955), 14);
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    // Create a base icon for all the custom markers
    var baseIcon = new GIcon();
    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);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);
    // Set up the latitude and longitude arrays for each marker point
    var lat = new Array();
    lat[0] = 56.389635;  // South Inch
    lat[1] = 56.386935;  // South Inch Terrace
    lat[2] = 56.386097;  // Craigie Waterfall
    lat[3] = 56.383632;  // Craigie Knowes
    lat[4] = 56.381400;  // Craigie Hill
    lat[5] = 56.384591;  // Buckie Braes
    lat[6] = 56.388400;  // Soutar House
    lat[7] = 56.392089;  // Fergusson Gallery
    var lon = new Array();
    lon[0] = -3.430500;
    lon[1] = -3.432700;
    lon[2] = -3.441755;
    lon[3] = -3.444004;
    lon[4] = -3.448346;
    lon[5] = -3.457346;
    lon[6] = -3.443066;
    lon[7] = -3.426835;
    // Set up the information box array for each marker point
    var info = new Array();
    info[0] = "<p class=\"b\">South Inch<br /><img src=\"walks\/southinch.png\"><br />Poem: <a href=\"poems\/visit.html\" target=\"_blank\">The Visitation</a></p>"; 
    info[1] = "<p class=\"b\">South Inch Terrace<br /><img src=\"walks\/southinchterrace.png\"><br />Poem: <a href=\"poems\/cradle.html\" target=\"_blank\">Cradle Sang</a></p>"; 
    info[2] = "<p class=\"b\">Craigie Waterfall<br /><img src=\"walks\/waterfall.png\"><br />Poem: <a href=\"poems\/water.html\" target=\"_blank\">The Waterfall</a></p>"; 
    info[3] = "<p class=\"b\">Craigie Knowes<br /><img src=\"walks\/craigieknowes.png\"><br />Poems: <a href=\"poems\/knowes.html\" target=\"_blank\">Craigie Knowes</a>&nbsp;<a href=\"poems\/toun.html\" target=\"_blank\">Yon Toun</a></p>"; 
    info[4] = "<p class=\"b\">Craigie Hill<br /><img src=\"walks\/craigiehill.png\"><br />Poem: <a href=\"poems\/patriot.html\" target=\"_blank\">Patriotism</a></p>";  
    info[5] = "<p class=\"b\">Buckie Braes<br /><img src=\"walks\/buckiebraes.png\"><br />Poem: <a href=\"poems\/buckie.html\" target=\"_blank\">Buckie Braes</a></p>"; 
    info[6] = "<p class=\"b\">Soutar House<br /><img src=\"walks\/soutarhouse.png\"><br />Poem: <a href=\"poems\/auto.html\" target=\"_blank\">Autobiography</a></p></p>";
    info[7] = "<p class=\"b\">Fergusson Gallery<br /><img src=\"walks\/fergusson.png\"><br />Poem: <a href=\"poems\/ballad.html\" target=\"_blank\">Ballad</a></p>"; 
    // Function to create the custom marker points and information boxes
    function createMarker(index) {
      var letter = String.fromCharCode("A".charCodeAt(0) + index);
      var letteredIcon = new GIcon(baseIcon);
      letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
      var point = new GLatLng(lat[index], lon[index]);
      markerOptions = { icon:letteredIcon };
      var marker = new GMarker(point, markerOptions);
      map.addOverlay(marker);
      GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(info[index]);
      });
      return marker;
    }
    // Run the function as many times as we have markers
    for (var i = 0; i < lat.length; i++) {
      map.addOverlay(createMarker(i));
    }
    // Draw the route of the walk
    var polyline = new GPolyline([
      new GLatLng(56.392089, -3.426835),  // Fergusson Gallery
      new GLatLng(56.392050, -3.426835),  // Marshall Place
      new GLatLng(56.392050, -3.428835),  // South Inch
      new GLatLng(56.386935, -3.432700),  // South Inch Terrace
      new GLatLng(56.388185, -3.436000),  // Craigie Burn Path
      new GLatLng(56.387040, -3.439500),  // Glenearn Road
      new GLatLng(56.386650, -3.441755),  // Windsor Terrace
      new GLatLng(56.386097, -3.441355),  // Windsor Terrace Steps
      new GLatLng(56.385897, -3.441655),  // Craigie Waterfall
      new GLatLng(56.384540, -3.440900),  // Moncrieffe Terrace
      new GLatLng(56.384380, -3.442900),  // Moredun Terrace
      new GLatLng(56.383950, -3.442900),  // Verena Terrace (1)
      new GLatLng(56.383580, -3.442400),  // Verena Terrace (2)
      new GLatLng(56.383280, -3.442625),  // Verena Terrace (3)
      new GLatLng(56.383632, -3.444004),  // Craigie Knowes
      new GLatLng(56.383200, -3.442700),  // Verena Terrace (4)
      new GLatLng(56.382340, -3.443495),  // Quarry Road
      new GLatLng(56.382400, -3.444540),  // Glenlochay Road (N)
      new GLatLng(56.380770, -3.444480),  // Glenlochay Road (S)  
      new GLatLng(56.380265, -3.445000),  // Craigie Hill Path (1)
      new GLatLng(56.380070, -3.445800),  // Craigie Hill Path (2)
      new GLatLng(56.380150, -3.447600),  // Craigie Hill Path (3)
      new GLatLng(56.380175, -3.450350),  // Craigie Hill Path (4)
      new GLatLng(56.380050, -3.452750),  // Craigie Hill Path (5)
      new GLatLng(56.381325, -3.457250),  // Craigie Hill Path (6)
      new GLatLng(56.383191, -3.457346),  // Buckie Braes Path (1)
      new GLatLng(56.383891, -3.459046),  // Buckie Braes Path (2)
      new GLatLng(56.386100, -3.457950),  // Buckie Braes Path (3)
      new GLatLng(56.386750, -3.457050),  // Buckie Braes Path (4)
      new GLatLng(56.387000, -3.451825),  // Woodside Crescent
      new GLatLng(56.388050, -3.451350),  // Orchard Place
      new GLatLng(56.388800, -3.449000),  // Murray Crescent
      new GLatLng(56.389650, -3.449950),  // Needless Road (W)
      new GLatLng(56.390100, -3.446900),  // Needless Road (E)
      new GLatLng(56.390550, -3.445450),  // Wilson Street (N)
      new GLatLng(56.388400, -3.443066),  // Soutar House
      new GLatLng(56.388000, -3.442550),  // Wilson Street (S)
      new GLatLng(56.387300, -3.442120),  // Queen Street (W)
      new GLatLng(56.387700, -3.439880),  // Queen Street (E)
      new GLatLng(56.387040, -3.439500),  // Glenearn Road
      new GLatLng(56.388185, -3.436000),  // Craigie Burn Path
      new GLatLng(56.392050, -3.428835)   // Marshall Place
      ], "#3d001c", 3, 0.75);
      map.addOverlay(polyline);
  }
}
