var tlJmapCrossHair = null;

(function($){

  tlJmapCrossHair = function(options)
  {
    var defaults = {
      /* Takes the form of a page that can have "?image=" + radius + "-" + color + ".png" appended */
      updateUrl: "",
      radius: 20,
      color: "0000c000",
      padding: 0
    };
    this.options = $.extend({}, defaults, options);
  }

  tlJmapCrossHair.prototype = new GOverlay();

  tlJmapCrossHair.prototype.initialize = function(map)
  {
    this.map = map;
    this.crshr = $("<img/>");
    this.crshr.addClass("tlJmapCrosshair");
    this.crshr.css("position", "absolute");

    // Render our overlay
    this.redraw(true);

    $(map.getPane(G_MAP_MAP_PANE)).append(this.crshr);
  }

  tlJmapCrossHair.prototype.remove = function()
  {
    this.crshr.remove();
  }

  tlJmapCrossHair.prototype.redraw = function(force)
  {
    if (typeof force == "undefined") force = false;
    var center = this.map.fromLatLngToDivPixel(this.map.getCenter());
    var offset = this.options.radius + this.options.padding;

    this.crshr.css("top", center.y - offset);
    this.crshr.css("left", center.x - offset);

    if (!force) return;

    this.crshr.attr("src", this.options.updateUrl + "?image=" + this.options.radius + "-" + this.options.color + ".png");
    this.crshr.width(offset * 2);
    this.crshr.height(offset * 2);
  }

  tlJmapCrossHair.prototype.setRadius = function(radius)
  {
    if (this.radius != radius)
    {
      this.options.radius = radius;
      this.redraw(true);
    }
  }
})(jQuery);
