///////////////////////////////
// Modified 9-05 by colm.
//
//Modified to use paths instead 
// of the built in SVG line object
///////////////////////////////

/***************************************
  SIMPLE LINE SHAPE
***************************************/
Line.prototype = new Shape();
Line.prototype.constructor = Line;
Line.superclass = Shape.prototype;
function Line(x1,y1,x2,y2,tmp,draw){
  if (arguments.length > 0) {
    this.init(x1,y1,x2,y2,tmp,draw);
  }
}
Line.prototype.init = function ( x1, y1, x2, y2, tmp, draw) {
  if (debugLevel >= 20)
	 	debug("LINE : init line");
  Line.superclass.init.call( this, null, tmp );
  this.handles[0] = new Handle( x1, y1, this );
  this.handles[1] = new Handle( x2, y2, this );
  if (draw) {
    this.make();
  }
}
Line.prototype.make = function(){
  if (debugLevel >= 20)
		debug("LINE : make line");

  this.svgNode = svgDoc.createElement("path");
  this.svgNode.addEventListener( "click", this, false );
  style = this.svgNode.getStyle();
  style.setProperty("fill", fillColor);
  style.setProperty("stroke", strokeColor);
  style.setProperty("stroke-width", strokeWidth);
  drawingGroup.appendChild(this.svgNode);
	var pathstring = "M " + this.handles[0].point.x + " " + this.handles[0].point.y + ", L " 
											 + this.handles[1].point.x + " " + this.handles[1].point.y + ", Z ";
	this.svgNode.setAttribute("d", pathstring);										 
	this.svgNode.setAttribute("id", "line");
}

Line.prototype.update = function( x1, y1, x2, y2) {
  if (arguments.length > 0){
    this.handles[0].moveto( x1, y1 );
    this.handles[1].moveto( x2, y2 );
  }
	var pathstring = "M " + this.handles[0].point.x + " " + this.handles[0].point.y + ", L " 
											 + this.handles[1].point.x + " " + this.handles[1].point.y + ", Z ";
	this.svgNode.setAttribute("d", pathstring);
}

Line.prototype.tempLine = function(){
  this.svgNode.setAttribute( "style", "stroke-width:1; stroke:black; stroke-dasharray:5,5");
}
Line.prototype.destructor = function(){
  if (debugLevel >= 20)
		debug("LINE : destructor");
  this.svgNode.parentNode.removeChild( this.svgNode );
  delete this.svgNode;
	for(var k = 0; k < this.handles.length; k++)
  	delete this.handles[k];
}


Line.prototype.debug = function(){
  alert("This line exists");
}

