function SpeedMarkers() 
{
    this.wmsurl = serverUrl + "php/getmarker.php";
    this.layerArray = new Array();
    this.idArray = new Array();
    this.buffer0 = null;
    this.dragEventHandle = null;
    this.opacity = 1;
    this.format = null;
    this.clickable = null;
	this.cluster = true;
}

SpeedMarkers.prototype = new GOverlay();


SpeedMarkers.prototype.initialize = function(map) 
{
  this.buffer0 = document.createElement("DIV");
  this.buffer0.style.position = "absolute";
    
  map.getPane(G_MAP_MARKER_PANE).appendChild(this.buffer0);

  this.map = map;
  
  this.dragEventHandle = GEvent.bind(this.map,"moveend",this,this.dragend);
  this.zoomEventHandle = GEvent.bind(this.map,"zoomend",this,this.zoomstart);
}

SpeedMarkers.prototype.remove = function() 
{
  GEvent.removeListener(this.dragEventHandle);
  GEvent.removeListener(this.zoomEventHandle);
  this.buffer0.parentNode.removeChild(this.buffer0);
  this.buffer0 = null;
}


SpeedMarkers.prototype.copy = function() 
{
  var tmp = new SpeedMarkers(this.map);
  tmp.layerArray = this.layerArray;
  tmp.idArray = this.idArray;
  return tmp;
}

SpeedMarkers.prototype.imageLoaded = function(request) 
{
  if(debug)
  {
      GLog.write(request.responseText);
  }
  
  var res = eval('(' + request.responseText + ')');
  
  this.buffer0.innerHTML = res.html;
  
  this.idArray = null;
  this.idArray = res.ids;

  var mapBounds = this.map.getBounds();
     
  var ne = mapBounds.getNorthEast();  
  var sw = mapBounds.getSouthWest(); 
     
  var c1 = this.map.fromLatLngToDivPixel(sw);
  var c2 = this.map.fromLatLngToDivPixel(ne);
  
 
  this.buffer0.style.left = c1.x + "px";
  this.buffer0.style.top = c2.y + "px";
  this.buffer0.style.display = "";
  
  if(debug)GLog.write("Image loaded");
}

SpeedMarkers.prototype.redraw = function(force) 
{
  if (!force) 
  {
    return;
  }
  
  var mapBounds = this.map.getBounds();
  
  var ne = mapBounds.getNorthEast();  
  var sw = mapBounds.getSouthWest(); 
  
  var c1 = this.map.fromLatLngToDivPixel(sw);
  var c2 = this.map.fromLatLngToDivPixel(ne);
  
  var clu = "";
  if(this.cluster) {
	  clu = "&cluster=1";
  }
  else {
	  clu = "&cluster=0";
  }
  
  var wu = "mandant=" + mandant + "&ukat=" + this.layerArray.join(",") + "&mids=" + this.idArray.join(",") + "&bbox=" + sw.lng() + "," + ne.lat() + "," + ne.lng() + "," + sw.lat() +  "&width=" + (c2.x - c1.x) + "&height=" + (c1.y - c2.y) + "&z=" + this.map.getZoom() + clu;        
  if(this.format) wu += "&format=" + this.format;
  
  if(this.clickable) wu +=  "&imagemap=" + this.clickable;
  
  if(debug) 
  {	
  	GLog.write(this.wmsurl + "?" + wu);
  }
  
  var myAjax = new Ajax.Request
  (
      this.wmsurl, 
      {
    	    method: 'POST', 
            parameters: wu, 
    	    onSuccess: this.imageLoaded.bind(this)
      }
  );
  
}

SpeedMarkers.prototype.addLayer = function(layer)
{
    if(debug)
    {
	   GLog.write("addLayer: TMJ " + layer);
	}
	
    this.layerArray[this.layerArray.length] = layer;
    this.layerArray = this.layerArray.uniq();
}

SpeedMarkers.prototype.removeLayer = function(layer)
{
        if(debug)
    GLog.write("remLayer:" + layer);    
    for(var i = 0;i < this.layerArray.length;i++)
    {
        if(this.layerArray[i] == layer)
        {
            this.layerArray[i] = null;
            
            this.layerArray = this.layerArray.compact();
            break;
        }
    }
}

SpeedMarkers.prototype.addId = function(id)
{
    if(debug)
    GLog.write(id);
    this.idArray[this.idArray.length] = id;
    this.idArray = this.idArray.uniq();
}

SpeedMarkers.prototype.containsId = function(id)
{
    for(var i = 0;i < this.idArray.length;i++)
    {
        if(this.idArray[i] == id)
        {
            return true;
        }
    }
    
    return false;
}


SpeedMarkers.prototype.removeId = function(id)
{
    for(var i = 0;i < this.idArray.length;i++)
    {
        if(this.idArray[i] == id)
        {
            this.idArray[i] = null;
            
            this.idArray = this.idArray.compact();
            break;
        }
    }
}


SpeedMarkers.prototype.dragend = function()
{
   this.redraw(true);
}

SpeedMarkers.prototype.zoomstart = function()
{
   this.buffer0.style.display = "none";
}


SpeedMarkers.prototype.getLayers = function()
{
	var result = this.layerArray.join(",");
	return result;
}

SpeedMarkers.prototype.getClusterState = function()
{
	return this.cluster;
}

SpeedMarkers.prototype.setClusterState = function(nState)
{
	this.cluster = nState;
}
