// Define the overlay, derived from google.maps.OverlayView
//www.barattalo.it/examples/ruler.html
function Label(opt_options, style) {
	// Initialization
	this.setValues(opt_options);
	// Label specific
	var span = this.span_ = document.createElement('span');
	//span.setAttribute("class",style)
	//span.style.cssText = 'position:relative; left:0%; top:-15px;';

	var div = this.div_ = document.createElement('div');
	div.className = style;
	div.appendChild(span);
	div.style.cssText = 'position:absolute; display:none; white-space:nowrap;';

	this.offsetx = opt_options.x||0;
	this.offsety = opt_options.y||0;
};

Label.prototype = new google.maps.OverlayView;

// Implement onAdd
Label.prototype.onAdd = function() {
	var pane = this.getPanes().overlayLayer;
	pane.appendChild(this.div_);

	// Ensures the label is redrawn if the text or position is changed.
	var me = this;
	this.listeners_ = [
		google.maps.event.addListener(this, 'position_changed', function() {
			me.draw();
		}),
		google.maps.event.addListener(this, 'text_changed', function() {
			me.draw();
		})
	];
};

// Implement onRemove
Label.prototype.onRemove = function() {
	this.div_.parentNode.removeChild(this.div_ );
	// Label is removed from the map, stop updating its position/text.
	for (var i = 0, I = this.listeners_.length; i < I; ++i) {
		google.maps.event.removeListener(this.listeners_[i]);
	}
};

// Implement draw
Label.prototype.draw = function() {
	var projection = this.getProjection();
	//alert(this.get('position'));

	var position = projection.fromLatLngToDivPixel(this.get('position'));//ÇöÀç À§Ä¡°¡Á®¿À±â//label.bindTo('position', marker, 'position')
	//ÇöÀç ¸ÊÀ» ±âÁØÀ¸·Î »ó´ë ÁÂÇ¥¸¦ °¡Á®¿Â´Ù.

	var div = this.div_;
	div.style.left = (position.x+this.offsetx) + 'px';
	div.style.top = (position.y+this.offsety) + 'px';
	div.style.display = 'block';
	var text = this.get('text');
	if(text) this.span_.innerHTML = text.toString();
};

