// <![CDATA[

function hex2dec(thisColor){

var colRGB = new Array();
var colHEX = new Array();

colRGB[0] = thisColor.substr(0, 2);
colRGB[1] = thisColor.substr(2, 2);
colRGB[2] = thisColor.substr(4, 2);

colHEX[0] = parseInt(colRGB[0], 16);
colHEX[1] = parseInt(colRGB[1], 16);
colHEX[2] = parseInt(colRGB[2], 16);

return colHEX;
}

function gradient(message, colors, mode){

colors = colors.replace(/#/g, '');
colors = colors.split('-');
var output = "";
var Next = 0;

if(colors.length < 2){
output = message;
}
else{

var colLen = colors.length;
var messLen = message.length;
var startMess = 0;
var startNextMess = Math.ceil(messLen/(colLen-1));

for(i=0; i < colLen; i++){

thisText = message.substr(startMess, startNextMess);

if(colors[i] && colors [i+1]){

colFrom = hex2dec(colors[i]);
colTo = hex2dec(colors[i+1]);

textlength = thisText.length;
var r = (colFrom[0]-colTo[0])/textlength;
var g = (colFrom[1]-colTo[1])/textlength;
var b = (colFrom[2]-colTo[2])/textlength;

var AllHex = "0123456789ABCDEF";

for(l = 0;l < textlength; l++){

if(thisText.charAt(l) == "<")Next+=1;

if(Next == 0){
colFrom[0] -= r;
colFrom[1] -= g;
colFrom[2] -= b;

R = AllHex.charAt(Math.floor(colFrom[0]/16))+AllHex.charAt(colFrom[0]%16);
G = AllHex.charAt(Math.floor(colFrom[1]/16))+AllHex.charAt(colFrom[1]%16);
B = AllHex.charAt(Math.floor(colFrom[2]/16))+AllHex.charAt(colFrom[2]%16);

thisColor = R+G+B;
output += "<font color=\"#"+thisColor+"\">"+thisText.charAt(l)+"</font>";

}
else{
output += thisText.charAt(l);
}

if(thisText.charAt(l) == ">" && Next !== 0)Next -= 1;

}
}

startMess = startMess + startNextMess;
}

if(mode == 1){
return output;
}
else{
document.write(output);
}

}
}
// ]]>