
// the legend with checkboxes displayed next to large maps
var GoogleMapLegend = {

  activeMap: null,

  load: function() 
  {
    //Prevent error message
    if (typeof (google.maps.Icon) == "undefined") return;
  
    var legendContainer = document.getElementById('googleMapResultsLegendList');
    if (!legendContainer)
    {
      return;
    }
    
    if (GoogleMiniMap && GoogleMiniMap.loaded)
    {
      this.activeMap = GoogleMiniMap;
    }
    if (GoogleMapDetail && GoogleMapDetail.loaded)
    {
      this.activeMap = GoogleMapDetail;
    }
    if (GoogleMapResults && GoogleMapResults.loaded)
    {
      this.activeMap = GoogleMapResults;
    }
    
    Spif.DOMEvents.attach(legendContainer, "change", GoogleMapLegend.handleChange);
    if (Spif.isIE)
    {
      Spif.DOMEvents.attach(legendContainer, "click", GoogleMapLegend.handleChange);
    }
  },
  
  handleChange: function(evt)
  {
    var el = evt.subject;
    var showPins = el.checked;
    var fname = (el.checked ? "show" : "hide") + "Pins";
    
    if (el.nodeName.toLowerCase() == "input")
    {
      var type = el.id.replace("googleMapResultsToggle","").toLowerCase();
      if (type == "huis")
      {
        type = "huis/villa";
      }
      GoogleMapLegend[fname](type);
    }    
  },
  
  showPins: function(type)
  {
    this.activeMap.showPins(type);
  },
  
  hidePins: function(type)
  {
    this.activeMap.hidePins(type);
  }
  
};