
function Cluster(markerClusterer, markerType, clusterDetailsCvs, clusterDetailsGrd, markerInfoCvs) {
   this.center_ = null;
   this.centerCluster_ = false;
   this.clusterDetailsCvs_ = clusterDetailsCvs;
   this.clusterDetailsGrd_ = clusterDetailsGrd;
   this.map_ = markerClusterer.getMap();
   this.markerClusterer_ = markerClusterer;
   this.markerInfoCvs_ = markerInfoCvs;
   this.markers_ = [];
   this.markerType_ = markerType;
   this.clusterIcon_ = null;
}
  
    Cluster.prototype.getMarkers = function() {
      return this.markers_;
    };
     
    Cluster.prototype.isInBounds = function() {
      if (!this.center_) {
        return false;
      }
      
      var bounds = this.map_.getBounds();
      
      return bounds.contains(this.center_);
    };
 
    Cluster.prototype.getCenter = function() {
      return this.center_;
    };
 
    Cluster.prototype.getMap = function() {
      return this.map_;
    };
    
    Cluster.prototype.addMarker = function(marker) {
      if (!this.center_) {
        this.center_ = new google.maps.LatLng(marker.lat_, marker.lng_);
      }
      if (marker.centerMarker_) {
        this.centerCluster_ = true;
        this.center_ = new google.maps.LatLng(marker.lat_, marker.lng_);
      }
      this.markers_.push(marker);
    };
 
    Cluster.prototype.redraw = function() {
      if (this.clusterIcon_ === null) {
        var cntDirectMailTotal = this.getCntDirectMailTotal();
        var cntEEOAsianTotal = this.getCntEEOAsianTotal();
        var cntEEOBlackTotal = this.getCntEEOBlackTotal();
        var cntEEOHispanicTotal = this.getCntEEOHispanicTotal();
        var cntEEOOtherTotal = this.getCntEEOOtherTotal();
        var cntEEOPopulationTotal = this.getCntEEOPopulationTotal();
        var markerLabel;
        switch (this.markerType_) {
          case _constMarkerTypeZIP:
            if (this.markers_.length == 1) {
              markerLabel = this.markers_[0].ZIP_;
            } else {
              markerLabel = this.markers_.length + ' ZIPs';
            }
            break;
          case _constMarkerTypeZIP3:
            markerLabel = this.markers_[0].ZIP3_ + 'XX';
            break;
          case _constMarkerTypeState:
            markerLabel = this.markers_[0].state_;
            break;
        }
        this.clusterIcon_ = new ClusterIcon(this, this.center_, cntDirectMailTotal, markerLabel, this.markerType_, this.centerCluster_);
        this.clusterIcon_.show();
      } else {
        this.clusterIcon_.show();
      }
    };
 
    Cluster.prototype.clearMarkers = function() {
      if (this.clusterIcon_ !== null) {
        this.clusterIcon_.remove();
      }
      this.markers_ = [];
    };
    /*
    Cluster.prototype.addBoundaries = function(boundaryPolygons) {
      this.map_.removeOverlay(this.clusterIcon_);
      for (var i = 0; i < boundaryPolygons.length; i++) {
        this.map_.addOverlay(boundaryPolygons[i]);// TODO: this.map_.addOverlay()?
      }
      this.map_.addOverlay(this.clusterIcon_);// TODO: this.map_.addOverlay()?
    };*/
 
    Cluster.prototype.getCntDirectMailTotal = function() {
      var hitsCnt = 0;
      for (var i = 0; i < this.markers_.length; ++i) {
        if (this.markers_[i].cntDirectMail_ != -1) {
          hitsCnt += this.markers_[i].cntDirectMail_;
        }
      }
      return hitsCnt;
    };
    
    Cluster.prototype.getCntEmailTotal = function() {
      var hitsCnt = 0;
      for (var i = 0; i < this.markers_.length; ++i) {
        if (this.markers_[i].cntEmail_ != -1) {
          hitsCnt += this.markers_[i].cntEmail_;
        }
      }
      return hitsCnt;
    };
    
    Cluster.prototype.getCntEEOAsianTotal = function() {
      var hitsCnt = 0;
      var dataExists = false;
      for (var i = 0; i < this.markers_.length; ++i) {
        if (this.markers_[i].eeoAsian_ != -1) {
          dataExists = true;
          hitsCnt += this.markers_[i].eeoAsian_;
        }
      }
      if (dataExists) {
        return hitsCnt;
      } else {
        return -1;
      }
    };
    
    Cluster.prototype.getCntEEOBlackTotal = function() {
      var hitsCnt = 0;
      var dataExists = false;
      for (var i = 0; i < this.markers_.length; ++i) {
        if (this.markers_[i].eeoBlack_ != -1) {
          dataExists = true;
          hitsCnt += this.markers_[i].eeoBlack_;
        }
      }
      if (dataExists) {
        return hitsCnt;
      } else {
        return -1;
      }
    };
    
    Cluster.prototype.getCntEEOHispanicTotal = function() {
      var hitsCnt = 0;
      var dataExists = false;
      for (var i = 0; i < this.markers_.length; ++i) {
        if (this.markers_[i].eeoHispanic_ != -1) {
          dataExists = true;
          hitsCnt += this.markers_[i].eeoHispanic_;
        }
      }
      if (dataExists) {
        return hitsCnt;
      } else {
        return -1;
      }
    };
    
    Cluster.prototype.getCntEEOOtherTotal = function() {
      var hitsCnt = 0;
      var dataExists = false;
      for (var i = 0; i < this.markers_.length; ++i) {
        if (this.markers_[i].eeoOther_ != -1) {
          dataExists = true;
          hitsCnt += this.markers_[i].eeoOther_;
        }
      }
      if (dataExists) {
        return hitsCnt;
      } else {
        return -1;
      }
    };
    
    Cluster.prototype.getCntEEOPopulationTotal = function() {
      var hitsCnt = 0;
      var dataExists = false;
      for (var i = 0; i < this.markers_.length; ++i) {
        if (this.markers_[i].eeoPopulation_ != -1) {
          dataExists = true;
          hitsCnt += this.markers_[i].eeoPopulation_;
        }
      }
      if (dataExists) {
        return hitsCnt;
      } else {
        return -1;
      }
    };

