// William Soutar Central Perth Walk
function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(56.395447, -3.427803), 15);
    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.392968;  // Soutar's Menagerie
    lat[1] = 56.395070;  // Wildfowl Sculpture
    lat[2] = 56.393397;  // Greyfriars Burial Ground
    lat[3] = 56.394527;  // Ropemaker's Close
    lat[4] = 56.395800;  // St John's Kirk
    lat[5] = 56.396661;  // Nae Day Sae Dark Sculpture
    lat[6] = 56.397697;  // Curfew Row
    lat[7] = 56.398290;  // Fair Maid's House
    lat[8] = 56.400208;  // Rose Terrace
    lat[9] = 56.399601;  // North Inch
    lat[10] = 56.399185;  // Perth Bridge
    lat[11] = 56.393750;  // Kinnoull Churchyard
    lat[12] = 56.391631;  // Railway Bridge
    lat[13] = 56.392089;  // Fergusson Gallery
    var lon = new Array();
    lon[0] = -3.425900;
    lon[1] = -3.425590;
    lon[2] = -3.427000;
    lon[3] = -3.430236;
    lon[4] = -3.428000;
    lon[5] = -3.429952;
    lon[6] = -3.430561;
    lon[7] = -3.429952;
    lon[8] = -3.432300;
    lon[9] = -3.429256;
    lon[10] = -3.424500;
    lon[11] = -3.422225;
    lon[12] = -3.423579;
    lon[13] = -3.426835;
    // Set up the information box array for each marker point
    var info = new Array();
    info[0] = "<p class=\"b\">Soutar's Menagerie<br /><img src=\"walks\/menagerie.png\"><br />Poem: <a href=\"poems\/aince.html\" target=\"_blank\">Aince Upon a Day</a></p>"; 
    info[1] = "<p class=\"b\">Golden Eye on the Dark and Singing Tide<br /><img src=\"walks\/wildfowl.png\"><br />Poem: <a href=\"poems\/river.html\" target=\"_blank\">The River</a></p>"; 
    info[2] = "<p class=\"b\">Greyfriars Burial Ground<br /><img src=\"walks\/greyfriars.png\"><br />Poem: <a href=\"poems\/epit.html\" target=\"_blank\">Epitaph for a Dead Self</a></p>"; 
    info[3] = "<p class=\"b\">Ropemaker's Close<br /><img src=\"walks\/ropemakers.png\"><br />Poem: <a href=\"poems\/back.html\" target=\"_blank\">Backlands</a></p>"; 
    info[4] = "<p class=\"b\">St John's Kirk<br /><img src=\"walks\/stjohnskirk.png\"><br />Poem: <a href=\"poems\/knox.html\" target=\"_blank\">John Knox</a></p>";  
    info[5] = "<p class=\"b\">Nae Day Sae Dark<br /><img src=\"walks\/naeday.png\"><br />Poems: <a href=\"poems\/naeday.html\" target=\"_blank\">Nae Day Sae Dark</a>&nbsp;<a href=\"poems\/thrang.html\" target=\"_blank\">Thrang and Thrivin</a></p>"; 
    info[6] = "<p class=\"b\">Curfew Row<br /><img src=\"walks\/curfewrow.png\"><br />Poem: <a href=\"poems\/house.html\" target=\"_blank\">The Auld House</a></p>"; 
    info[7] = "<p class=\"b\">Fair Maid's House<br /><img src=\"walks\/fairmaidshouse.png\"><br />Poem: <a href=\"poems\/tryst.html\" target=\"_blank\">The Tryst</a></p>"; 
    info[8] = "<p class=\"b\">Rose Terrace<br /><img src=\"walks\/roseterrace.png\"><br />Poem: no link.</p>"; 
    info[9] = "<p class=\"b\">North Inch<br /><img src=\"walks\/northinch.png\"><br />Poem: <a href=\"poems\/hal.html\" target=\"_blank\">Hal o\' the Wynd</a></p>"; 
    info[10] = "<p class=\"b\">Perth Bridge<br /><img src=\"walks\/perthbridge.png\"><br />Poems: <a href=\"poems\/brig.html\" target=\"_blank\">The Auld Brig</a>&nbsp;<a href=\"poems\/man.html\" target=\"_blank\">The Auld Man</a></p>";
    info[11] = "<p class=\"b\">Kinnoull Churchyard<br /><img src=\"walks\/kirkyaird.png\"><br />Poem: <a href=\"poems\/kirk.html\" target=\"_blank\">The Kirk-Yaird</a></p>"
    info[12] = "<p class=\"b\">Railway Bridge<br /><img src=\"walks\/railwaybridge.png\"><br />Poem: no link.</p>"
    info[13] = "<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.392089, -3.426035),  // Tay Street (1)
      new GLatLng(56.392968, -3.425900),  // Soutar's Menagerie
      new GLatLng(56.394168, -3.425590),  // Tay Street (2)
      new GLatLng(56.395070, -3.425590),  // Wildfowl Sculpture
      new GLatLng(56.395070, -3.426800),  // South Street/Speygate
      new GLatLng(56.393397, -3.427000),  // Greyfriars Burial Ground
      new GLatLng(56.394250, -3.427000),  // Canal Street (1)
      new GLatLng(56.394300, -3.430150),  // Canal Street (2)
      new GLatLng(56.395700, -3.429952),  // Ropemaker's Close
      new GLatLng(56.395700, -3.428775),  // King Edward Street
      new GLatLng(56.396000, -3.428775),  // St John's Place (1)
      new GLatLng(56.396000, -3.429952),  // St John's Place (2)
      new GLatLng(56.396661, -3.429952),  // Nae Day Sae Dark Sculpture/High Street
      new GLatLng(56.397490, -3.429952),  // Guard Vennel/Mill Street
      new GLatLng(56.397697, -3.430561),  // Curfew Row
      new GLatLng(56.398290, -3.429952),  // Fair Maid's House
      new GLatLng(56.398390, -3.429552),  // North Port
      new GLatLng(56.398875, -3.429016),  // Charlotte Street (1)
      new GLatLng(56.399475, -3.431500),  // Charlotte Street (2)
      new GLatLng(56.400208, -3.432300),  // Rose Terrace
      new GLatLng(56.399601, -3.429256),  // North Inch
      new GLatLng(56.398975, -3.429056),  // Charlotte Street (3)
      new GLatLng(56.398625, -3.427650),  // Charlotte Street (4)
      new GLatLng(56.399185, -3.424500),  // Perth Bridge
      new GLatLng(56.399325, -3.423275),  // Commercial Street (1)
      new GLatLng(56.398395, -3.422750),  // Commercial Street (2)
      new GLatLng(56.397495, -3.422550),  // Riverside Walk (1)
      new GLatLng(56.395895, -3.423000),  // Riverside Walk (2)
      new GLatLng(56.395100, -3.423590),  // Riverside Walk (3)
      new GLatLng(56.394000, -3.422925),  // Riverside Walk (4)
      new GLatLng(56.393750, -3.422225),  // Kinnoull Churchyard
      new GLatLng(56.393350, -3.422725),  // Riverside Walk (5)
      new GLatLng(56.391231, -3.421050),  // Riverside Walk (6)
      new GLatLng(56.390350, -3.421425),  // Riverside Walk (7)
      new GLatLng(56.390800, -3.421975),  // Riverside Walk (8)
      new GLatLng(56.391631, -3.423579),  // Railway Bridge
      new GLatLng(56.392450, -3.425950)   // Tay Street (1)
      ], "#3d001c", 3, 0.75);
    map.addOverlay(polyline);
  }
}
