/**
 * @author Dylan Oudyk
 * 
 * Please refer to SVG path documentation for a 
 * complete reference of the different path commands
 * http://www.w3.org/TR/SVG/paths.html#PathData
 * 
 */
function Path(){
	this._pathData = [];
}

Path.begin = function(){
	return new Path();
};

Path.prototype = {
	/**
	 * override of toString
	 */
	toString : function(){
		return this._pathData ? this._pathData.join(' ') : '';
	},
	
	/**
	 * @private
	 * adds data into the path data array
	 */
	addData : function (){
		this._pathData.push (this._pathData.join.call(arguments, ' '));
		return this;
	},
	
	/**
	 * Absolute coordinates
	 * Move to command
	 * @param {Number} x
	 * @param {Number} y
	 */
	MoveTo : function(x, y){
		return this.addData ('M', x, y);		
	},
	
	/**
	 * Relative coordinates
	 * Move to command
	 * @param {Number} x
	 * @param {Number} y
	 */
	moveTo : function(x, y){
		return this.addData ('m', x, y);		
	},
	
	/**
	 * Absolute coordinates
	 * Line to command
	 * @param {Number} x
	 * @param {Number} y
	 */
	LineTo : function (x, y){
		return this.addData ('L', x, y);
	},
	
	/**
	 * Line to command
	 * @param {Number} x
	 * @param {Number} y
	 */
	lineTo : function (x, y){
		return this.addData ('l', x, y);
	},
	
	/**
	 * Absolute coordinates
	 * Horizontal line to
	 * @param {Object} x
	 */
	Horizontal: function(x){
		return this.addData ('H', x);
	},
	
	/**
	 * Relative coordinates
	 * horizontal line to
	 * @param {Object} x
	 */
	horizontal : function(x){
		return this.addData('h', x);
	},
	
	/**
	 * Absolute coordinates,
	 * Vertical line to
	 * @param {Object} y
	 */
	Vertical : function(y){
		return this.addData('V', y);
	},
	
	/**
	 * Relative coordinates
	 * vertical line to
	 * @param {Object} y
	 */
	vertical : function(y){
		return this.addData('v', y);
	},
	
	/**
	 * Absolute coordinates
	 * Cubic bezier curve to
	 * @param {Number} x1
	 * @param {Number} y1
	 * @param {Number} x2
	 * @param {Number} y2
	 * @param {Number} x
	 * @param {Number} y
	 */
	CurveToCubic : function(x1, y1, x2, y2, x, y){
		return this.addData('C', x1, y1, x2, y2, x, y);		
	},
	
	/**
	 * Relative coordinates
	 * Cubic bezier curve to
	 * @param {Number} x1
	 * @param {Number} y1
	 * @param {Number} x2
	 * @param {Number} y2
	 * @param {Number} x
	 * @param {Number} y
	 */
	curveToCubic : function(x1, y1, x2, y2, x, y){
		return this.addData('c', x1, y1, x2, y2, x, y);		
	},
	
	/**
	 * Absolute coordinates
	 * shorthand cubic bezier curve to
	 * @param {Number} x2
	 * @param {Number} y2
	 * @param {Number} x
	 * @param {Number} y
	 */
	CurveToCubicShort : function (x2, y2, x, y){
		return this.addData('S', x2, y2, x, y);
	},
	
	/**
	 * relative coordinates
	 * shorthand cubic bezier curve to
	 * @param {Number} x2
	 * @param {Number} y2
	 * @param {Number} x
	 * @param {Number} y
	 */
	curveToCubicShort : function (x2, y2, x, y){
		return this.addData('s', x2, y2, x, y);
	},
	
	/**
	 * Absolute coordinates
	 * Quadratic Bezier curve
	 * @param {Number} x1
	 * @param {Number} y1
	 * @param {Number} x
	 * @param {Number} y
	 */
	CurveToQuadratic : function (x1, y1, x, y){
		return this.addData ('Q', x1, y1, x, y);
	},
	
	/**
	 * Relative coordinates
	 * Quadratic Bezier curve
	 * @param {Number} x1
	 * @param {Number} y1
	 * @param {Number} x
	 * @param {Number} y
	 */
	curveToQuadratic : function (x1, y1, x, y){
		return this.addData ('q', x1, y1, x, y);
	},
	
	/**
	 * Absolute coordinates
	 * Quadratic Bezier curve shorthand
	 * @param {Object} x
	 * @param {Object} y
	 */
	CurveToQuadraticShort : function (x, y){
		return this.addData ('T', x, y);
	},
	
	/**
	 * relative coordinates
	 * Quadratic Bezier curve shorthand
	 * @param {Object} x
	 * @param {Object} y
	 */
	curveToQuadraticShort : function (x, y){
		return this.addData ('t', x, y);
	},
	
	EllipticalArc : function (rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y){
		return this.addData ('A', rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y);
	},
	
	ellipticalArc : function (rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y){
		return this.addData ('a', rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y);
	},
	
	/**
	 * Closes the path
	 */
	close : function(){
		return this.addData ('z');
	}
};
