Polygon.Inherits(Shape);
function Polygon(name){
	if(typeof(name) == "undefined"){
		name = "Polygon";
	}
	
	this.Inherits(Shape, name);
}


Polygon.prototype.create = function(id, coordinate){
	var coordLen = coordinate.length;
	
	if(coordLen == 0) return;
	switch(getBrowser()){
		case "Explorer":{
			if(this.opacity != null){
				var fill = document.createElement("v:fill");
				fill.setAttribute("opacity", this.opacity);
			}
			this.polygon = document.createElement("v:group");
			this.polygon.id = id;
			this.polygon.style.width = this.width;
			this.polygon.style.height = this.height;
			
			for(i=0; i<coordLen; i++){
				pointArray = coordinate[i];
				
				var shape = document.createElement("v:shape");
				shape.style.width = this.width + "px";
				shape.style.height = this.height + "px";
				shape.setAttribute("Filled", (this.fillColor != null)? "true": "false");
				shape.setAttribute("FillColor", this.fillColor);
				shape.setAttribute("Stroked", (this.strokeColor != null)? true: false);
				shape.setAttribute("StrokeColor", this.strokeColor);
				shape.setAttribute("StrokeWeight", this.strokeSize);
				
				var len = pointArray.length;
				var pathPoints = [];
				
				pathPoints.push("m " + pointArray[0].x + ',' + pointArray[0].y + " l ");
				for(var j=1; j<len; j++) {
					((j+1)==len)? pathPoints.push(pointArray[j].x + "," + pointArray[j].y + " ") : pathPoints.push(pointArray[j].x + "," + pointArray[j].y + ", ");
				}
				
				shape.setAttribute("path", pathPoints.join(""));
				if(fill != undefined){shape.appendChild(fill);}
				
				this.polygon.appendChild(shape);
			}
			break;
		}default:{
			var svgNS = 'http://www.w3.org/2000/svg'; 
			this.polygon = document.createElementNS(svgNS, "g"); 
			this.polygon.id = id;
			for(i=0; i<coordLen; i++){
				pointArray = coordinate[i];
				
				shape = document.createElementNS(svgNS, 'polygon');
				len = pointArray.length;
				
				pathPoints = [];
				for(j=0; j<len; j++){
					((j+1)==len)? pathPoints.push(pointArray[j].x + ", " + pointArray[j].y) : pathPoints.push(pointArray[j].x + ", " + pointArray[j].y + ", ");
				}
				shape.setAttributeNS(null, "points", pathPoints.join(""));
				shape.setAttributeNS(null, "fill", this.fillColor);
				shape.setAttributeNS(null, "stroke", this.strokeColor);
				shape.setAttributeNS(null, "stroke-width", this.strokeSize);
				shape.setAttributeNS(null, "fill-opacity", this.opacity);

				this.polygon.appendChild(shape);
			}
			break;
		}
	}
}

Polygon.prototype.setFillColor = function(fillColor){
	var len = this.polygon.childNodes.length;
	switch(getBrowser()){
		case "Explorer":{
			for(var i=0; i<len; i++){
				if(this.polygon.childNodes[i].nodeName == "shape"){
					this.polygon.childNodes[i].FillColor = fillColor;
				}
			}
			break;
		}default:{
			for(i=0; i<len; i++){
				if(this.polygon.childNodes[i].nodeName != "text"){
					this.polygon.childNodes[i].setAttributeNS(null, "fill", fillColor);
				}
			}
			break;
		}
	}
}