function RaphaelOverlay(options) {

	/**
	 * autor: CTAPbIu_MABP
	 * email: ctapbiumabp@gmail.com
	 * site: http://mabp.kiev.ua/2010/09/10/raphael-overlay/
	 * license: GPL
	 * last update: 10.09.2010
	 * version: 0.1
	 */

	this.figures = options.figures;
	this.plot = options.plot;
	this.position = options.position;
	this.setMap(options.map);
	
	this.shapes = [];
	this.zoom;
}

RaphaelOverlay.prototype = new google.maps.OverlayView();

RaphaelOverlay.prototype.onAdd = function() {
	
	var center = this.getProjection().fromLatLngToDivPixel(new google.maps.LatLng(0,0)),
		worldWidth = this.getProjection().getWorldWidth();
		
	this.div = document.createElement('div');
	this.div.style.border = 'none';
	this.div.style.position = 'absolute';
	this.div.style.overflow = 'visible';
	
	this.div.style.left = center.x - worldWidth / 2 + 'px';
	this.div.style.top = center.y - worldWidth / 2 + 'px';
	this.div.style.width = worldWidth+'px';
	this.div.style.height = worldWidth+'px';
	
	this.getPanes().overlayImage.appendChild(this.div);
	this.canvas = Raphael(this.div, worldWidth, worldWidth);
	this.canvas.setSize(worldWidth,worldWidth);
};

RaphaelOverlay.prototype.draw = function() {
	/*
	var zoom = this.getMap().getZoom();
	
	if (this.zoom == zoom){
		return;
	}else{
		this.zoom = zoom; 
	}*/
	
	var center = this.getProjection().fromLatLngToDivPixel(new google.maps.LatLng(0,0)),
		worldWidth = this.getProjection().getWorldWidth(),
		left = center.x - worldWidth / 2,
		top = center.y - worldWidth / 2,
		figure = null;
		
	this.zoom = this.getMap().getZoom();
	this.div.style.left = left + 'px';
	this.div.style.top = top + 'px';
	this.div.style.width = worldWidth + 'px';
	this.div.style.height = worldWidth + 'px';
	this.canvas.setSize(worldWidth, worldWidth);
	
	for (var i in this.shapes){
		this.shapes[i].remove();
	}
	
	for (var i in this.figures){
		figure = this[this.figures[i].type](this.figures[i], {
			scale : 1 << this.getMap().getZoom(),
			left:left, 
			top:top
		});
		if (this.figures[i].attr){
			figure.attr(this.figures[i].attr)
		}
		this.shapes.push(figure);
	}

};

RaphaelOverlay.prototype.text = function(data, param) {
	var point = this.getProjection().fromLatLngToDivPixel(data.position),
		x = point.x - param.left,
		y = point.y - param.top;
	return this.canvas.text(x, y, data.text);
};

RaphaelOverlay.prototype.image = function(data, param) {
	var point = this.getProjection().fromLatLngToDivPixel(data.position),
		width = data.width * param.scale,
		height = data.height * param.scale,
		x = point.x - param.left,
		y = point.y - param.top;
	return this.canvas.image(data.src, x, y, width, height);

};

RaphaelOverlay.prototype.ellipse = function(data, param) {
	var point = this.getProjection().fromLatLngToDivPixel(data.position),
		rx = param.scale * data.rx,
		ry = param.scale * data.ry,
		x = point.x - param.left,
		y = point.y - param.top;
	return this.canvas.ellipse(x, y, rx, ry);
};

RaphaelOverlay.prototype.rect = function(data, param) {
	var point = this.getProjection().fromLatLngToDivPixel(data.position),
		width = data.width * param.scale,
		height = data.height * param.scale,
		x = point.x - param.left,
		y = point.y - param.top;
	return this.canvas.rect(x, y, width, height);
};

RaphaelOverlay.prototype.circle = function(data, param) {
	var point = this.getProjection().fromLatLngToDivPixel(data.position),
		radius = param.scale * data.radius,
		x = point.x - param.left,
		y = point.y - param.top;
	return this.canvas.circle(x, y, radius / 2);
};


RaphaelOverlay.prototype.onRemove = function() {
	for (var i in this.shapes){
		this.shapes[i].remove();
	}
	this.div.parentNode.removeChild(this.div);
};
