//##############################################################################
//------------------------------------------------------------------------------
function Point(a, b)
{
    if(typeof(a) != 'undefined')
    {
        this.x = a;
        
        if(typeof(b) != 'undefined')
            this.y = b;
        else
            this.y = a;
    }
    else
    {
        this.x = 0;
        this.y = 0;
    }
}

//------------------------------------------------------------------------------
Point.prototype.isEqualTo = function(a)
{
	if(typeof(a.x) != 'undefined' && typeof(a.y) != 'undefined')
	{
		return (this.x == a.x && this.y == a.y);
	}
	else
	{
		return (this.x == a && this.y == a);
	}
}

//------------------------------------------------------------------------------
Point.prototype.add = function(a)
{
	if(typeof(a.x) != 'undefined' && typeof(a.y) != 'undefined')
	{
		this.x += a.x;
		this.y += a.y;
	}
	else
	{
		this.x += a;
		this.y += a;
	}
}

//------------------------------------------------------------------------------
Point.prototype.subtract = function(a)
{
	if(typeof(a.x) != 'undefined' && typeof(a.y) != 'undefined')
	{
		this.x -= a.x;
		this.y -= a.y;
	}
	else
	{
		this.x -= a;
		this.y -= a;
	}
}

//------------------------------------------------------------------------------
Point.prototype.multiply = function(a)
{
	if(typeof(a.x) != 'undefined' && typeof(a.y) != 'undefined')
	{
		this.x *= a.x;
		this.y *= a.y;
	}
	else
	{
		this.x *= a;
		this.y *= a;
	}
}

//------------------------------------------------------------------------------
Point.prototype.divide = function(a)
{
	if(typeof(a.x) != 'undefined' && typeof(a.y) != 'undefined')
	{
		this.x /= a.x;
		this.y /= a.y;
	}
	else
	{
		this.x /= a;
		this.y /= a;
	}
}

//------------------------------------------------------------------------------
Point.prototype.round = function()
{
	this.x = Math.round(this.x);
	this.y = Math.round(this.y);
}

//------------------------------------------------------------------------------
Point.prototype.normalize = function()
{
	var absX = Math.abs(this.x);
	var absY = Math.abs(this.y);
	
	var ratio;
	if(absX > absY)
		ratio = 1 / absX;
	else
		ratio = 1 / absY;
		
	this.x *= ratio;
	this.y *= ratio;
}

//------------------------------------------------------------------------------
Point.prototype.toString = function()
{
	return new String() + this.x + ',' + this.y;
}

