// Based on the script ELabel by Mike Williams, Community Church Javascript Team, http://www.bisphamchurch.org.uk/, http://econym.org.uk/gmap/
// This work is licenced under a Creative Commons Licence, http://creativecommons.org/licenses/by/2.0/uk/

function Label (point, html, classname, offset, pane) {
	this.point = point;
	this.html = html;
	this.classname = classname || '';
	this.offset = offset || new GSize (0, 0);
	this.pane = pane || G_MAP_MARKER_SHADOW_PANE;
	this.hidden = false;
	};

Label.prototype = new GOverlay ();

Label.prototype.initialize = function (m) {
  var el = document.createElement('div');
  el.style.position = 'absolute';
	el.className = this.classname;
  el.innerHTML = this.html;
  m.getPane(this.pane).appendChild(el);
	this.map = m;
  this.container = el;
  if (this.hidden) this.hide();
	};

Label.prototype.remove = function () {
  this.container.parentNode.removeChild(this.container);
	};

Label.prototype.copy = function () {
  return new Label(this.point, this.html, this.classname, this.offset, this.pane);
	};

Label.prototype.redraw = function (f) {
  var p = this.map.fromLatLngToDivPixel(this.point);
  var h = parseInt(this.container.clientHeight);
  this.container.style.left = (p.x + this.offset.width) + "px";
  this.container.style.top = (p.y +this.offset.height - h) + "px";
	};

Label.prototype.show = function () {
  if (this.container) {this.container.style.display = 'block'; this.redraw();};
	this.hidden = false;
	};
      
Label.prototype.hide = function () {
  if (this.container) this.container.style.display = 'none';
	this.hidden = true;
	};
      
Label.prototype.setHtml = function (t, c) {
  this.html = t;
  this.container.innerHTML = t;
	if (c != '') {this.classname = c; this.container.className = c;};
  this.redraw (true);
	};
      
Label.prototype.setPoint = function (p) {
  this.point = p;
  this.redraw(true);
	};
      
Label.prototype.getPoint = function () {
  return this.point;
	};

Label.prototype.isHidden = function () {
	return this.hidden;
	};

Label.prototype.supportsHide = function () {
	return true;
	};
