﻿
RotatingElements = { endorse :  [        
                "<div class=\"endorsements\" id=\"endorsement01\"><img class=\"endorsements-image\" src=\"/images/fcm-thumb-lepier.jpg\" alt=\"thumbnail portrait of Larry LePier\" /><p>&ldquo;I support FCMS because I know first hand the importance of getting family to the emergency room within minutes.&rdquo;<br />- Larry LePier, Board of Trustees, First Care Medical Services</p></div>",
                "<div class=\"endorsements\" id=\"endorsement02\"><img class=\"endorsements-image\" src=\"/images/fcm-thumb-flermoens.jpg\" alt=\"thumbnail portrait of the Flermoens\" /><p>&ldquo;I chose FCMS for surgery because I know the people, it&#39;s convenient, and there is a support system in place for specialists. This facility is worth supporting.&rdquo;<br />- Orrie Flermoen, Winger, Minnesota</p></div>",
                "<div class=\"endorsements\" id=\"endorsement03\"><img class=\"endorsements-image\" src=\"/images/fcm-thumb-markkathy.jpg\" alt=\"thumbnail portrait of Mark and Kathy\" /><p>&ldquo;Kathy and I support FCMS Foundation to insure the future availability of local healthcare, and because we recognize the tremendous economic impact First Care has on our area communities.&rdquo;<br />- Mark Finstad, President, Ultima Bank Minnesota</p></div>" ]
          };
          
var randomnumber = Math.floor(Math.random()*3)

var currentElement = randomnumber;

function rotateTextDiv(el, textGroup) {
  setOpacity1(el, 0);
  var t = RotatingElements[textGroup][currentElement++];
  
  if(currentElement > (RotatingElements[textGroup].length - 1))
        currentElement = 0;
        
  el.innerHTML = t;
  unfadeText1(el, textGroup);
}

function setOpacity1(el, value) {
  el.style.opacity = value / 100;
  el.style.filter = "alpha(opacity=" + value + ")";
}

function unfadeText1(el, tg) {
  var v = el.style.opacity * 100 + 1;
  if(v > 100) {
    setOpacity1(el, 100);
    setTimeout(bundleFunction1(null, fadeText1, [el, tg]), 7000);
    return;
  }
  setOpacity1(el, v);
  setTimeout(bundleFunction1(null, unfadeText1, [el, tg]), 10);
}
function fadeText1(el, tg) {
  var v = el.style.opacity * 100 - 1;
  if(v < 0) {
    setOpacity1(el, 0);
    rotateTextDiv(el, tg);
    //or... setTimeout(bundleFunction(null, rotateText, [el, tg]), NUMBER);
    return;
  }
  setOpacity1(el, v);
  setTimeout(bundleFunction1(null, fadeText1, [el, tg]), 10);
}

function bundleFunction1(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);
  };
}