/* ***** Begin ***************************************************** */
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); });
}
/* ***** End ******************************************************* */




/* *****
 * User defined fade objects and messages
 *
 * These messages are used in fades triggered by mouseovers and
 * mouseouts on table cells.  They are the simplest type of fade and
 * require no extra Javascript code.
 */
 
var fader = new Array();

/* *****
 * The code below describes how to make a throbbing or automatic fade
 * sequence of messages.  It is important to note that this function is
 * NOT part of the Buffered Text-Fade Effect, but merely an example of
 * how it can be used.  In this example, the throb() function controls
 * the commands which are sent to the fade engine; it is called
 * repeatedly at set time intervals rather than using mouseover events
 * as triggers.
 *
 * Notes:
 * - A global array "hash" is used to keep track of where each
 *   animation is currently in the sequence.
 * - The list of messages defined in the fader *must* start at one (1)
 *   and count upwards without skipping any integers.
 * - The third line of the throb() function controls how fast
 *   commands get sent to the fade engine.  It waits only 100 milli-
 *   seconds when fading out, but 5000 milliseconds (5 seconds) when
 *   fading in; this means the message will remain visible for about 5
 *   seconds before fading out again.
 *
 * Other types of fade animation are possible simply by designing
 * different ways to control the fade-ins and fade-outs!
 */
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', 'e1dbcb', '333333', 30, 30);
fader[2].msg[1] = "<p>&#8220;A wonderful, beautifully written story of the education and development of a young soldier-scholar...&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#petraeus'>General David Petraeus</a></span></p><p>&#8220;A compelling, can&rsquo;t-put-down book, a well-written, memorable description of preparing for war and leading in combat.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#klein'>Joe Klein</a>, <i>Time</i></span></p><p>&#8220;A thoughtful, introspective work reminiscent of the great British memoirs of World War I.... Read it.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#ricks'>Thomas E. Ricks</a>, <i>The Washington Post</i></span></p><p>&#8220;A classic memoir about what it means to be American.... I recommend <em>The Unforgiving Minute</em> without any mental reservation or purpose of evasion.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#lipsky'>David Lipsky, <i>Rolling Stone</i></span></p>";
fader[2].msg[2] = "<p>&#8220;A powerful narrative of purpose, responsibility, courage, and personal growth. Every young man and woman in America should read this book.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#clark'>General Wesley Clark</a></span></p><p>&#8220;An unusually honest, funny, accessible, and vivid account of a soldier&rsquo;s coming of age. This is more than a soldier&rsquo;s story; it is a work of literature.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#coll'>Steve Coll</a>, Pulitzer Prize winner</span></p><p>&#8220;The poignant true story of a young man&rsquo;s unusual education from the classrooms of West Point and Oxford to his development as a leader, son, brother, husband and friend.... I admire Craig Mullaney&rsquo;s courage.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#lugar'>Senator Richard Lugar</a></span></p><p>&#8220;A poignant and evocative book about the great hurdles in coming of age: love, death, belief, and betrayal. I couldn&rsquo;t stop reading.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#fick'>Nathaniel Fick</a>, author of the <em>New York Times</em> bestseller <em>One Bullet Away</em></span></p>";
fader[2].msg[3] = "<p>&#8220;Mullaney&rsquo;s  keen eye for detail, lively narrative style, and capacity for  self-reflection&mdash;unusual in many soldiers&mdash;make an old story new and  gripping.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#slaughter'>Anne-Marie Slaughter</a>, Dean of the Woodrow Wilson School</span></p><p>&#8220;<em>The Unforgiving Minute</em> should be required reading for all who serve in the White House and Congress and for those who aspire to leadership. Read it. Twice.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#bucha'>Paul Bucha</a>, past president of the Congressional Medal of Honor Society</span></p><p>&#8220;Weaving action and reflection, <em>The Unforgiving Minute</em> is fast-paced,  entertaining, and rich with insight and wisdom.&nbsp;&nbsp;A great debut from a  leader to watch.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#mccaffrey'>General Barry McCaffrey</a></span></p><p>&#8220;<em>The Unforgiving  Minute</em> accurately  captures what it is to prepare for the ultimate responsibility of  leading soldiers in war.... Thoughtful, hilarious,  gut-wrenching, and inspiring.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#hagenbeck'>Lieutenant General F.L. Hagenbeck</a></span></p>";
fader[2].msg[4] = "<p>&#8220;The thinking soldier&rsquo;s guide to modern combat, told with a novelist&rsquo;s eye for detail and a philosopher&rsquo;s penchant for perspective.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#murphy'>Bill Murphy Jr.</a>, author of <em>In a Time of War</em></span></p><p>&#8220;A masterpiece of self-awareness.  No American can read this book and ever again forget what we owe to others for giving to us a society filled with so many choices that we have the freedom to make for ourselves.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#boren'>David L. Boren</a>, former U.S. Senator</span></p><p>&#8220;A searingly honest and brilliant tale, full of small victories,  significant losses, self-awareness and understanding...full of life lessons on every page, written in a modest  and unflinching style&mdash;a classic memoir.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#stavridis'>Admiral James Stavridis</a>, U.S. Southern Command</span></p><p>&#8220;An honest account of the closeness and the distance between a father and a son and the highs and lows of military life. A must read for all combat leaders.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#coleman'>Lieutenant General Ronald Coleman</a>, U.S. Marine Corps</span></p>";
fader[2].msg[5] = "<p>&#8220;The ultimate&rsquo;s soldier&rsquo;s book...a lyrical, spellbinding tale of war, love, and courage. <em>The Unforgiving Minute</em> is the <em>Three Cups of Tea</em> of soldiering.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#rashid'>Ahmed Rashid</a>, <em>New York Times</em> bestselling author</span></p><p>&#8220;<em>The  Unforgiving Minute</em> tells the story of a fiercely  passionate young man and provides important insight into a new greatest  generation&mdash;his comrades in arms who serve in a time of war.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#nagl'>Dr. John Nagl</a>, author of <em>Learning to Eat Soup with a Knife</em></span></p><p>&#8220;A literate and thoughtful memoir that is a valuable contribution to both the genre and to our understanding of contemporary conflict.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#exum'>Andrew Exum</a>, author of <em>This Man&rsquo;s Army</em></span></p><p>&#8220;I couldn&rsquo;t put down <em>The Unforgiving Minute</em>.  Well-written and engaging, this book should be a requirement for all young people seeking to become leaders.&#8221;<span>&mdash;<a href='../content/book.asp?id=praise#kerrick'>Lieutenant General Donald L. Kerrick, former Deputy National Security Adviser</span></p>";
// Start this fader
setTimeout(function() { throb(2); }, 1000);
