/* comp = name (ID="comp") of the HTML page component to fade
cbeg = start value for color in #rrggbb format
cend = end value for color in #rrggbb format
iter = number of steps in the fade from start color to end color
time = number of milliseconds to display each step
rbeg = start value for red component of rbg color
gbeg = start value for green component of rbg color
bbeg = start value for blue component of rbg color
rend = end value for red component of rbg color
gend = end value for green component of rbg color
bend = end value for blue component of rbg color */

var hstr = '#';
var hdig = "0123456789abcdef";
function mOvr(comp, cbeg, cend, iter, time) {
  var rbeg = hdig.indexOf(cbeg.substr(1,1))*16 + hdig.indexOf(cbeg.substr(2,1));
  var gbeg = hdig.indexOf(cbeg.substr(3,1))*16 + hdig.indexOf(cbeg.substr(4,1));
  var bbeg = hdig.indexOf(cbeg.substr(5,1))*16 + hdig.indexOf(cbeg.substr(6,1));
  var rend = hdig.indexOf(cend.substr(1,1))*16 + hdig.indexOf(cend.substr(2,1));
  var gend = hdig.indexOf(cend.substr(3,1))*16 + hdig.indexOf(cend.substr(4,1));
  var bend = hdig.indexOf(cend.substr(5,1))*16 + hdig.indexOf(cend.substr(6,1));
  for ( i = 1, r = rbeg, g = gbeg, b = bbeg;
    i <= iter;
    r = Math.round(rbeg + i * ((rend - rbeg) / (iter-1))),
    g = Math.round(gbeg + i * ((gend - gbeg) / (iter-1))),
    b = Math.round(bbeg + i * ((bend - bbeg) / (iter-1))), i++ )	 {
    hstr = '#' + hdig.charAt(Math.floor(r/16)) + hdig.charAt(r%16) +
      hdig.charAt(Math.floor(g/16)) + hdig.charAt(g%16) +
      hdig.charAt(Math.floor(b/16)) + hdig.charAt(b%16);
    setTimeout('var el = document.getElementById("' + comp + '"); el.style.backgroundColor = "' + hstr + '";', i * time);
  }
}

function mOut(comp, cbeg, cend, iter, time) {
  var rbeg = hdig.indexOf(cbeg.substr(1,1))*16 + hdig.indexOf(cbeg.substr(2,1));
  var gbeg = hdig.indexOf(cbeg.substr(3,1))*16 + hdig.indexOf(cbeg.substr(4,1));
  var bbeg = hdig.indexOf(cbeg.substr(5,1))*16 + hdig.indexOf(cbeg.substr(6,1));
  var rend = hdig.indexOf(cend.substr(1,1))*16 + hdig.indexOf(cend.substr(2,1));
  var gend = hdig.indexOf(cend.substr(3,1))*16 + hdig.indexOf(cend.substr(4,1));
  var bend = hdig.indexOf(cend.substr(5,1))*16 + hdig.indexOf(cend.substr(6,1));
  for ( i = 1, r = rend, g = gend, b = bend;
    i <= iter;
    r = Math.round(rend - i * ((rend - rbeg) / (iter-1))),
    g = Math.round(gend - i * ((gend - gbeg) / (iter-1))),
    b = Math.round(bend - i * ((bend - bbeg) / (iter-1))), i++ )	 {
    hstr = '#' + hdig.charAt(Math.floor(r/16)) + hdig.charAt(r%16) +
      hdig.charAt(Math.floor(g/16)) + hdig.charAt(g%16) +
      hdig.charAt(Math.floor(b/16)) + hdig.charAt(b%16);
    setTimeout('var el = document.getElementById("' + comp + '"); el.style.backgroundColor = "' + hstr + '";', i * time);
  }
}

