function fadeColour( fromcol, tocol, fadePortion ) {
if( fadePortion < 0 || fadePortion > 1 || isNaN( fadePortion ) ) {
window.defaultStatus = 'Fatal error: colour fader passed invalid portion - must be between 0 and 1';
return '#000000';
}
if( typeof( fromcol ) != 'string' || typeof( tocol ) != 'string' || fromcol.length < 6 || fromcol.length > 7 || tocol.length < 6 || tocol.length > 7 ) {
window.defaultStatus = 'Fatal error: colour fader passed invalid rrggbb hex colour value';
return '#000000';
}
if( fromcol.length == 7 ) { fromcol = fromcol.substring( 1, 7 ); }
if( tocol.length == 7 ) { tocol = tocol.substring( 1, 7 ); }
if( typeof( eval( '0x' + fromcol ) ) != 'number' || typeof( eval( '0x' + tocol ) ) != 'number' ) {
window.defaultStatus = 'Fatal error: colour fader passed invalid rrggbb hex colour value';
return '#000000';
}
for( var x = 0, oF = [], oT = [], oP = [], oH = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']; x < 3; x++ ) {
oF[x] = eval( '0x' + fromcol.substring( 2 * x, ( 2 * x ) + 2 ) ); oT[x] = eval( '0x' + tocol.substring( 2 * x, ( 2 * x ) + 2 ) );
oP[x] = Math.round( oF[x] + ( ( oT[x] - oF[x] ) * fadePortion ) ); oP[x] = oH[ ( oP[x] - ( oP[x] % 16 ) ) / 16 ] + oH[ oP[x] % 16 ];
}
return '#' + oP.join('');
}