/*
 * SRSA Website and Race Management Software
 *
 * Pete Calvert <pete@skiresults.co.uk>
 * Copyright 2008/09
 *
 * MultiMap API Handling
 * javascript/map.js
 */

function Map_Load() {
  for(lIndex = 0; ; lIndex++) {
    lElement = document.getElementById('map' + lIndex);
    
    if(lElement) {
      lViewer = new MultimapViewer(lElement);
      lViewer.addEventHandler('endGeocode', Map_Mark);
      lViewer.goToPosition(new MMLocation(new MMAddress({
        zip: lElement.title,
        country_code: 'GB'
      })));
      lViewer.addWidget(new MMSmallZoomWidget());
    } else {
      break;
    }
  }
}

function Map_Mark(aType, aTarget, aLocation, aErrorCode) {
  if(!aErrorCode) {
    var lIcon = new MMIcon('/images/red-circle.png');
    lIcon.iconSize = new MMDimensions(32, 32);
    lIcon.iconAnchor = new MMPoint(16, 16);
    
    aTarget.createMarker(aLocation, {'inert': true, 'icon': lIcon});
  }
}

MMAttachEvent(window, 'load', Map_Load);
