// JavaScript Document

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);
}

function throbFade() {
  fade(2, Math.floor(throbStep / 2), (throbStep % 2) ? false : true);
  setTimeout("throbFade();", (throbStep % 2) ? 200 : 8000);
  if (++throbStep > fader[2].message.length * 2 - 1) throbStep = 0;
}

fader[2] = new fadeObj(2, 'fade2', '3b2415', 'f4e9cd', 50, 50, false);
fader[2].message[0] = "A smile is a curve that sets everything straight. ~Phyllis Diller";
fader[2].message[1] = "Don't count the days, make the days count.  ~Muhammad Ali";
fader[2].message[2] = "Wrinkles should merely indicate where smiles have been.  ~Mark Twain";
fader[2].message[3] = "Enjoy the little things, for one day you may look back and realize they were the big things.  ~Robert Brault";
fader[2].message[4] = "Start every day with a smile and get it over with.  ~W.C. Fields";
fader[2].message[5] = "Adam and Eve had many advantages, but the principal one was that they escaped teething.  ~Mark Twain";
fader[2].message[6] = "If you don't like something change it; if you can't change it, change the way you think about it.  ~Mary Engelbreit";
fader[2].message[7] = "Think big thoughts but relish small pleasures.  ~H. Jackson Brown, Jr.";
fader[2].message[8] = "The world always looks brighter from behind a smile.  ~Author Unknown";
fader[2].message[9] = "The impossible can always be broken down into possibilities.  ~Author Unknown";
fader[2].message[10] = "If you smile when no one else is around, you really mean it.  ~Andy Rooney";
fader[2].message[11] = "I have learned to use the word impossible with the greatest caution. <br />~Wernher von Braun";
fader[2].message[12] = "I've never seen a smiling face that was not beautiful.  ~Author Unknown";
fader[2].message[13] = "Always forgive your enemies; nothing annoys them so much - Oscar Wilde.";
fader[2].message[14] = "A laugh is a smile that bursts. <br />~Mary H. Waldrip";
fader[2].message[15] = "We cannot direct the wind but we can adjust the sails.  ~Author Unknown";
fader[2].message[16] = "Smile - sunshine is good for your teeth.  ~Author Unknown";
fader[2].message[17] = "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes.  ~Hugh Downs";
fader[2].message[18] = "You're never fully dressed without a smile.  ~Martin Charnin";
fader[2].message[19] = "A bargain is something you can't use at a price you can't resist.  ~Franklin P. Jones";
fader[2].message[20] = "Smile - it increases your face value. <br />~Author Unknown";
fader[2].message[21] = "People who snore always fall asleep first.  ~Author Unknown";
fader[2].message[22] = "A smile is a powerful weapon; you can even break ice with it.  ~Author Unknown";
fader[2].message[23] = "'Normal' is just a setting on the dryer.  ~Barbara Johnson";
fader[2].message[24] = "I am not young enough to know everything.  ~Oscar Wilde.";
fader[2].message[25] = "Most smiles are started by another smile.  ~Author Unknown";
fader[2].message[26] = "Nothing is as frustrating as arguing with someone who knows what he's talking about.  ~Sam Ewing";
fader[2].message[27] = "A smile is something you can't give away; it always comes back to you. <br />~Author Unknown";
fader[2].message[28] = "Our greatest glory is not in never falling, but in getting up every time we do.  ~Confucius";

var throbStep = 0;
setTimeout("throbFade();", 1000);

