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];

function fadeObj(number, id, colOff, colOn, spdIn, spdOut, def) {
  this.number = number;
  this.id = id;
  this.colOff = [parseInt(colOff.substr(0, 2), 16), parseInt(colOff.substr(2, 2), 16), parseInt(colOff.substr(4, 2), 16)];
  this.colOn = [parseInt(colOn.substr(0, 2), 16), parseInt(colOn.substr(2, 2), 16), parseInt(colOn.substr(4, 2), 16)];
  this.colNow = [parseInt(colOff.substr(0, 2), 16), parseInt(colOff.substr(2, 2), 16), parseInt(colOff.substr(4, 2), 16)];
  this.spdIn = spdIn;
  this.spdOut = spdOut;
  this.def = def;
  this.direction = false;
  this.active = false;
  this.message = new Array();
  this.messageNow = 0;
}

function fadeCmd(number, message, direction) {
  this.number = number;
  this.message = message;
  this.direction = direction;
}

function fade(number, message, direction) {
  if (fader[number].def && fader[number].messageNow == 0 && fader[number].direction) {
    fadeQ[fadeQ.length] = new fadeCmd(number, 0, false);
    fadeQ[fadeQ.length] = new fadeCmd(number, message, direction);
    message = 0;
    direction = false;
  } else fadeQ[fadeQ.length] = new fadeCmd(number, message, direction);
  setTimeout(function() { fadeBegin(number); }, 20);
}

function fadeBegin(number) {
  for (var x = 0; x < fadeQ.length; x++) {
    for (var y = x + 1; y < fadeQ.length; y++) {
      if (fadeQ[x].number == fadeQ[y].number && fadeQ[x].message == fadeQ[y].message && fadeQ[x].direction != fadeQ[y].direction) {
        fadeQ.splice(x, 1);
        fadeQ.splice(y - 1, 1);
      }
    }
  }
  if (!fader[number].active) {
    for (var x = 0; x < fadeQ.length; x++) {
      if (fadeQ[x].number == number && fadeQ[x].direction != fader[number].direction) {
        var del = fadeQ.splice(x, 1);
        setTimeout(function() { fadeEng(number, del[0].message, del[0].direction); }, 0);
        break;
      }
    }
  }
}

function fadeEng(number, message, direction) {
  if (!fader[number].active) {
    fader[number].active = true;
    fader[number].direction = direction;
    fader[number].messageNow = message;
    document.getElementById(fader[number].id).innerHTML = fader[number].message[message];
  }
  var iniCol = (direction) ? fader[number].colOff : fader[number].colOn;
  var endCol = (direction) ? fader[number].colOn : fader[number].colOff;
  var incCol = fader[number].colNow;
  var spd = (direction) ? fader[number].spdIn : fader[number].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(fader[number].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]) {
    fader[number].active = false;
    for (var x = 0; x < fadeQ.length; x++) {
      if (fadeQ[x].number == number) {
        var del = fadeQ.splice(x, 1);
        setTimeout(function() { fadeEng(number, del[0].message, del[0].direction); }, 0);
        return false;
      }
    }
    if (!direction) {
      if (fader[number].def) {
        setTimeout(function() { fadeEng(number, 0, true); }, 0);
      } else document.getElementById(fader[number].id).innerHTML = "&nbsp;";
    }
  } else setTimeout(function() { fadeEng(number, message, direction); }, 0);
}
var throbStep = new Array();
function throbFade(item) {
  if (!throbStep[item]) throbStep[item] = 0;
  fade(item, Math.floor(throbStep[item] / 2), (throbStep[item] % 2) ? false : true);
  setTimeout(function() { throbFade(item); }, (throbStep[item] % 2) ? 100 : 15000);
  if (++throbStep[item] > fader[item].message.length * 2 - 1) throbStep[item] = 0;
}

fader[2] = new fadeObj(2, 'fade', 'EEEEEE', '2B2B2B', 50, 50, false);
fader[2].message[0] = "&quot;We like the individual attention and the personal service we receive. Pam Landon’s consciousness to detail and integrity brought us to TD&T Financial Group, P.C. They know us by first name, and for a small company like ours, that’s important. TD&T’s people make the difference.&quot;";
fader[2].message[1] = "&quot;We like having a smaller firm taking care of our finances because I feel they really care about us. In a huge firm you are just a number and nobody really knows who you are. If you call the office, a real person answers the phone and that’s hard to find these days.&quot;";
fader[2].message[2] = "&quot;Thanks to TD&T Financial Group, P.C., we have a complete and accurate financial picture of our company at all times.&quot;";
fader[2].message[3] = "&quot;The expert auditing services provided by TD&T Financial Group, P.C. helps us cut the wheat from the chaff.&quot;";
fader[2].message[4] = "&quot;Our relationship with TD&T began with an audit of our financial records.  We were very pleased with the end result.  The detailed audit report they provided was easy to understand and workable.  It was obvious to us that TD&T understood the needs of non-profit organizations.  They provide the service and information we need to be able to focus our efforts on preserving, nurturing and protecting our historical agricultural treasures for future generations to enjoy.&quot;";
fader[2].message[5] = "&quot;Our company had grown in size and we needed an accounting firm with experience in the trucking industry to help our small business operate at full capacity. After visiting with TD&T we found them very personable and knowledgeable of the industry, resulting in a positive operational path for our business.  Another benefit of working with TD&T is having one on one interaction with our accountant; this allows financial information to be discussed freely, resulting in the best possible decision for our company’s growth.&quot;";

setTimeout(function() { throbFade(2); }, 1000);