/**
 * This script implements a rectangle overlay for a GMap2 object.
 */

function Rectangle(bounds, opt_weight, opt_color) {
	this.bounds_ = bounds;
	this.weight_ = opt_weight || 1;
	this.color_ = opt_color || "#FFFF99";
}

Rectangle.prototype = new GOverlay();

// The div for the rectangle
Rectangle.prototype.initialize = function(map) {
	var div = document.createElement("div");
	div.style.border = this.weight_ + "px solid #000000";
	div.style.background = this.color_;
	div.style.opacity = "0.60";
	div.style.filter = "alpha(opacity=60)";
	div.style.position = "absolute";

	map.getPane(G_MAP_MAP_PANE).appendChild(div);

	this.map_ = map;
	this.div_ = div;
}

Rectangle.prototype.remove = function() {
	this.div_.parentNode.removeChild(this.div_);
}

Rectangle.prototype.copy = function() {
	return new Rectangle(this.bounds_, this.weight_, this.color_,
		this.backgroundColor_, this.opacity_);
}

Rectangle.prototype.redraw = function(force) {
	if(!force) { return; }

	// Compute coordinates for size of div
	var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
	var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());

	// Position the div appropriately
	this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
	this.div_.style.height = Math.abs(c2.y - c1.y) + "px";
	this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_) + "px";
	this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_) + "px";
}
