//<script type="text/javascript">

Doodle.Canvas = function(divCanvas, document) {
	this.divCanvas = divCanvas;
	this.document = document;
	this.gr = new Graphics(divCanvas);

	// set up mouse handlers
	this.divCanvas.onmousedown = this.onMouseDown.bindEvent(this);
	this.divCanvas.onmousemove = this.onMouseMove.bindEvent(this);
	this.divCanvas.onmouseup = this.onMouseUp.bindEvent(this);
	
	// canvas properties
	this.bMouseDown = false;
	
	// other properties
	this.gr.penColor = "black";
}

Doodle.Canvas.prototype.getMousePos = function(evt) {
	var pos = dhtml.getElementPosition(this.divCanvas);
	var scroll = dhtml.getScrollPos();
	var x = evt.clientX - (pos.left - scroll.left);
	var y = evt.clientY - (pos.top - scroll.top);
		
	return {x:x, y:y};
}

Doodle.Canvas.prototype.onMouseDown = function(evt) {
	if ( !this.line ) {
		this.p1 = this.getMousePos(evt);
		this.p2 = this.p1;

		this.line = this.gr.drawLine(this.p1.x,this.p1.y,this.p2.x,this.p2.y);
	}
}
Doodle.Canvas.prototype.onMouseMove = function(evt) {
	if ( this.line ) {
		this.p2 = this.getMousePos(evt);
		this.line.undraw();
		this.line = this.gr.drawLine(this.p1.x,this.p1.y,this.p2.x,this.p2.y);
	}
}
Doodle.Canvas.prototype.onMouseUp = function(evt) {
	if ( this.line ) {
		this.document.createLine(this.p1,this.p2);

		delete this.p1;
		delete this.p2;
		delete this.line;
	}
}

//</script>