/* ********************************************************************
* Buffered Text-fade Effect - v3.0
* - Copyright 2008 - Licenced for free distribution under the BSDL
*   - http://www.opensource.org/licenses/bsd-license.php
******************************************************************** */

function fadeObject(id, c1, c2, s1, s2) {
  var self = this;
  this.id      = id;
  this.elem    = false;
  this.colour  = {
    stt: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)],
    end: [parseInt(c2.substr(0, 2), 16), parseInt(c2.substr(2, 2), 16), parseInt(c2.substr(4, 2), 16)],
    now: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)]
  };
  this.steps   = [s1, s2];
  this.dir     = false;
  this.active  = false;
  this.queue   = [];
  this.msg     = [];
  this.message = 0;
  function d2h(num) {
    num = Math.round(num);
    return ((num < 16) ? "0" : "") + num.toString(16);
  }
  this.fade = function(message, direction) {
    this.elem = this.elem || document.getElementById(this.id);
    this.queue.push([message, direction]);
    for (var x = 0; x < this.queue.length; x++) {
      for (var y = x + 1; y < this.queue.length; y++) {
        if (this.queue[x][0] == this.queue[y][0] && this.queue[x][1] != this.queue[y][1]) {
          this.queue.splice(x, 1);
          this.queue.splice(y - 1, 1);
        }
      }
    }
    if (!this.active) setTimeout(function() { self.fadeLoop(); }, 0);
  };
  this.fadeLoop = function() {
    if (!this.active && this.queue.length) {
      if (this.dir && this.message != this.queue[0][0]) this.queue.unshift([this.message, false]);
      var msg = this.queue.shift();
      if (this.msg[msg[0]]) {
        this.active = true;
        this.elem.innerHTML = this.msg[this.message = msg[0]];
        this.dir = msg[1];
      }
    }
    if (this.dir) {
      var c1 = this.colour.stt, c2 = this.colour.end, s = this.steps[0];
    } else var c1 = this.colour.end, c2 = this.colour.stt, s = this.steps[1];
    for (var x = 0, cnow = "", inc = 0; x < 3; x++) {
      this.colour.now[x] += inc = (c2[x] - c1[x]) / s;
      cnow += this.colour.now[x] = (inc < 0) ? Math.max(this.colour.now[x], c2[x]) : Math.min(this.colour.now[x], c2[x]);
    } this.elem.style.color = "#" + d2h(this.colour.now[0]) + d2h(this.colour.now[1]) + d2h(this.colour.now[2]);
    if (cnow == c2.join("")) {
      this.active = false;
      if (!this.queue.length) {
        if (!this.dir) {
          if (this.msg[0]) {
            this.queue.push([0, true]);
            setTimeout(function() { self.fadeLoop(); }, 0);
          } else this.elem.innerHTML = "&nbsp;";
        }
      } else setTimeout(function() { self.fadeLoop(); }, 0);
    } else setTimeout(function() { self.fadeLoop(); }, 0);
  };
  if (window.addEventListener) {
    window.addEventListener('load', function() { self.fade(0, true); }, false); 
  } else if (window.attachEvent)
    window.attachEvent('onload', function() { self.fade(0, true); });
}


var fader = new Array();

fader[0] = new fadeObject('fade0', 'dddddd', '000000', 20, 20);
fader[0].msg[0] = "This is an optional default message; the fade object on the right side has no default.  Mouseover each topic to make quotes fade in and out.";
fader[0].msg[1] = "Nowhere can a man find a quieter or more untroubled retreat than in his own soul.<br />- Marcus Aurelius";
fader[0].msg[2] = "Feeding the starving poor only increases their number.<br />- Ben Bova";
fader[0].msg[3] = "The limits of tyrants are prescribed by the endurance of those whom they oppose.<br />- Frederick Douglass";
fader[0].msg[4] = "The foolish man seeks happiness in the distance, the wise grows it under his feet.<br />- James Oppenheim";

fader[1] = new fadeObject('fade1', 'bbbbbb', '000000', 20, 20);
fader[1].msg[1] = "Success is relative. It is what we can make of the mess we have made of things.<br />- T.S. Eliot";
fader[1].msg[2] = "We have two ears and one mouth so we may listen more and talk the less.<br />- Epictetus";
fader[1].msg[3] = "It is better to be violent, if there is violence in our hearts, than to put on the cloak of nonviolence to cover impotence.<br />- Mahatma Gandhi";
fader[1].msg[4] = "Don't part with your illusions. When they are gone you may still exist, but you have ceased to live.<br />- Mark Twain";


var hash = new Array();
function throb(item) {

  // If the hash array does not have an entry for this item, initialise it at 2
  if (!hash[item]) hash[item] = 2;

  // Send a fade command using the hash array to tell us what parameters we should use
  fader[item].fade(Math.floor(hash[item] / 2), !(hash[item] % 2));

  // Call this function again for this same item after a certain amount of time
  setTimeout(function() { throb(item); }, (hash[item] % 2) ? 100 : 15000);

  // If we have exceeded the number of messages in this fader, start over again at 2
  if (++hash[item] > fader[item].msg.length * 2 - 1) hash[item] = 2;
}

fader[2] = new fadeObject('fade2', 'acacac', '232936', 30, 30);
fader[2].msg[1] = "<span style='background: url(images/quoteleft.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='line-height: 145%; font-size: 14px; font-style: italic;'>Anne Stern is the perfect recording engineer. She's extremely professional and easy to work with. She is not satisfied until you and she have created the best possible recording. If you want to sound your best (and then some), you want to work with Anne. I cannot imagine working with another producer.&nbsp;</span><span style='background: url(images/quoteright.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><br><span style='line-height: 145%; font-size: 14px;'>&mdash; </span><span style='font-size: 85%;'>Stephen Nelson, client of Stern Studios</span>";
fader[2].msg[2] = "<span style='background: url(images/quoteleft.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='line-height: 145%; font-size: 14px; font-style: italic;'>Anne Stern has masterfully engineered several live recordings of the Stanford Institute Choir. One of my soloists commented that he preferred her recordings to those done while he was in the Chamber Chorale, Stanford's foremost vocal ensemble.&nbsp;</span><span style='background: url(images/quoteright.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><br><span style='line-height: 145%; font-size: 14px;'>&mdash; </span><span style='font-size: 85%;'>Elizabeth Brimhall, Director, Stanford Institute Choir</span>";
fader[2].msg[3] = "<span style='background: url(images/quoteleft.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='line-height: 145%; font-size: 14px; font-style: italic;'>Anne knows her way around ProTools like white on rice. She's got amazing technical skills, a knack for arranging, and the creativity of the constantly curious. Not only do I admire her shiny brain, she's got a lovely voice, great chops, and she's a heckuva nice gal too.&nbsp;</span><span style='background: url(images/quoteright.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><br><span style='line-height: 145%; font-size: 14px;'>&mdash; </span><span style='font-size: 85%;'>Kathy Goll-Derstine, singer, songwriter, and client of Stern Studios</span>";
fader[2].msg[4] = "<span style='background: url(images/quoteleft.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='line-height: 145%; font-size: 14px; font-style: italic;'>Above and beyond her skill as an audio enginneer, Anne has been amazingly quick and professional in her turn around time, always getting our CD's back in a timely fashion. She is fabulous!&nbsp;</span><span style='background: url(images/quoteright.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><br><span style='line-height: 145%; font-size: 14px;'>&mdash; </span><span style='font-size: 85%;'>Elizabeth Brimhall, Director, Stanford Insitute Choir</span>";
fader[2].msg[5] = "<span style='background: url(images/quoteleft.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='line-height: 145%; font-size: 14px; font-style: italic;'>Hey Anne! They are SO good! I can't believe it. Both are perfect and I really appreciate and admire the work done. It makes me want to write a bunch of new songs so we can record them!&nbsp;</span><span style='background: url(images/quoteright.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><br><span style='line-height: 145%; font-size: 14px;'>&mdash; </span><span style='font-size: 85%;'>Shelli Kesler, singer, songwriter, client of Stern Studios</span>";
fader[2].msg[6] = "<span style='background: url(images/quoteleft.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='line-height: 145%; font-size: 14px; font-style: italic;'>Anne, you are a tech wizard in your understanding of theory, not to mention your many gifts and talents.&nbsp;</span><span style='background: url(images/quoteright.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><br><span style='line-height: 145%; font-size: 14px;'>&mdash; </span><span style='font-size: 85%;'>Trish McDonald, singer and songwriter</span>";
fader[2].msg[7] = "<span style='background: url(images/quoteleft.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='line-height: 145%; font-size: 14px; font-style: italic;'>Anne, you seriously rock, and your timing is great.  Seriously rock, I mean. Sheesh. They'll take away my English major card and my black turtleneck and won't let me into coffeehouses where they're doing poetry readings anymore.&nbsp;</span><span style='background: url(images/quoteright.jpg) no-repeat scroll left top;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><br><span style='line-height: 145%; font-size: 14px;'>&mdash; </span><span style='font-size: 85%;'>Stephen Nelson, client of Stern Studios</span>";

// Start this fader
setTimeout(function() { throb(2); }, 1000);
