

function PolyMgr(map) {
	this.map_ = map;
	this.polys_ = new Array();
}

PolyMgr.prototype = new Object();

PolyMgr.prototype.add = function(poly) {
	this.polys_.push(poly);
}

PolyMgr.prototype.setVisibility = function(vis) {
	for( var i=0; i < this.polys_.length; i++ ) {
		this.polys_[i].setVisibility(vis);
	}
}

PolyMgr.prototype.setLabelVisibility = function(vis) {
	for( var i=0; i < this.polys_.length; i++ )
		this.polys_[i].label_.setVisibility(vis);
}

PolyMgr.prototype.clean = function() {
	while( this.polys_.length > 0 ) {
		var p = this.polys_.pop();
		p.clean();
	}
}
		
function Poly(map, points, center, levels, strokeColor, strokeWidth, strokeWeight, fillColor, fillOpacity, label) {
	this.map_ = map;
	this.levels_ = levels;
	this.points = points;
	this.strokeColor_ = strokeColor;
	this.strokeWidth_ = strokeWidth;
	this.fillColor_ = fillColor;
	this.fillOpacity_ = fillOpacity;
	this.label_ = label;
	this.visibility_ = false;
	this.poly_ = null;
	this.overlay_ = false;
	this.center = center;
	
		this.poly_ = new GPolygon.fromEncoded({
			polylines: [{
	  		color: strokeColor,
	  		weight: strokeWidth,
	  		opacity: fillOpacity,
	  		points: points,
	  		levels: levels,
	  		zoomFactor: 2,
	  		numLevels: 18
			}],
  			fill: true,
  			color: fillColor,
  			outline: true
		});		
	this.map_.addOverlay(this.label_);
}

Poly.prototype = new Object();

Poly.prototype.clean = function() {
	this.setVisibility(false);
	this.map_.removeOverlay(this.label_);
	this.hide();
	this.poly_ = null;
	this.label_ = null;
}
		

Poly.prototype.show = function() {
	if( this.overlay_ == false )
		this.map_.addOverlay(this.poly_);
	this.overlay_ = true;
}

Poly.prototype.hide = function () {
	if( this.overlay_ == true )
		this.map_.removeOverlay(this.poly_);
	this.overlay_ = false;
}

Poly.prototype.setVisibility = function(vis) {
	if(vis==true) this.show();
	else this.hide();
	this.setLabelVisibility(vis);
}


Poly.prototype.setLabelVisibility = function(vis) {
	this.label_.setVisibility(vis);
}
