
	var DoublePair = Class.create();
	
	DoublePair.prototype = {
		
		nX: 0,
		nY: 0,
				
		initialize: function(nX,nY){
			this.nX = nX;
			this.nY = nY;
		},
		
		scale: function(nScaleFactor){
			this.nX *= nScaleFactor;
			this.nY *= nScaleFactor;
			return this;
		},
		
		translate: function(objVector){
			this.nX += objVector.nX;
			this.nY += objVector.nY;
			return this;
		},
		
		getLength: function(){
			return Math.sqrt(this.nX * this.nX  + this.nY * this.nY);
		},
		
		copy: function(){
			return new DoublePair(this.nX,this.nY);
		},
		
		compare: function(objDoublePair){
			var dX = this.nX - objDoublePair.nX;
			var dY = this.nY - objDoublePair.nY;
			return dX*dX + dY*dY; 
		},
		
		differs: function(objDoublePair){
			return (this.nX - objDoublePair.nX < -0.5) || (this.nX - objDoublePair.nX > 0.5) || (this.nY - objDoublePair.nY < -0.5) || (this.nY - objDoublePair.nY > 0.5	)
		}
		
	};

	var HairObject = Class.create();
	
	HairObject.prototype = {
		
		objRootPoint: null,
		objSecondPoint: null,
		objEndPoint: null,
		nRadius1: 0,
		nRadius2: 0,
		nHairLength: 0,
		sColor: '#62d1fa',
		
		initialize: function(objPoint,nAngle,nLength,nRadius1){
			var objVector = new DoublePair( Math.cos(nAngle)*nLength, Math.sin(nAngle)*nLength);
			this.nHairLength = nLength;
			this.objRootPoint = objPoint;
			this.objEndPoint = new DoublePair(objVector.nX,objVector.nY);
			this.objSecondPoint = objVector.scale(nRadius1 / this.nHairLength);
			this.nRadius1 = nRadius1;
			this.nRadius2 = this.nHairLength - nRadius1;
			delete objVector;
		},
		
		move: function(objMoveVector){
			var objPointBefore = this.objEndPoint.copy();
			var objReverseVector = new DoublePair(-objMoveVector.nX,-objMoveVector.nY);
			this.objEndPoint.translate(objReverseVector);
			var objMarkVector = new DoublePair(this.objEndPoint.nX - this.objSecondPoint.nX, this.objEndPoint.nY - this.objSecondPoint.nY);
			objMarkVector.scale( this.nRadius2 / objMarkVector.getLength() );
			this.objEndPoint.nX = this.objSecondPoint.nX + objMarkVector.nX;
			this.objEndPoint.nY = this.objSecondPoint.nY + objMarkVector.nY;
			
			delete objMarkVector;
			delete objReverseVector;
			//return objPointBefore.compare(this.objEndPoint) >= 0.5;
			return objPointBefore.differs(this.objEndPoint);
		},
		
		paint: function(objCanvasContext){
			objCanvasContext.strokeStyle = this.sColor;
			objCanvasContext.beginPath();
			objCanvasContext.moveTo(this.objRootPoint.nX,this.objRootPoint.nY);
			objCanvasContext.quadraticCurveTo(this.objRootPoint.nX+this.objSecondPoint.nX,this.objRootPoint.nY+this.objSecondPoint.nY,this.objRootPoint.nX+this.objEndPoint.nX,this.objRootPoint.nY+this.objEndPoint.nY);
			objCanvasContext.stroke();
		}

	};
	 