/**
 * cluster marker/
 */       
function Cluster(marker, map, clusterIcon) {
  if(marker.price == 0 || marker.price == null) {
    this.title   = '<div class="cluster-list-item">' + marker.title + ' <span class="price">kostenlos</span></div>';
  } else if(marker.price) {
    this.title   = '<div class="cluster-list-item">' + marker.title + ' <span class="price">' + marker.price + '&euro;</span></div>';
  } else {
    this.title   = '<div class="cluster-list-item">' + marker.title + '</div>';
  }
  this.overlay = new GMarker(marker.overlay.getLatLng(), clusterIcon);  
  this.bounds  = new GLatLngBounds(marker.overlay.getLatLng());
  this.id      = marker.id;  
  this.ids     = [marker.id];
  this.bubbles = $H();
  this.bubbles.set(marker.id, marker.title + marker.bubble);
  map.addOverlay(this.overlay);
  GEvent.bind(this.overlay, "mouseover", this, this.openInfoWindow);
}

Cluster.prototype.add = function(marker) {
  if(marker.price == 0 || marker.price == null) {
    this.title += '<div class="cluster-list-item">' + marker.title + ' <span class="price">kostenlos</span></div>';
  } else if(marker.price) {
    this.title += '<div class="cluster-list-item">' + marker.title + ' <span class="price">' + marker.price + '&euro;</span></div>';
  } else {
    this.title += '<div class="cluster-list-item">' + marker.title + '</div>';
  }
  this.bounds.extend(marker.overlay.getLatLng());
  this.overlay.setLatLng(this.bounds.getCenter());
  this.ids.push(marker.id);
  this.bubbles.set(marker.id, marker.title + marker.bubble);
}

Cluster.prototype.openInfoWindow = function(id) {
  if(id instanceof Object) {    
    this.overlay.openInfoWindowHtml(
      '<label>Artikel an diesem Ort:</label><div class="cluster-scroller" style="max-height:' + (windowSize[1] - 300 > 600 ? 600 : windowSize[1] - 300) + 'px;">'
      + this.title 
      + '</div>');    
  } else {
    this.overlay.openInfoWindowHtml(this.bubbles.get(id));
  }
}

Cluster.prototype.getLatLng = function() {
  return this.overlay.getLatLng();
}

Cluster.prototype.getId = function () {
  return this.id;
}
