function ColourWheelState( ) {
	this.active = false;
	this.innerAreaActive = false;
	this.middleAreaActive = false;
	this.outerAreaActive = false;
	this.section = -1;
}


function ColourWheel( cwConfig )
{
	this.processing = false;
	this.config = cwConfig;
	this.state = new ColourWheelState();
}



ColourWheel.prototype.NewState = function( e, offset )
{
	var mousePosition = new MouseCoordinates( e, offset, this.config.xoffset, this.config.yoffset );
	var currentPolarCoords = new PolarCoordinates( mousePosition );
	var newState = this.config.GetNewState( this.state, currentPolarCoords );
	return newState;
}


ColourWheel.prototype.MouseMoved = function( e, offset )
{
	if ( this.processing == true )
		return;
		
	this.processing = true;
	
	newState = this.NewState( e, offset );

	this.config.processMovement( this.state, newState );
	
	this.state.active = newState.active;
	this.state.innerAreaActive = newState.innerAreaActive;
	this.state.middleAreaActive = newState.middleAreaActive;
	this.state.outerAreaActive = newState.outerAreaActive;
	this.state.section = newState.section;

	this.processing = false;
}	

function MouseCoordinates( e, offset, xoffset, yoffset )
{
	this.x = ( e.pageX - (offset.left) ) - xoffset;
	this.y = yoffset + ( 0 - ( Math.abs( Math.round( e.pageY - (offset.top) ) ) ) );
}

function PolarCoordinates( mouseCoords )
{	
	this.radius = 0;
	this.t = 0;
	this.degrees = 0;
	
	this.radius = Math.sqrt( Math.pow(mouseCoords.x,2) + Math.pow(mouseCoords.y,2) );

	if ( mouseCoords.x==0 && mouseCoords.y==0 )		{ this.t = 0; }
	else if ( mouseCoords.x>0 )			{ this.t = Math.atan( mouseCoords.y/mouseCoords.x ); }
	else if ( mouseCoords.x<0 && mouseCoords.y>=0 )	{ this.t = Math.atan( mouseCoords.y/mouseCoords.x ) + Math.PI; }
	else if ( mouseCoords.x<0 && mouseCoords.y<0 )	{ this.t = Math.atan( mouseCoords.y/mouseCoords.x ) - Math.PI; }
	else if ( mouseCoords.x==0 && mouseCoords.y>0 )	{ this.t = Math.PI/2; }
	else if ( mouseCoords.x==0 && mouseCoords.y<0 )	{ this.t = 0-( Math.PI/2 ); }
	
	if ( this.t >= 0 )
	{
		this.degrees = Math.round( this.t * ( 180 / Math.PI ) );
	}
	else
	{
		this.degrees = Math.round( 180 + ( 180 - Math.abs(this.t) * ( 180 / Math.PI ) ) );
	}
	this.radius = Math.round( this.radius );
}	

	
	
