/* author: Keith Atkins */
/* Creation date: 26/01/02 */
//------------------------------------- Merge colors  start ---------------------------------------*******
//Returns an array with 'sets' entries 1st is 'Col1' and last is 'Col2' and sets-2 between
window.mergeColors = mergeColors;
MC_ConA     = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','F')
function mergeColors(Col1,Col2,Sets) //-----------------------------------------------------------------------
{
Msg1 = "mergeColors - must be of the form #rrggbb in hex."
MC_Array    = new Array();
var ConA  = MC_ConA;
if (Sets == 0) {MC_Array[0]=Col1;MC_Array[1]=Col2;return MC_Array}
if (Sets <   0) {MC_Array[0]=Col1;return MC_Array}
// Process Col1
colArray1 = makeColorArray(Col1)
Red1   = colArray1[0]
Green1 = colArray1[1]
Blue1  = colArray1[2]
// Process Col2
colArray1 = makeColorArray(Col2)
Red2   = colArray1[0]
Green2 = colArray1[1]
Blue2  = colArray1[2]

dRed     = (Red2-Red1)/(Sets-1);
dGreen   = (Green2-Green1)/(Sets-1);
dBlue    = (Blue2-Blue1)/(Sets-1);
n = Sets;
for (i=0;i<n;i++)
  {
  R = ConA[Math.floor(Red1/16)]+ConA[Math.floor(Red1%16)];
  G = ConA[Math.floor(Green1/16)]+ConA[Math.floor(Green1%16)];
  B = ConA[Math.floor(Blue1/16)]+ConA[Math.floor(Blue1%16)];
  MC_Array[i] = "#"+R+G+B;
  Red1   +=dRed;
  if (Red1 < .1) Red1=0;
  Green1 +=dGreen;
  if (Green1 < .1) Green1=0;
  Blue1  +=dBlue;
  if (Blue1 < .1) Blue1=0; 
  }
return MC_Array;
}
//------------------------------------------------------------
function makeColorArray(colStr)
{
var A = new Array()
colStr = colStr.toLowerCase()
if (colStr.substr(0,1) == "#")
	{
	A[0]  = parseInt(colStr.slice(1,3),16)
	A[1]  = parseInt(colStr.slice(3,5),16)
	A[2]  = parseInt(colStr.slice(5,7),16)
	}
	else
	{
	if (colStr.substr(0,3) != "rgb"){alert("mergeColors - invalid color "+colStr);return}
	B    = colStr.split("(")
	B[1] = B[1].replace(")","")
	A    = B[1].split(",")
	A[0] = parseInt(A[0])
	A[1] = parseInt(A[1])
	A[2] = parseInt(A[2])
	}
return A
}
//---------------- Merge colors End -----------------------------------------

