/**
 * @author jonas wilson
 */

function collisionManager()
{
	this.collidableArray = new Array();
	
}

collisionManager.prototype.createSquareCollidable = function( left, right, top, bottom)
{
	var sqare = new squareCollidable( left, right, top, bottom );
	this.collidableArray.push(sqare);
	return sqare;
};

collisionManager.prototype.createCircularCollidable = function( centerX, centerY, radius)
{
	var circle = new circularCollidable( centerX, centerY, radius);
	this.collidableArray.push(circle);
	return circle;
};

collisionManager.prototype.checkCollision = function(mouseCoordX, mouseCoordY)
{
	
	for(var i=0; i < this.collidableArray.length; ++i)
	{
		if (this.collidableArray[i].checkCollision(mouseCoordX, mouseCoordY))
		{
			return i;
		}
	}
	return -1;
};


function collidable()
{
}

collidable.prototype.checkCollision = function(mouseCoordX, mouseCoordY) 
{
	alert('impossible');
};

function circularCollidable(centerX, centerY, radius)
{
	collidable.call(this);
	
	this.centerX = centerX;
	this.centerY = centerY;
	this.radius = radius;
}

circularCollidable.prototype.checkCollision = function(mouseCoordX, mouseCoordY)
{
	var difx = (mouseCoordX - this.centerX);
	var dify = (mouseCoordY - this.centerY);
	var dif = Math.sqrt(Math.pow(difx, 2) + Math.pow(dify, 2));
	
	if( dif < this.radius)
		return true;
	else
		return false;
};

function squareCollidable(left, right, top, bottom)
{
	collidable.call(this);
	this.left = left;
	this.right = right;
	this.top = top;
	this.bottom = bottom;
}

squareCollidable.prototype.checkCollision = function(mouseCoordX, mouseCoordY)
{
	
	if (mouseCoordX > this.left &&
		mouseCoordX < this.right &&
		mouseCoordY > this.top &&
		mouseCoordY < this.bottom)
	{
		return true;
	}
	else
		return false;
};
