RoundRectangle.Inherits(Shape);
function RoundRectangle(name){
	if(typeof(name) == "undefined"){
		name = "Rectangle";
	}
	this.Inherits(Shape, name);
	
	this.backgroundColor = "#26415f";
	this.strokeColor = "#d8d9d4";
}

RoundRectangle.prototype.create = function(id, width, height, text, fontSize, left, top){
	this.id = id;
	
	
	var re = new RegExp("<\s*br\s*/\s*>");
	try{
		var newLineCount = (text.match(re)).length;
		if(newLineCount > 0){
			var arrLine = text.split(re);
			width = arrLine[0].length;
			for(var i=1; i<arrLine.length; i++){
				width = (width > arrLine[i].length)?width:arrLine[i].length;
			}
			width = parseInt(parseInt(width) * parseInt(fontSize-6));
			height = 2 * (parseInt(arrLine.length) + 1) * parseInt(fontSize);
		}
	}catch(ex){
	
	}
	
	var clientBrowser = new ClientBrowser();
	clientBrowser.init();
	
	switch(clientBrowser.browser){
		case "Explorer":{
			shape = document.createElement("v:roundrect");
			shape.setAttribute("id", this.id);
			shape.style.position = "absolute";
			shape.style.zIndex = 1;
			shape.style.width = width;
			shape.style.height = height;
			shape.style.left = left;
			shape.style.top = top;
			shape.setAttribute("arcsize", "0.1");
			shape.setAttribute("opacity", "1.0");
			shape.setAttribute("fill", "true");
			shape.setAttribute("fillColor", this.backgroundColor);
			shape.setAttribute("stroke", "true");
			shape.setAttribute("strokeColor", this.strokeColor);
			shape.setAttribute("strokeWeight", "1px");
			
			var fill = document.createElement("v:fill");
			fill.setAttribute("opacity", "0.6");
			shape.appendChild(fill);
			
			var innerText = document.createElement("div");
			var textNode = document.createElement("pre");
			textNode.style.wordWrap = "break-word";
			textNode.innerHTML = text;
			
			textNode.style.fontFamily = "Georgia, Times\ New\ Roman, Times, serif";
			textNode.style.fontSize = fontSize + "px";
			textNode.style.fontWeight = "bold";
			textNode.style.color= "#f2f2f0";
			textNode.style.padding = "15px 15px 10px 15px";
			textNode.style.lineHeight = "1.6";
			
			innerText.appendChild(textNode);
			shape.appendChild(innerText);
			
			
		    return shape;
		}default:{
			var roundRect= document.createElement("div");
			
			var textNode = document.createElement("div");
			textNode.style.wordWrap = "break-word";
			textNode.innerHTML = text;
			
			textNode.style.fontFamily = "Georgia, Times\ New\ Roman, Times, serif";
			textNode.style.fontSize = fontSize + "px";
			textNode.style.fontWeight = "bold";
			textNode.style.position = "absolute";
			textNode.style.top = top + "px";
			textNode.style.left = left + "px";
			textNode.style.color= "#f2f2f0";
			textNode.style.padding = "15px 15px 10px 15px";
			textNode.style.lineHeight = "1.6";
			textNode.style.zIndex = 1;
			textNode.style.width = width + "px";
			
			roundRect.appendChild(textNode);
			
			var radius = 15;
			var canvas = document.createElement("canvas");
			canvas.style.position = "absolute";
			canvas.setAttribute("id", this.id);
			canvas.setAttribute("width", width);
			canvas.setAttribute("height", height);
			canvas.style.zIndex = 0;
			canvas.style.margin = "0px";
			canvas.style.left = left + "px";
			canvas.style.top = top + "px";
			
			var ctx = canvas.getContext('2d');

			ctx.clearRect(0, 0, width, height);
			
			ctx.fillStyle = this.backgroundColor;
			ctx.strokeStyle= this.strokeColor;
			ctx.lineWidth = 1;
			
			ctx.beginPath(); 
			ctx.moveTo(left, top+radius); 
			ctx.lineTo(left, top+height-radius); 
			ctx.quadraticCurveTo(left, top+height, left+radius, top+height); 
			ctx.lineTo(left+width-radius, top+height); 
			ctx.quadraticCurveTo(left+width, top+height, left+width, top+height-radius); 
			ctx.lineTo(left+width,top+radius); 
			ctx.quadraticCurveTo(left+width, top, left+width-radius, top); 
			ctx.lineTo(left+radius, top); 
			ctx.quadraticCurveTo(left,top,left,top+radius); 
			ctx.closePath();
			ctx.stroke();
			
			ctx.globalAlpha = 0.6;
			ctx.fill();
			ctx.save();
			
			roundRect.appendChild(canvas);
			
			return roundRect;
	    }
	}
}