function gMapCustomOverlay(params) {
	google.maps.OverlayView.call(this);
	
	this.element_ = params.element;
	this.position_ = params.position;
	this.map_ = params.map;
	
	this.horizontalOffset_ = params.horizontalOffset;
	this.verticalOffset_ = params.verticalOffset;
	
	this.div_ = null;
	this.setMap(this.map_);
}

gMapCustomOverlay.prototype = new google.maps.OverlayView();

gMapCustomOverlay.prototype.onAdd = function() {
	var div = this.element_;
	
	var cancelEvent = function (e) { 
	  e.cancelBubble = true; 
	  if (e.stopPropagation) e.stopPropagation(); 
	};
	
	div.style.position = 'absolute';
	this.div_ = div;
	
	google.maps.event.addDomListener(div, 'mousedown', cancelEvent); 
	google.maps.event.addDomListener(div, 'click', cancelEvent);
	google.maps.event.addDomListener(div, 'dblclick', cancelEvent);
	google.maps.event.addDomListener(div, 'contextmenu', cancelEvent);
	
	var panes = this.getPanes();
	panes.floatPane.appendChild(div);
};

gMapCustomOverlay.prototype.draw = function() {
	var pos = this.getProjection().fromLatLngToDivPixel(this.position_);
	
	var div = this.div_;
	this.div_.style.left = (pos.x - $(div).width() / 2 + this.horizontalOffset_) + "px";
	this.div_.style.top = (pos.y - $(div).height() / 2 + this.verticalOffset_) + "px";
};


gMapCustomOverlay.prototype.show = function() {
	this.div_.style.visibility = 'visible';
}

gMapCustomOverlay.prototype.hide = function() {
	this.div_.style.visibility = 'hidden';
}

gMapCustomOverlay.prototype.toggle = function() {
	if(this.div_.style.visibility == 'hidden') {
		this.show();
	} else {
		this.hide();
	}
}
