var fader = new Array(), fadeQ = new Array();
var RGB = new Array(256), k = 0, hex = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
for (var i = 0; i < 16; i++) for (var j = 0; j < 16; j++) RGB[k++] = hex[i] + hex[j];
var is_getElementById   = (document.getElementById) ? "true" : "false";

var id = "fadito";
var actColorOff = "000066";
var actColorOn = "BFD5EA";
var direction = true;
var active = false;
var spdIn = 100; var spdOut = 100;
var colOff = [parseInt(actColorOff.substr(0, 2), 16), parseInt(actColorOff.substr(2, 2), 16), parseInt(actColorOff.substr(4, 2), 16)];
var colOn = [parseInt(actColorOn.substr(0, 2), 16), parseInt(actColorOn.substr(2, 2), 16), parseInt(actColorOn.substr(4, 2), 16)];
var colNow = [parseInt(actColorOff.substr(0, 2), 16), parseInt(actColorOff.substr(2, 2), 16), parseInt(actColorOff.substr(4, 2), 16)];


function fadeEng() {
  if (!active) {
    active = true;
    direction = direction;
    messageNow = document.getElementById(id).innerHTML;
  }
  // depending on direction choose which color and speed is the starting point
  var iniCol = (direction) ? colOff : colOn;
  var endCol = (direction) ? colOn : colOff;
  var incCol = colNow;
  var spd = (direction) ? spdIn : spdOut;
  for (var x = 0; x < 3; x++) {
    var incr = (endCol[x] - iniCol[x]) / spd;
    incCol[x] = (incr < 0) ? Math.max(incCol[x] + incr, endCol[x]) : Math.min(incCol[x] + incr, endCol[x]);
  }
  document.getElementById(id).style.color = "#" + RGB[parseInt(incCol[0])] + RGB[parseInt(incCol[1])] + RGB[parseInt(incCol[2])];
    
  if (incCol[0] == endCol[0] && incCol[1] == endCol[1] && incCol[2] == endCol[2]) {
  direction = !direction;  
  setTimeout("fadeEng();", 0);
  } else setTimeout("fadeEng();", 0);
}