/**************************************************************************/
/****  Circle Class,  elements to be held in world stack               ****/
/**************************************************************************/

function Circle(x,y,r,c, a)
{
	this.x = x;//x cord
	this.y = y; //y cord
	this.r = r; //radius
	this.c = c; //color

	this.a = a; //Acceleration
	this.dx = Math.ceil((Math.random()*25)-12); //random Y acceleration




	//Draw object into world
	this.draw = function()
	{
		
		//Outine
		g.beginPath();
		g.fillStyle = "#FFF";
		g.arc(this.x, this.y, this.r, 0, Math.PI*2, true);
		g.closePath();
		g.fill();
		//use path and arc to make circle
		g.beginPath();
		g.fillStyle = this.c;
		g.arc(this.x, this.y, this.r-3, 0, Math.PI*2, true);
		g.closePath();
		g.fill();
		
		//The ball with radius of 70 is our special ball which gets text on it
		if(r==70){
		g.font = "bold 25px sans-serif";
		g.fillStyle = "#FFF"
		g.fillText("Click Me", this.x-50, this.y+5);
		
		}

	}
	
	
	//Return variable of specifed ball
	this.getX = function()
	{
		return this.x;
	}
	
	this.getY = function()
	{
		return this.y;
	}
	
	this.getR = function()
	{
		return this.r;
	}
	
	this.getA = function()
	{
		return this.a;
	}
	this.getC = function()
	{
		return this.c;
	}
	
	
	
	
	//Move function, generate physics and moves object.
	this.move = function()
	{	
		wall = false;	//wall flag	
			
		//Collision Detection of balls on Walls
			if((this.x+this.r) >= WIDTH || (this.x-this.r) <= 0)
			{
				this.dx = this.dx*-1;
			}
			
			if((this.y + this.r) >= HEIGHT )
			{
				wall = true;
				this.a = this.a*-1;
			}
			
			if((this.y - this.r) <= 0)
			{
			this.a = this.a*-1;
			}
			
			
			
			
			//Adjust Gravity Resrictions for this cycle
		
			if(this.a > 0)//Ball is moving down, gravity / interval
				this.a = this.a + 9.8/40;
			if(this.a < 0)//ball moving upward
				this.a = this.a + 9.8/20;//Gravit/interval + some extra resistance
	
				
	
			//Herizontal Restrictions: Air Friction
			if(this.dx != 0 && this.dx > 0)//if going to the right and not 0
				this.dx = this.dx - 1/35;
			else if(this.dx != 0 && this.dx < 0)//if going left and not 0
				this.dx = this.dx + 1/35;
			
			
			
		//Fianlly! We Can Move The Ball
			this.x += this.dx;//move horizontal	
			
			if(wall && this.a > 0)//hits lower wall and no acceleration
			{		
				this.y = HEIGHT - this.r;
				this.a = 0;
			}
			
			else
				this.y += this.a;
			
				

			
		
	}
	
	
}

