var places = {  // http://www.fallingrain.com/world/index.html
    'albany':       { 'name': 'Albany, CA',
                      'location': new GPoint(-122.297, 37.887) },
    'amsterdam':    { 'name': 'Amsterdam, Netherlands', 
                      'location': new GPoint(4.916,    52.35) },
    'castrovalley': { 'name': 'Castro Valley, CA', 
                      'location': new GPoint(-122.085, 37.694) },
    'denbosch':     { 'name': 'Den Bosch, Netherlands', 
                      'location': new GPoint(5.3167,   51.7) },
    'haifa':        { 'name': 'Haifa, Israel', 
                      'location': new GPoint(34.989,   32.815) },
    'moscow':       { 'name': 'Moscow, Russia', 
                      'location': new GPoint(37.615,   55.752) },
    'pittsfield':   { 'name': 'Pittsfield, MA', 
                      'location': new GPoint(-73.245,  42.45) },
    'sanjose':      { 'name': 'San Jose, CA', 
                      'location': new GPoint(-121.894, 37.339) },
    'santabarbara': { 'name': 'Santa Barabara, CA', 
                      'location': new GPoint(-119.697, 34.42) },
    'seattle':      { 'name': 'Seattle, WA',
                      'location': new GPoint(-122.330, 47.606) },
    'telaviv':      { 'name': 'Tel-Aviv, Israel',
                      'location': new GPoint(34.766,   32.067) },
    'ventura':      { 'name': 'Ventura, CA', 
                      'location': new GPoint(-119.292, 34.278) }
};
  
var people = {
    'ab': { name: 'Алексей Бетин', place: places['pittsfield'], color: 'brown' },
    'lj': { name: 'Лена Жуковская', place: places['haifa'], color: 'yellow' },
    'dz': { name: 'Дима Загороднов', place: places['santabarbara'], color: 'red' },
    'vk': { name: 'Вася Кочергин', place: places['seattle'], color: 'orange' },
    'sk': { name: 'Сергей Куркин', place: places['denbosch'], color: 'purple' },
    'dl': { name: 'Дима Лычагин', place: places['sanjose'], color: 'green' },
    'ms': { name: 'Максим Шацкий', place: places['castrovalley'], color: 'blue' } 
};
    
function getImageLink(person) {
    return 'http://labs.google.com/ridefinder/images/mm_20_' + person.color + '.png';
}

function createMarkerText(person) {
    return person.name + ',<br/>' + person.place.name;
}    
    
function createMarker(map, pid, person) {
    var icon = new GIcon();
    icon.image = getImageLink(person);
    icon.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);

    var marker = new GMarker(person.place.location, icon);
    var markerText = createMarkerText(person);
    var markerClick = function() { marker.openInfoWindowHtml(markerText); };
    GEvent.addListener(marker, "click", markerClick);

    map.addOverlay(marker);    
    
    var pimg = document.getElementById(pid+'-img');
    pimg.src = getImageLink(person);
    pimg.onclick = function() { marker.openInfoWindowHtml(markerText); };
}

function drawMap(elementid) {
    if (GBrowserIsCompatible()) {
        var map = new GMap(document.getElementById(elementid));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.centerAndZoom(new GPoint(-44.29, 57.13), 4);
        map.zoomTo(15);
  
        //GEvent.addListener(map, "click", function() { alert(map.getCenterLatLng()); });              

        for (var pid in people) {
          var person = people[pid];
          createMarker(map, pid, person);
        }
    }        
}

