/**
 * MapMarkerOverlay Object
 * Allow to show dynamic HTML
 *
 * @author shulard@gmail.com
 * @author ocarrera@agenceinteractive.com
 * @copy Agence Interactive 2010
 */
MapMarkerOverlay.prototype = new google.maps.OverlayView();

/**
 * MapMarkerOverlay constructor
 * @return MapMarkerOverlay object
 */
function MapMarkerOverlay()
{
	this.sContent = null;
	return this;
}

MapMarkerOverlay.prototype.setContent = function( sContent )
{
	this.sContent = sContent;
}

MapMarkerOverlay.prototype.setPositionFromMarker = function( oMarker )
{
	this.oPosition = oMarker.position;
}

MapMarkerOverlay.prototype.onAdd = function()
{
	if( this.element )
		this.element.parentNode.removeChild(this.element);

	// Create the DIV and set some basic attributes.
	this.element = new Element('div');
	this.element.set('style', 'position:absolute;');
	this.element.set('html', this.sContent);
	
	// We'll add this overlay to the floatPane pane (at the top pane).
	var panes = this.getPanes();
	panes.floatPane.appendChild(this.element);
}

MapMarkerOverlay.prototype.draw = function()
{
	if( !this.getMap() )
		throw('Map object hasn\'t been attached to Overlay');
	
	var overlayProjection = this.getProjection();
	var oPixelPosition = overlayProjection.fromLatLngToDivPixel(this.oPosition);

	// Resize the image's DIV to fit the indicated dimensions.
	if( $chk( oPixelPosition ) )
	{
		this.element.style.left = (oPixelPosition.x - (this.element.getSize().x / 2) ) + 'px';
		this.element.style.top = (oPixelPosition.y - this.element.getSize().y ) + 'px';
	}
	else
		throw('Overlay hasn\'t been poisitioned...')
	
	google.maps.event.trigger(this, 'overlayLoaded');
}



MapMarkerOverlay.prototype.onRemove = function()
{
	this.element.parentNode.removeChild(this.element);
	this.element = null;
}
