    //<![CDATA[
    var rootDir = "./";
		var map;
    var directions;
    var geocoder;
    var iconHome = new GIcon();
    iconHome.image = 'http:\/\/labs.google.com/ridefinder/images/mm_20_yellow.png';
    iconHome.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconHome.iconSize = new GSize(12, 20);
    iconHome.shadowSize = new GSize(22, 20);
    iconHome.iconAnchor = new GPoint(6, 20);
    iconHome.infoWindowAnchor = new GPoint(5, 1);
    var iconRed = new GIcon();
    iconRed.image = rootDir + 'img/map/red.png';
    iconRed.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconRed.iconSize = new GSize(20, 34);
    iconRed.shadowSize = new GSize(34, 34);
    iconRed.iconAnchor = new GPoint(10, 34);
    iconRed.infoWindowAnchor = new GPoint(10, 33);
    var iconRedGreen = new GIcon();
    iconRedGreen.image = rootDir + 'img/map/red_green.png';
    iconRedGreen.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconRedGreen.iconSize = new GSize(20, 34);
    iconRedGreen.shadowSize = new GSize(34, 34);
    iconRedGreen.iconAnchor = new GPoint(10, 34);
    iconRedGreen.infoWindowAnchor = new GPoint(10, 33);
    var iconRedBlue = new GIcon();
    iconRedBlue.image = rootDir + 'img/map/red_blue.png';
    iconRedBlue.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconRedBlue.iconSize = new GSize(20, 34);
    iconRedBlue.shadowSize = new GSize(34, 34);
    iconRedBlue.iconAnchor = new GPoint(10, 34);
    iconRedBlue.infoWindowAnchor = new GPoint(10, 33);
    var iconGreenBlue = new GIcon();
    iconGreenBlue.image = rootDir + 'img/map/green_blue.png';
    iconGreenBlue.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconGreenBlue.iconSize = new GSize(20, 34);
    iconGreenBlue.shadowSize = new GSize(34, 34);
    iconGreenBlue.iconAnchor = new GPoint(10, 34);
    iconGreenBlue.infoWindowAnchor = new GPoint(10, 33);
    var iconRedGreenBlue = new GIcon();
    iconRedGreenBlue.image = rootDir + 'img/map/red_green_blue.png';
    iconRedGreenBlue.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconRedGreenBlue.iconSize = new GSize(20, 34);
    iconRedGreenBlue.shadowSize = new GSize(34, 34);
    iconRedGreenBlue.iconAnchor = new GPoint(10, 34);
    iconRedGreenBlue.infoWindowAnchor = new GPoint(10, 33);
    var iconGreen = new GIcon();
    iconGreen.image = rootDir + 'img/map/green.png';
    iconGreen.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconGreen.iconSize = new GSize(20, 34);
    iconGreen.shadowSize = new GSize(34, 34);
    iconGreen.iconAnchor = new GPoint(10, 34);
    iconGreen.infoWindowAnchor = new GPoint(10, 33);
    var iconYellow = new GIcon();
    iconYellow.image = rootDir + 'img/map/yellow.png';
    iconYellow.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconYellow.iconSize = new GSize(20, 34);
    iconYellow.shadowSize = new GSize(34, 34);
    iconYellow.iconAnchor = new GPoint(10, 34);
    iconYellow.infoWindowAnchor = new GPoint(10, 33);
    var iconBlue = new GIcon();
    iconBlue.image = rootDir + 'img/map/blue.png';
    iconBlue.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconBlue.iconSize = new GSize(20, 34);
    iconBlue.shadowSize = new GSize(34, 34);
    iconBlue.iconAnchor = new GPoint(10, 34);
    iconBlue.infoWindowAnchor = new GPoint(10, 33);
    var iconCyan = new GIcon();
    iconCyan.image = rootDir + 'img/map/cyan.png';
    iconCyan.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconCyan.iconSize = new GSize(20, 34);
    iconCyan.shadowSize = new GSize(34, 34);
    iconCyan.iconAnchor = new GPoint(10, 34);
    iconCyan.infoWindowAnchor = new GPoint(10, 33);
    var iconPurple = new GIcon();
    iconPurple.image = rootDir + 'img/map/purple.png';
    iconPurple.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconPurple.iconSize = new GSize(20, 34);
    iconPurple.shadowSize = new GSize(34, 34);
    iconPurple.iconAnchor = new GPoint(10, 34);
    iconPurple.infoWindowAnchor = new GPoint(10, 33);
    var iconSilver = new GIcon();
    iconSilver.image = rootDir + 'img/map/silver.png';
    iconSilver.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconSilver.iconSize = new GSize(20, 34);
    iconSilver.shadowSize = new GSize(34, 34);
    iconSilver.iconAnchor = new GPoint(10, 34);
    iconSilver.infoWindowAnchor = new GPoint(10, 33);
    var iconGold = new GIcon();
    iconGold.image = rootDir + 'img/map/gold.png';
    iconGold.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconGold.iconSize = new GSize(20, 34);
    iconGold.shadowSize = new GSize(34, 34);
    iconGold.iconAnchor = new GPoint(10, 34);
    iconGold.infoWindowAnchor = new GPoint(10, 33);
    var iconWhite = new GIcon();
    iconWhite.image = rootDir + 'img/map/white.png';
    iconWhite.shadow = 'http:\/\/labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconWhite.iconSize = new GSize(20, 34);
    iconWhite.shadowSize = new GSize(34, 34);
    iconWhite.iconAnchor = new GPoint(10, 34);
    iconWhite.infoWindowAnchor = new GPoint(10, 33);

    function load() {
      if (GBrowserIsCompatible()) {
        geocoder = new GClientGeocoder();
        map = new GMap2(document.getElementById('map'));
        map.addControl(new GSmallMapControl());
        //map.addMapType(G_PHYSICAL_MAP);
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(62, -100), 3);
        directionsPanel = document.getElementById("route");
        directions = new GDirections(map, directionsPanel);
      }
    }

  function searchLocations() {
    var address = document.getElementById('addressInput').value;
    if(address == "") { address = "Canada"; }
    geocoder.getLatLng(address, function(latlng) {
      if (!latlng) {
        var errorString = address;
        if(currentLang == "fr") {
          errorString += ' pas trouvé';
        } else {
          errorString += ' not found';
        }
        alert(errorString);
        //alert(address + ' not found');
      } else {
        hideDirections();
        searchLocationsNear(latlng, address);
      }
    });
  }

  function searchLocationsNear(center, yourAddress) {
    var dealers = document.getElementById('numberSelect').value;
    var special = document.getElementById('specialty').value;
//    if(yourAddress == "Canada" && special != "all") { dealers = 500; }
    var yourLat = center.lat();
    var yourLng  = center.lng();
    if(yourAddress == "ROBLIN, MB"          ) { yourLat = 51.227911111; yourLng = -101.35233333; }
    if(yourAddress == "CAMBRIDGE STN, NS"   ) { yourLat = 45.05241111;  yourLng =  -64.63969722; }
//    if(yourAddress == "SELKIRK, MB" ) { yourLat = 50.145130555; yourLng =  -96.872569444; }
    var searchUrl = rootDir + 'map_dealer_data.php?sid=' + Math.random() + '&lat=' + yourLat + '&lng=' + yourLng + '&limit=' + dealers + '&lang=' + currentLang+ '&special=' + special;
    GDownloadUrl(searchUrl, function(data) {
      var xml = GXml.parse(data);
      var markers = xml.documentElement.getElementsByTagName('marker');
      map.clearOverlays();

      var sidebar = document.getElementById('sidebar');
      sidebar.innerHTML = '';
      if (markers.length == 0)
        {
          sidebar.innerHTML = 'No results found.';
          map.setCenter(new GLatLng(62, -100), 3);
          return;
        }

      var bounds = new GLatLngBounds();
      for (var i = 0; i < markers.length; i++)
        {
          var name = unescape(markers[i].getAttribute('name'));
          if(name == "Your Address")
            { var address = yourAddress; }
           else
            {
              var address = unescape(markers[i].getAttribute('address'));
              address += '<br \/>' + unescape(markers[i].getAttribute('city'));
              address += ', ' + unescape(markers[i].getAttribute('prov'));
              address += ' ' + unescape(markers[i].getAttribute('postalcode'));
            }
          var dealerSpecialty = parseInt(markers[i].getAttribute('specialty'))
          var htmlStr = '<br \/>' + unescape(markers[i].getAttribute('html'));
          var distance = parseFloat(markers[i].getAttribute('distance'));
          var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
                                  parseFloat(markers[i].getAttribute('lng')));

          // create GDirection string
          var toAddress = name+'@'+point.lat()+','+point.lng();
          var marker = createMarker(point, name, address + htmlStr, toAddress, yourAddress, dealerSpecialty);
          map.addOverlay(marker);
          if(name != "Your Address")
            {
              var sidebarEntry = createSidebarEntry(marker, name, address, distance);
              sidebar.appendChild(sidebarEntry);
            }
          bounds.extend(point);
        }
      map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
     });
   }

    function createMarker(point, name, address, toAddress, fromAddress, dealerSpecialty)
      {
        if(name == "Your Address")
          {
            var marker = new GMarker(point, {title: address, icon: iconHome});
          }
         else
          {
            var dealerIcon  = iconWhite;
            if(dealerSpecialty == 1) { dealerIcon  = iconGreen;         }
            if(dealerSpecialty == 2) { dealerIcon  = iconRed;           }
            if(dealerSpecialty == 3) { dealerIcon  = iconRedGreen;      }
            if(dealerSpecialty == 4) { dealerIcon  = iconBlue;          }
            if(dealerSpecialty == 5) { dealerIcon  = iconGreenBlue;     }
            if(dealerSpecialty == 6) { dealerIcon  = iconRedBlue;       }
            if(dealerSpecialty == 7) { dealerIcon  = iconRedGreenBlue;  }
            var marker = new GMarker(point, {title: name, icon: dealerIcon});
            var html = '<b>' + name + '</b> <br/>' + address;
            if (currentLang && currentLang == "en")
              { html += '<br/><br/><a href="javascript:showDirections(\''+name.replace("'","\\'")+'\', \''+fromAddress.replace("'","\\'")+'\', \''+toAddress.replace("'","\\'")+'\');">Driving Directions</a>'; }
            GEvent.addListener(marker, 'click', function() { hideDirections(); marker.openInfoWindowHtml(html); });
          }
        return marker;
      }

    function hideDirections()
      {
        document.getElementById("mapdir").style.visibility  = "hidden";
        document.getElementById("route").innerHTML          = "";
      }

    function showDirections(name, startAddress, endAddress)
      {
        document.getElementById("destination").innerHTML  = name;
        if(startAddress == "ROBLIN, MB"  )
          { directions.load("51.227911111N,101.35233333W to " + endAddress); }
         else
          { directions.load(startAddress + " to " + endAddress); }
        document.getElementById("mapdir").style.visibility="visible";
      }

    function createSidebarEntry(marker, name, address, distance) {
      var div = document.createElement('div');
      var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ' km)<br/>' + address;
      div.innerHTML = html;
      div.style.cursor = 'pointer';
      div.style.marginBottom = '5px'; 
      GEvent.addDomListener(div, 'click', function() {
        hideDirections();
        GEvent.trigger(marker, 'click');
      });
      GEvent.addDomListener(div, 'mouseover', function() {
        div.style.backgroundColor = '#eee';
      });
      GEvent.addDomListener(div, 'mouseout', function() {
        div.style.backgroundColor = '#fff';
      });
      return div;
    }
    //]]>

