elasticLine = function(oParams)
{
	this.canvas = document.getElementById(oParams.canvas.id);
	this.canvasContainer = document.getElementById(oParams.canvas.containerId);

	this.currentWidth = this.canvasContainer.clientWidth;
	this.currentHeight = this.canvasContainer.clientHeight;

	this.lineType = oParams.lineType;

	this.linePoints = oParams.linePoints;

	if (this.lineType == 'bezier') {
		this.controlPoints = oParams.controlPoints
	}
	
	this.ctx = null;
	if (this.canvas.getContext) {
		this.ctx = this.canvas.getContext('2d');
		this.ctx.strokeStyle = oParams.strokeStyle || "rgba(255, 255, 255, 0.2)";
	}

	if (!oParams.doNotDraw) {
		this.draw();
	}
}

elasticLine.prototype.test = function(){
	alert(this.normalWidth + 'x' + this.normalHeight);
}

elasticLine.prototype.calculatePoints = function (aPoints){
	var tmpPoints = new Array();
	var _x = 0;
	var _y = 0;

	for (var i = 0; i < aPoints.length ; i++) {
		if (!aPoints[i].xFixed){
			_x = this.currentWidth * aPoints[i].xRatio;
		} else {
			_x = aPoints[i].x;
		}
		if (!aPoints[i].yFixed){
			_y = this.currentHeight * aPoints[i].yRatio;
		} else {
			_y = aPoints[i].y;
		}

		tmpPoints.push({x : _x, y : _y});
	}

	return tmpPoints;
}

elasticLine.prototype.drawStraightLine = function(){
	var linePoints = this.calculatePoints (this.linePoints);

	this.ctx.beginPath();
	this.ctx.moveTo (linePoints[0].x, linePoints[0].y);
	this.ctx.lineTo (linePoints[1].x, linePoints[1].y);
	this.ctx.stroke();
}

elasticLine.prototype.drawBezierLine = function(){
	var linePoints = this.calculatePoints (this.linePoints);
	var controlPoints = this.calculatePoints (this.controlPoints);

	this.ctx.beginPath();
	this.ctx.moveTo (linePoints[0].x, linePoints[0].y);
	this.ctx.bezierCurveTo (
		controlPoints[0].x,
		controlPoints[0].y,
		controlPoints[1].x,
		controlPoints[1].y,
		linePoints[1].x,
		linePoints[1].y
	);
	this.ctx.stroke();
}

elasticLine.prototype.draw = function(){
	switch(this.lineType){
		case "bezier" : this.drawBezierLine(); break;
		case "straight" : this.drawStraightLine(); break;
	}
}

elasticLine.prototype.redraw = function(){
	if (this.currentWidth != this.canvasContainer.clientWidth || this.currentHeight != this.currentHeight) {
		this.ctx.clearRect(0, 0, this.canvas.offsetWidth, this.canvas.offsetHeight);

		this.currentWidth = this.canvasContainer.clientWidth;
		this.currentHeight = this.canvasContainer.clientHeight;

		this.draw();
	}
}
