// 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) ? 100 : 15000);
  if (++throbStep > fader[2].message.length * 2 - 1) throbStep = 0;
}

fader[2] = new fadeObj(2, 'fade2', 'bbbbbb', '000000', 30, 30, false);
fader[2].message[0] = "Alan Best is uniquely talented in providing a safe, noncompetitive martial arts program for children that promotes self esteem, self confidence,  and self control. Both my children attended Best Martial Arts Institute, and I often recommend the program to my patients and their families. <br>-<i> Patricia Cagney, M.D., Pediatrician</i>";
fader[2].message[1] = "The staff at Best Martial Arts Institute are among the best teachers of children in any subject we have ever known.<br>-<i> Amy & Frank Gibson</i>";
fader[2].message[2] = "Martial arts had such a maturing influence on my son, I decided to enroll myself. <br>-<i> Rick Schulz</i>"
fader[2].message[3] = "Sensei Best has a gift. It is the mix of physical expertise and generosity of spirit. He has taught our son for years, and has helped to weave him into a confident young man.<br>-<i> Leslie & Art Noxon</i>";
fader[2].message[4] = "The program is wonderful because it teaches children to work hard and have fun without immediately receiving something in return for their efforts. The perseverance, love and joy of learning is reflected in the children taking the classes.<br>-<i> Michelle E. Bassett</i>";
fader[2].message[5] = "This is a fantastic class!  We like how the instructors tie together martial arts with character development and strong morals for daily life. <br>-<i> Parent</i>";
fader[2].message[6] = "Bringing my child to BMAI has been the single best thing I have done as a parent. His listening skills, his respect for himself and others, and his willingness to try challenging tasks increase every week.<br>-<i> Paul Rhoden, School Teacher</i>";
fader[2].message[7] = "Best Martial Arts has been a great thing for my children. Your instructors are professional and interact well with kids of all ages. The instructors are very knowledgeable and have a great ability to bring out the best in children of all levels and abilities. They have EARNED the respect of my children. <br>-<i> Parent</i>";
fader[2].message[8] = "Your instructors are all excellent. They maintain safe control of the class while eliciting respect from all the students. I appreciate the values being taught here and modeled by the instructors. Seems like all the students look forward to class--I know mine do.<br><i> - Parent</i>";
fader[2].message[9] = "Teachers are very fun, knowledgeable and get the most out of the children. My child is learning respect, discipline, hard work as well as Judo.  I love this class!<br>-<i> Parent</i>";
fader[2].message[10] = "Excellent instructors, friendly atmosphere and superior quality of teaching...one of our favorite classes ever.<br>-<i> Parent</i>";
fader[2].message[11] = "I have really appreciated the focus on skill, but even more so on character - good sportsmanship, kindness, respect, etc. The class is a very positive experience for my child.<br>-<i> Parent</i>";

var throbStep = 0;
setTimeout("throbFade();", 1000);
