COUNTY_FILL_OPACITY = 0.2;
COUNTY_LINE_OPACITY = 0.4;
COUNTY_LINE_WIDTH = 2;

CountyMapControl = Class.create({
    initialize: function(map_id, options) {
	this.options = $H(options);
	this.onselect = this.options.get("onselect") || function() {};
	this.map = new GMap2(document.getElementById(map_id));
	this.map.setCenter(new GLatLng(options.lat, options.lng), 8);
	this.map.addControl(new GLargeMapControl());
	this.counties = $A([]);
    },
    add_county: function(county_name, options) {
	var county = new GCounty(county_name, options);
	this.map.addOverlay(county);
	GEvent.addListener(county.marker, "click", function() {
	    this.onselect(county_name);
	}.bind(this));
	this.counties << county;
    }
});

// options:
//  points: [[lat, long], [lat, long], [lat, long]]
//  center: [lat, long]
//  color: "#0033ff"
//  image: "url"
//  image-size: [x, y]
function GCounty(county_name, options) {
    options = $H(options)
    this.color = options.get("color");
    this.image = options.get("image");
    this.image_size = options.get("image_size");
    this.id = options.get('id');
    this.lat = options.get('lat');
    this.lng = options.get('lng');
};
GCounty.prototype = Object.extend(new GControl(), {
    initialize: function(map) {
	this.map = map;
    
	this.center = new GLatLng(this.lat, this.lng);

	var icon = new GIcon();
	icon.image = this.image;
	icon.iconSize = new GSize(this.image_size[0], this.image_size[1]);
	icon.dragCrossSize = new GSize(0, 0);
	icon.iconAnchor = new GPoint(this.image_size[0] / 2, this.image_size[1] / 2);
    
	this.marker = new GMarker(this.center, {icon:icon, draggable:false, bouncy:false, dragCrossMove:true});
	map.addOverlay(this.marker);
    },
    redraw: function(map) {
    }
});
