/* Nav menu Page colour wheel configuration */ 
function navPageCW( ) {
	this.entity = '#nav-cw-div';
	this.label = '#nav-cw-label';
	this.xoffset = 140;
	this.yoffset = 140;
	this.radius  = 91;
	
	this.innerRadiusInactive = 20;
	this.innerRadiusActive = 26;
	this.middleRadiusInactive = 52;
	this.middleRadiusActive = 70;
	this.outerRadiusInactive = 91;
	this.outerRadiusActive = 109;
	
	this.colours = [ 'multicoloured',
					 'brown',
					 'black',
					 'white',
					 'beige',
					 'mid-brown',
					 'red-orange',
					 'orange',
					 'light-orange',
					 'yellow',
					 'light-green',
					 'green',
					 'blue-green',
					 'blue',
					 'blue-violet',
					 'purple',
					 'pink',
					 'red'
					  ];
}

navPageCW.prototype.doOverlay = function( section, action ){
	if ( section >=0 && section <= this.colours.length ) {
		$('#nav-cw-'+section).css( "display", action );
	}
}


navPageCW.prototype.GetInnerSection = function( currentPolarCoords ){
	return 0;
}

navPageCW.prototype.GetMiddleSection = function( currentPolarCoords ){
	if ( currentPolarCoords.degrees <=6 || currentPolarCoords.degrees > 294 )
	{
		return 1;
	}
	return 1 + Math.round( ( currentPolarCoords.degrees +29 ) / 72 );
}

navPageCW.prototype.GetOuterSection = function( currentPolarCoords ){
	if ( currentPolarCoords.degrees <=15 || currentPolarCoords.degrees > 345 )
	{
		return 6;
	}
	return 6 + Math.round( ( currentPolarCoords.degrees - 3) / 30 );
}


navPageCW.prototype.GetNewState = function( oldState, currentPolarCoords ){
	var newState = new ColourWheelState();
	

	if ( oldState.innerAreaActive == true )
	{
		if ( currentPolarCoords.radius <= this.innerRadiusActive ){
			newState.active = true;
			newState.innerAreaActive = true;
			newState.section = this.GetInnerSection( currentPolarCoords );
		}
		else if ( currentPolarCoords.radius <= this.middleRadiusInactive ){
			newState.active = true;
			newState.middleAreaActive = true;
			newState.section = this.GetMiddleSection( currentPolarCoords );
		}
		else if ( currentPolarCoords.radius <= this.outerRadiusInactive ){
			newState.active = true;
			newState.outerAreaActive = true;
			newState.section = this.GetOuterSection( currentPolarCoords );
		}
	}
	else if ( oldState.middleAreaActive == true ) {
		if ( currentPolarCoords.radius <= this.innerRadiusInactive ){
			newState.active = true;
			newState.innerAreaActive = true;
			newState.section = this.GetInnerSection( currentPolarCoords );
		}
		else if ( currentPolarCoords.radius <= this.middleRadiusActive ){
			newState.active = true;
			newState.middleAreaActive = true;
			newState.section = this.GetMiddleSection( currentPolarCoords );
		}
		else if ( currentPolarCoords.radius <= this.outerRadiusInactive ){
			newState.active = true;
			newState.outerAreaActive = true;
			newState.section = this.GetOuterSection( currentPolarCoords );
		}
	}
	else if ( oldState.outerAreaActive == true ) {
		if ( currentPolarCoords.radius <= this.innerRadiusInactive ){
			newState.active = true;
			newState.innerAreaActive = true;
			newState.section = this.GetInnerSection( currentPolarCoords );
		}
		else if ( currentPolarCoords.radius <= this.middleRadiusInactive ){
			newState.active = true;
			newState.middleAreaActive = true;
			newState.section = this.GetMiddleSection( currentPolarCoords );
		}
		else{
			var hoverSection = this.GetOuterSection( currentPolarCoords );
			if ( oldState.section == hoverSection ) {
				if ( currentPolarCoords.radius <= this.outerRadiusActive ){
					newState.active = true;
					newState.outerAreaActive = true;
					newState.section = this.GetOuterSection( currentPolarCoords );
				}
			}
			else
			{
				if ( currentPolarCoords.radius <= this.outerRadiusInactive ){
					newState.active = true;
					newState.outerAreaActive = true;
					newState.section = this.GetOuterSection( currentPolarCoords );
				}
			}
		}
	}
	else
	{
		if ( currentPolarCoords.radius <= this.innerRadiusInactive ){
			newState.active = true;
			newState.innerAreaActive = true;
			newState.section = this.GetInnerSection( currentPolarCoords );
		}
		else if ( currentPolarCoords.radius <= this.middleRadiusInctive ){
			newState.active = true;
			newState.middleAreaActive = true;
			newState.section = this.GetMiddleSection( currentPolarCoords );
		}
		else if ( currentPolarCoords.radius <= this.outerRadiusInactive ){
			newState.active = true;
			newState.outerAreaActive = true;
			newState.section = this.GetOuterSection( currentPolarCoords );
		}
	}

	return newState;
}



navPageCW.prototype.processMovement = function( oldState, newState ){

	if( newState.section != oldState.section )
	{
		$(this.label).html( '&nbsp;' );

		if ( ( newState.section >= 0 ) && ( newState.section < this.colours.length ) ) {
			$(this.label).html( this.colours[newState.section] );
		}
		this.doOverlay( oldState.section, "none" );
		this.doOverlay( newState.section, "block" );
	}
}


navPageCW.prototype.addImages = function( target, sectionName, searchType ){    
	
	if( sectionName != '' ) {
		sectionName = '' + sectionName + ''	
	}
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/white/" title="multicoloured"><img id="nav-cw-0" src="/template/colour-wheel/multicoloured.png" alt="" width="54" height="54" />' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/brown/" title="brown"><img id="nav-cw-1" src="/template/colour-wheel/brown.png" alt="" width="63" height="71" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/black/" title="black"><img id="nav-cw-2" src="/template/colour-wheel/black.png" alt="" width="66" height="68" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/white/" title="white"><img id="nav-cw-3" src="/template/colour-wheel/white.png" alt="" width="77" height="60" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/beige/" title="beige"><img id="nav-cw-4" src="/template/colour-wheel/beige.png" alt="" width="57" height="89" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/mid-brown/" title="mid-brown"><img id="nav-cw-5" src="/template/colour-wheel/mid-brown.png" alt="" width="81" height="58" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/red-orange/" title="red-orange"><img id="nav-cw-6" src="/template/colour-wheel/red-orange.png" alt="" width="60" height="58" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/orange/" title="orange"><img id="nav-cw-7" src="/template/colour-wheel/orange.png" alt="" width="70" height="66" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/light-orange/" title="light-orange"><img id="nav-cw-8" src="/template/colour-wheel/light-orange.png" alt="" width="65" height="69" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/yellow/" title="yellow"><img id="nav-cw-9" src="/template/colour-wheel/yellow.png" alt="" width="58" height="59" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/light-green/" title="light-green"><img id="nav-cw-10" src="/template/colour-wheel/yellow-green.png" alt="" width="66" height="69"/></a>' ); 
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/green/" title="green"><img id="nav-cw-11" src="/template/colour-wheel/green.png" alt="" width="69" height="65" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/blue-green/" title="blue-green"><img id="nav-cw-12" src="/template/colour-wheel/blue-green.png" alt="" width="59" height="58" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/blue/" title="blue"><img id="nav-cw-13" src="/template/colour-wheel/blue.png" alt="" width="69" height="66" /></a>' ); 
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/blue-violet/" title="blue-violet"><img id="nav-cw-14" src="/template/colour-wheel/blue-violet.png" alt="" width="65" height="69" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/purple/" title="purple"><img id="nav-cw-15" src="/template/colour-wheel/violet.png" alt="" width="58" height="59" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/pink/" title="pink"><img id="nav-cw-16" src="/template/colour-wheel/violet-red.png" alt="" width="66" height="70" /></a>' );
	document.write('<a href="' + target + '' + sectionName + '' + searchType + '/red/" title="red"><img id="nav-cw-17"  src="/template/colour-wheel/red.png" alt="red" width="69" height="65" /></a>');
}


