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(); }, 10);
  };
  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(); }, 10);
          } else this.elem.innerHTML = "&nbsp;";
        }
      } else setTimeout(function() { self.fadeLoop(); }, 10);
    } else setTimeout(function() { self.fadeLoop(); }, 10);
  };
  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('fade2', 'FFFFFF', "505050", 100, 100);
fader[0].msg[0] = "\"I think he just might have been the best agriculture minister the Prairies have seen in awhile.  He seemed to listen and he seemed to want to make things better.\" Quote from Roger Epp, academic dean and rural prairie analyst at Augustana University College";
fader[0].msg[1] = "\"Speller has shown enlightened and reasoned leadership in this current situation (Mad Cow)\" \"Speller should be applauded for his leadership.\"  Editorial Simcoe Reformer December 29, 2003";
fader[0].msg[2] = "\"Speller soars in crisis control.  Agriculture Minister\'s handling of bird flu do deft, opposition critic lauds his efforts\"  article by Heather Scoffield";
fader[0].msg[3] = "\"Speller\'s defeat brought seemingly genuine expressions of regret from farm leaders who thought they had acquired an important ally in Ottawa.\"   The Western Producer July 22, 2005-12-28";
fader[0].msg[4] = "\"With Speller\'s brief tenure, money started to flow from the government to assist with the shock of BSE.  Speller also made the changes to the Canadian Agricultural Income Stabilization program long demanded by farmers\"  The Western Producer, July 8, 2004";
fader[0].msg[5] = "\"Bob Speller not being in government will be a huge loss,\" Canadian Federation of Agriculture president Bob Friesen said June 28.  \"He understood agriculture.  As a backbencher and a minister, he was there for us.  We had high hopes for him.\"  \"It is a huge loss. He will be missed.\"  --Western Producer July 1, 2004";
fader[0].msg[6] = "In effect, Klein proclaimed:   \"Minister Speller is doing a fine job on the BSE (mad cow) issue\" Haldimand press March 31, 2004";
fader[0].msg[7] = "\"If I had my hat on, I\'d take it off to you.\"  Quote from CCA president Neil Jahnke about Bob Speller, as reported in the Western Producer April 1, 2004";
fader[0].msg[8] = "\"As far as farm communities are concerned, I think they see him as available and responsive to their needs.\"  \"It seems to me that\'s the way parliament should work, to have the time to talk quietly about programs and meet with opposition.\" Quote from Dick Proctor, NDP agriculture critic and southern Saskatchewan MP in the Simcoe Reformer, April 23, 2004";
fader[0].msg[9] = "\"(Bob Speller) announced $1 billion in farm aid, a popular announcement that brought instant industry praise and stature for the agriculture minister as one of the few members of cabinet to win approval for significant new spending during a week when the government budget message was fiscal restraint.\"  April 1, 2004 Western Producer";
fader[0].msg[10] = "\"I judge him by what my members tell me, as well as the working relationship we have.  He\'s proved himself to be a good listener and proved he likes to take action when action is needed.\"  Quote from Bob Friesen, president of the Canadian Federation of Agriculture Simcoe Reformer April 23, 2003";
fader[0].msg[11] = "\"Losing Bob as ag minister is losing somebody who has listened well and who I think has had healthier national perspective than we\'ve seen for some time.\"The Leader-Post Regina June 30, 2004";
fader[0].msg[12] = "Jack Van Netten, local director of the Chicken Farmers of Ontario was quoted in the Simcoe Reformer June 23, 2004 as stating Speller has been supportive of supply managed commodities, such as poultry and that that was support Van Netten wants to keep. Bob is always supportive of agriculture, no matter what. \"All of the agriculture industry in Haldimand-Norfolk would be very concerned if we lost him, and the whole country (would be) as a matter of fact.\"";
fader[0].msg[13] = "\"Bob Speller wasn\'t just rare for his intelligence and understanding of our industry and the respect he commanded, but also for the fact that he is probably the only Minister of Agriculture we will have from our area - ever - in our current lifetime.\"The Growers August 2004";
//fader[0].msg[14] = "";
//fader[0].msg[15] = "";
//fader[0].msg[16] = "";


var hash = new Array();
var index = -1;
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;
  // C-Mod init random index
  if (index == -1) {
    index = Math.floor(Math.random() * (fader[item].msg.length - 1) + 1);
  }

  // Send a fade command, using the hash array to tell us what parameters we should use
  fader[item].fade(index, !(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;
  
  // C-Mod add random changer
  index = Math.floor(Math.random() * (fader[item].msg.length - 1) + 1);
}

setTimeout(function() { throb(0); }, 1000);




