function CircleOverlay(latLng, radius, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity) {
	this.latLng = latLng;
	this.radius = radius;
	this.strokeColor = strokeColor;
	this.strokeWidth = strokeWidth;
	this.strokeOpacity = strokeOpacity;
	this.fillColor = fillColor;
	this.fillOpacity = fillOpacity;
}

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

CircleOverlay.prototype.initialize = function(map) {
	this.map = map;
}

CircleOverlay.prototype.clear = function() {
	if(this.polygon != null && this.map != null) {
		this.polygon.setMap(null);
	}
}

CircleOverlay.prototype.draw = function() {
	var d2r = Math.PI / 180;
	circleLatLngs = new Array();
	var circleLat = this.radius * 0.00894;  // Convert statute miles into degrees latitude
	var circleLng = circleLat / Math.cos(this.latLng.lat() * d2r);
	var numPoints = 40;
	
	for (var i = 0; i < numPoints + 1; i++) { 
		var theta = Math.PI * (i / (numPoints / 2)); 
		var vertexLat = this.latLng.lat() + (circleLat * Math.sin(theta)); 
		var vertexLng = this.latLng.lng() + (circleLng * Math.cos(theta));
		var vertextLatLng = new google.maps.LatLng(vertexLat, vertexLng);
		circleLatLngs.push(vertextLatLng); 
	}
	
	this.clear();

        this.polygon = new google.maps.Polygon({
            paths: circleLatLngs,
            strokeColor: this.strokeColor,
            strokeOpacity: this.strokeOpacity,
            strokeWeight: this.strokeWidth,
            fillColor: this.fillColor,
            fillOpacity: this.fillOpacity
        });

        this.polygon.setMap(this.map);
}

CircleOverlay.prototype.remove = function() {
	this.clear();
}

CircleOverlay.prototype.containsLatLng = function(latLng) {

	if(this.polygon.containsLatLng) {
		return this.polygon.containsLatLng(latLng);
	}
}

CircleOverlay.prototype.setRadius = function(radius) {
	this.radius = radius;
}

CircleOverlay.prototype.setLatLng = function(latLng) {
	this.latLng = latLng;
}


