var number = 0;
var everyOther = 0;

function rotateText(el, textGroup) {
  setOpacity(el, 0);
  var t = rotateText.texts[textGroup];
  //var t = t[Math.floor(Math.random() * (t.length - 1))];
  
  if (number > t.length - 1)
  {
  	number = 0;
  }
  //alert(number);
  if (everyOther % 2 == 0)
  {
  	number = Math.floor(number);
  }
  everyOther++;
  
  var t = t[number];
  
  el.innerHTML = t;
  unfadeText(el, textGroup);
  number = number + 1;
}
rotateText.texts = {
  quotes: [
    " \"From our first contact to the day we moved in, and beyond, Bob and his excellent staff have gone above and beyond any expectations we had of a Realtor relationship.\"<br/><span style = \"color: #BD9121;\">~Salt Lake, Tina Briggs</span>",

    "\"We have simply never had a better experience with a Realtor.\"<br/><span style = \"color: #BD9121;\">~Las Vegas, Jessica Little</span>",

    "\"Your personal professionalism is so far above the norm that we are awed but very grateful. Thank you especially for the friendship, guidance and wisdom.\"<br/><span style = \"color: #BD9121;\">~St. George, Thomas Hanes</span>",

    "\"You were #1 in professionalism with helpful, detailed responses to our questions. you went over and beyond our expectations by going the extra mile to sell our home.\"<br/><span style = \"color: #BD9121;\">~Hurricane, Ted Graf</span>",

    "\"You came thru when no one else could help us. You know more than real estate. You know people, community and future plans of St. George, UT.\"<br/><span style = \"color: #BD9121;\">~St. George, Sarah Mecham</span>",

    "\"When you said you'd get it done, it got done!\"<br/><span style = \"color: #BD9121;\">~Mesquite, Will Leavitt</span>"
  ]
  /*,
  authors: [
    "~Salt Lake, Torina Briggs",
    "~Las Vegas, Jessica Little",
	"~St. George, Thomas Hanes",
    "~Hurricane, Ted Graff",
    "~St. George, Sarah Mecham",
    "~Mesquite, Will Leavitt"
  ]
  */
  };

function setOpacity(el, value) {
  el.style.opacity = value / 100;
  el.style.filter = "alpha(opacity=" + value + ")";
}

function unfadeText(el, tg) {
  var v = el.style.opacity * 100 + 1;
  if(v > 100) {
    setOpacity(el, 100);
    setTimeout(bundleFunction(null, fadeText, [el, tg]), 3000);
    return;
  }
  setOpacity(el, v);
  setTimeout(bundleFunction(null, unfadeText, [el, tg]), 10);
}

function fadeText(el, tg) {
  var v = el.style.opacity * 100 - 1;
  if(v < 0) {
    setOpacity(el, 0);
    rotateText(el, tg);
    //or... setTimeout(bundleFunction(null, rotateText, [el, tg]), NUMBER);
    return;
  }
  setOpacity(el, v);
  setTimeout(bundleFunction(null, fadeText, [el, tg]), 10);
}

function bundleFunction(context, func, args) {
  context = context || null;
  if(typeof func == "string" && context)
    func = context[func];
  if(!args)
    args = [];
  else if(!(args instanceof Array))
    args = [args];
  return function() {
    return func.apply(context, args);
  };
}