// <script language="javascript">

var NaviArrayObjects 	= new Array;
var NaviArrayFadeState 	= new Array;
var NaviArraySize 		= 0;
var NaviFadeStateEnd 	= 15;
var NaviFadeStates		= new Array;
var NaviAllReady		= false;

function fade_state()
{
    var state;
	var color_s;

	this.state = 0;
	this.color_s = 0;
}


function NaviMouseOver( who )
{
  if( NaviAllReady )
  {
	NaviRemoveFromFade( who );
	who.style.cursor     = 'hand';
	who.style.background = '#243946';
  }
}

function NaviMouseOut( who, color_s )
{
  if( NaviAllReady )
  {
	if ( !color_s ) color_s = 0; 
	NaviAddFade( who, color_s );
	// who.style.background='#f0f0f0';
  }
}

function NaviRemoveFromFade( who )
{
  for ( i = 0; i <= NaviArraySize; i++ )
  {
    if ( NaviArrayObjects[ i ] == who ) 
	{
	  NaviArrayObjects[ i ]    = NaviArrayObjects[ NaviArraySize ];
	  NaviArrayFadeState[ i ]  = NaviArrayFadeState[ NaviArraySize ];
	  NaviArraySize--;
	}
  }
}

function NaviAddFade( who, color_s )
{
  NaviArraySize++;
  NaviArrayObjects[   NaviArraySize ] = who;
  NaviArrayFadeState[ NaviArraySize ] = new fade_state();
  NaviArrayFadeState[ NaviArraySize ].color_s = color_s;
  if ( NaviArraySize == 1 ) NaviUpdateFade();
}

function NaviUpdateFade()
{
  for ( i = 1; i <= NaviArraySize; i++ )
  {
    // alert( NaviArrayObjects[ i ] );
    NaviArrayFadeState[ i ].state++;
	NaviArrayObjects[ i ].style.background = NaviConvertToBackground( NaviArrayFadeState[ i ].state,  NaviArrayFadeState[ i ].color_s  );

	if ( NaviArrayFadeState[ i ].state == NaviFadeStateEnd ) 
	{
	  NaviRemoveFromFade( NaviArrayObjects[ i ] );
	  i--;
	}
  }
  
  if ( NaviArraySize > 0 ) setTimeout( 'NaviUpdateFade()', 50 );
}

function NaviConvertToBackground( state, color_s )
{
  return NaviFadeStates[ color_s ][ state ];
}

function NaviInitFadeStates( begin_color, end_color, number_of_states, color_s )
{
  
  if ( number_of_states )  NaviFadeStateEnd = number_of_states;
  
  NaviFadeStates[ color_s ] = new Array;
  r_now = HexToR( begin_color );
  g_now = HexToG( begin_color );
  b_now = HexToB( begin_color );
  
  r_trg = HexToR( end_color );
  g_trg = HexToG( end_color );
  b_trg = HexToB( end_color );
  
  r_add = ( r_trg - r_now ) / NaviFadeStateEnd;
  g_add = ( g_trg - g_now ) / NaviFadeStateEnd;
  b_add = ( b_trg - b_now ) / NaviFadeStateEnd;
  
  for( i = 0; i <= NaviFadeStateEnd; i++ )
  {
    NaviFadeStates[ color_s ][ i ] = RGBToHex( Math.round( r_now ), Math.round( g_now ), Math.round( b_now ) );
	r_now += r_add;
	g_now += g_add;
	b_now += b_add;
  }
  
  NaviAllReady = true;
}



// This works only with numbers between 0 and 255, so its 
// perfect for color convertions, but not much good for 
// anything else
function NumToHex( num )
{

  if ( num > 255 ) num = 255;
  first = 0;
  while ( num >= 16 )
  {
    first++;
	num -= 16;
  }
  
  hex_value = '';  
  
  hex_alphabets = new Array;
  hex_alphabets[ 10 ] = 'a';
  hex_alphabets[ 11 ] = 'b';
  hex_alphabets[ 12 ] = 'c';
  hex_alphabets[ 13 ] = 'd';
  hex_alphabets[ 14 ] = 'e';
  hex_alphabets[ 15 ] = 'f';
  
  if ( first < 10 ) hex_value = first + ''; 
  else hex_value = hex_alphabets[ first ];

  if ( num < 10 ) hex_value += num + '';
  else hex_value += hex_alphabets[ num ];
  
  return hex_value;
} 

function RGBToHex( r, g, b )
{
  return '#'+ NumToHex( r ) + NumToHex( g ) + NumToHex( b );
}


function HexToNumEasy( hex_value )
{
  return parseInt( hex_value, 16)
}

function HexToR( hex_value )
{
  if ( hex_value.charAt( 0 ) == '#' ) hex_value = hex_value.substring(1,7);
  return HexToNumEasy( hex_value.substring( 0, 2 ) );
}

function HexToG( hex_value )
{
  if ( hex_value.charAt( 0 ) == '#' ) hex_value = hex_value.substring(1,7);
  return HexToNumEasy( hex_value.substring( 2, 4 ) );
}

function HexToB( hex_value )
{
  if ( hex_value.charAt( 0 ) == '#' ) hex_value = hex_value.substring(1,7);
  return HexToNumEasy( hex_value.substring( 4, 6 ) );
}

/*
</script>
*/