/*
	colour-selector.js
	
	For use in conjunction with an HTML page

	If you're going to use this on your own page, 
	you need to ensure that the ID's of your div tags are named consistently with this function
	(or you need to alter this function

	-------------------------------------------
	
	This program is Copyright 2006 Alec Harkness

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.


*/

function fUpdateColours(pColour, pValue) {

	vHex = "0123456789abcdef" ;
	pValue = parseInt( pValue ) ;

	for ( vRow = 0 ; vRow < 16 ; vRow++ ) {
		for ( vCell = 0 ; vCell < 16 ; vCell++ ) {

			if ( pColour == 'red' ) {
				vRed = vHex.substring(pValue,pValue+1) ;
				vGreen = vHex.substring(vRow,vRow+1) ;
				vBlue = vHex.substring(vCell,vCell+1) ;
			} else if ( pColour == 'green' ) {
				vRed = vHex.substring(vRow,vRow+1) ;
				vGreen = vHex.substring(pValue,pValue+1) ;
				vBlue = vHex.substring(vCell,vCell+1) ;
			} else if ( pColour == 'blue' ) {
				vRed = vHex.substring(vRow,vRow+1) ;
				vGreen = vHex.substring(vCell,vCell+1) ;
				vBlue = vHex.substring(pValue,pValue+1) ;
			}

			vColour = "#" + vRed + vGreen + vBlue ;

			vDivName = "Div" + '_' + vRow + '_' + vCell ;
			vDiv = document.getElementById(vDivName) ;

			vDiv.style.background = vColour ;
			vDiv.innerHTML = vColour ;

			vAvg = ( parseInt(vRed,16) + parseInt(vGreen,16) + parseInt(vBlue,16) ) / 3 ;
			vAvg = Math.round(15 - vAvg) ;
			vAvg = vHex.substring(vAvg,vAvg+1) ;
			vColour2 = '#' + vAvg + vAvg + vAvg ;

			vDiv.style.color = vColour2 ;



		}
	}

}
