function GMMarker (latLng, icon)
{
  this.latLng = latLng;
  this.icon = icon;
}

GMMarker.prototype = new GOverlay();

// =============================================

GMMarker.prototype.copy = function ()
{
  alert('GMMarker.copy() is not implemented');
}

GMMarker.prototype.initialize = function (map)
{
  var img = top.document.createElement('img');
  img.style.position = 'absolute';
  img.style.cursor = 'pointer';

  map.getPane(G_MAP_MARKER_PANE).appendChild(img);
  
  img.markerObject = this;

  img.onclick = function ()
  {
    GEvent.trigger(this.markerObject, 'click');
  }
  
  this.map = map;
  this.container = img;  
  
  this.redrawIcon();
}

GMMarker.prototype.redraw = function (force)
{
  if (!force) return;

  var point = this.map.fromLatLngToDivPixel(this.getLatLng());
  
  this.container.style.left   = point.x - this.getIcon().iconAnchor.x;
  this.container.style.top    = point.y - this.getIcon().iconAnchor.y;
  this.container.style.zIndex = GOverlay.getZIndex(this.getLatLng().lat());
  
  this.map.closeInfoWindow();
}

GMMarker.prototype.remove = function ()
{
  this.container.parentNode.removeChild(this.container);
}

// =============================================

GMMarker.prototype.getLatLng = function ()
{
  return this.latLng;
}

GMMarker.prototype.hide = function ()
{
  this.container.style.display = 'none';
}

GMMarker.prototype.openInfoWindow = function (node, opts)
{
  var markerPoint = this.map.fromLatLngToContainerPixel(this.getLatLng());
  
  markerPoint.x += this.getIcon().infoWindowAnchor.x - this.getIcon().iconAnchor.x;
  markerPoint.y += this.getIcon().infoWindowAnchor.y - this.getIcon().iconAnchor.y;

  return this.map.openInfoWindow(
    this.map.fromContainerPixelToLatLng(markerPoint), node,  opts
  );
}

GMMarker.prototype.setLatLng = function (latLng)
{
  var oldValue = this.latLng;
  
  this.latLng = latLng;
  
  this.redraw(true);
  
  return oldValue;
}

GMMarker.prototype.show = function ()
{
  this.container.style.display = 'block';
}

// =============================================

GMMarker.prototype.getIcon = function ()
{
  return this.icon;
}

GMMarker.prototype.setIcon = function (icon)
{  
  this.icon = icon;
 
  this.redrawIcon();
  this.redraw(true);
}

GMMarker.prototype.redrawIcon = function ()
{
  this.container.src    = this.icon.image;
  this.container.width  = this.icon.iconSize.width;
  this.container.height = this.icon.iconSize.height;
}
