var ImmobiloMapRadius = {
		
		polyline: null,
		borderColor: '#ff0000',
		bgColor: '#006600',
		opacity: 0.2,
		lineWidth: 1,
	
		destination: function(orig, hdng, dist) {
	
			var R = 6371; // earth's mean radius in km
			var oX, oY;
			var x, y;
			var d = dist/R;  // d = angular distance covered on earth's surface
			hdng = hdng * Math.PI / 180; // degrees to radians
			oX = orig.x * Math.PI / 180;
			oY = orig.y * Math.PI / 180;

			y = Math.asin( Math.sin(oY)*Math.cos(d) + Math.cos(oY)*Math.sin(d)*Math.cos(hdng) );
			x = oX + Math.atan2(Math.sin(hdng)*Math.sin(d)*Math.cos(oY), Math.cos(d)-Math.sin(oY)*Math.sin(y));

			y = y * 180 / Math.PI;
			x = x * 180 / Math.PI;
			return new GLatLng(y, x);
	
		},
		hide: function () {
			
			if (typeof ImmobiloMapRadius.polyline !== 'undefined') {
				map.removeOverlay(ImmobiloMapRadius.polyline);
			}
			
		},
		show: function (map, centerpoint, radius) {
			
			// ImmobiloMapRadius.hide();
				
			var points = [];
			var distance = radius/1000;
			for (i = 0; i < 72; i++) {
			  points.push(ImmobiloMapRadius.destination(centerpoint, i * 360/72, distance));
			}
			points.push(ImmobiloMapRadius.destination(centerpoint, 0, distance) );
			
			ImmobiloMapRadius.polyline = new GPolygon(
					points, 
					ImmobiloMapRadius.borderColor, 
					ImmobiloMapRadius.lineWidth, 
					ImmobiloMapRadius.lineWidth, 
					ImmobiloMapRadius.bgColor,
					ImmobiloMapRadius.opacity
			);
			map.addOverlay(ImmobiloMapRadius.polyline);
			
		}
		
};


