//////////////////////////////////////////////////////

// =======================================
// fact fader
// =======================================

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);
}
/* ***** End: GreyWyvern's Buffered Text-fade Effect - v2.2a ******* */


/* *****
 * The code below describes how to make a throbbing or automatic fade
 * sequence of messages.  The throbFade function is called repeatedly
 * which controls what commands are sent to the fade engine, rather
 * than using mouseovers.
 *
 * Notes:
 * - A global variable throbStep is used to keep track of where the
 *   animation is currently in the sequence.
 * - The list of messages defined in the fader *must* start at zero (0)
 *   and count upwards without skipping any integers.
 * - The second line of the throbFade() function controls how fast
 *   commands get sent to the fade engine.  It waits only 100 milli-
 *   seconds when fading out, but 4000 milliseconds (4 seconds) when
 *   fading in; this means the message will remain visible for about 4
 *   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!
 */
 
function throbFade() {
  fade(2, Math.floor(throbStep / 2), (throbStep % 2) ? false : true);
  setTimeout("throbFade();", (throbStep % 2) ? 100 : 12000);
  if (++throbStep > fader[2].message.length * 2 - 1) throbStep = 0;
}

fader[2] = new fadeObj(2, 'fade2', 'E3DCD0', '000000', 60, 60, true);
fader[2].message[0] = "<p>Mastercraft is an all-American, hand-made prodct.</p>";
fader[2].message[1] = "<p>Our furniture is renowned for its residential look and feel with commercial design and durability.</p>";
fader[2].message[2] = "<p>We practice environmentally friendly and energy-efficient manufacturing techniques.</p>";
fader[2].message[3] = "<p>Mastercraft Specialites product is available in solid oak standard construction with maple, poplar, and plywood &mdash; our products are made with only the finest of hardwoods.</p>";
fader[2].message[4] = "<p>Seven standard finishes, but we will custom match stain to most standard line brand laminates at no additional cost.</p>";
fader[2].message[5] = "<p>We offer 18 standard lines of product with more currently in development.</p>";
fader[2].message[6] = "<p>Mortise and tenon construction is standard, as is reinforcement with screw cleats and corner blocking at critical points Ð assuring a long-lasting product.</p>";
fader[2].message[7] = "<p>Dozens of standard options available.</p>";
fader[2].message[8] = "<p>We have the ability to design and build custom to meet your exact needs.</p>";
fader[2].message[9] = "<p>Our supervisory staff has over 225 combined years of woodworking experience.</p>";
fader[2].message[10] = "<p>Mastercraft's facilities total over 210,000 gsf of production space.</p>";
fader[2].message[11] = "<p>We openly invite all orders, no matter how small or large the quantity.</p>";

var throbStep = 0;
setTimeout("throbFade();", 250);


function throbFadeA() {
  fade(3, Math.floor(throbStepA / 2), (throbStepA % 2) ? false : true);
  setTimeout("throbFadeA();", (throbStepA % 2) ? 100 : 12000);
  if (++throbStepA > fader[3].message.length * 2 - 1) throbStepA = 0;
}

fader[3] = new fadeObj(3, 'fade3', 'E3DCD0', '000000', 60, 60, true);
fader[3].message[0] = "Mastercraft furniture meets all ANSI/BIFMA standards and is GSA approved for government/military use.  In fact, Mastercraft has provided furniture for over 100 U.S. military bases world-wide including Pearl Harbor, Cheyanne Mountain Air Force Station, and Area 51.";
fader[3].message[1] = "NASA space shuttle astronauts sleep on Mastercraft beds and hang their uniforms in Mastercraft wardrobes upon return from their voyages. After landing they are required to spend several days in quarantine in a special barracks. NASA chose Mastercraft furniture to outfit this barracks.";
fader[3].message[2] = "The barracks of the crew of Air Force One and the guards of the Tomb of the Unknown Soldier are also furnished with Mastercraft products.";

var throbStepA = 0;
setTimeout("throbFadeA();", 1000);

