Drupal.gmap.addHandler('gmap', function(elem) {
  var obj = this;

  obj.bind('init', function() {
    obj.clickmarker_refs = {};

    // Attach to the links.
    $('tr.row-property').click(function(e) {
      e.preventDefault();
      // strip off property-
      var id = this.id.substr(9);
      if (obj.clickmarker_refs[''+id+'/0']) {
        var marker = obj.clickmarker_refs[''+id+'/0'];
        obj.change('clickmarker', -1, marker);
        $('tr.row-property').removeClass( 'selected-row' );
        $(this).addClass( 'selected-row' ); 
      }
      return false;
    });
  });

  obj.bind('addmarker',function(marker) {
    // Stash away a copy of the marker indexed by rmt.
    if (marker.rmt) {
      obj.clickmarker_refs[marker.rmt] = marker;
    }
  });
});
