var prev=1;
function rotateText(el, textGroup) {
  setOpacity(el, 0);
  var t = rotateText.texts[textGroup];
  var elem = Math.floor(Math.random() * (t.length - 1));
  while(elem==prev) {
	  var elem = Math.floor(Math.random() * (t.length - 1));
  }
  var t = t[elem];
  prev=elem;
  el.innerHTML = t; 
//  elm=++elm%t.length;
  unfadeText(el, textGroup);

}
rotateText.texts = {
  quotes: [
    "\"Three years on, I have not returned to any bad habits and have never felt this good in every way\"<br><span class='authors'>D.S, Woking</span>",
    "\"After my sessions I always found that not only was I less wound up but my mind was more opened and focussed towards the good things that exist in my life.\"<br><span class='authors'>Financial Advisor, London</span>",
    "\"Your EFT and NLP coaching sessions have made a dramatic difference to all areas of my life\"<br><span class='authors'>V.B, Surrey</span>",
    "\"I have really noticed the difference with my driving as I am so much calmer.\"<br><span class='authors'>L.S, Richmond</span>",
    "\"After only one session with Denis I was, and still am, able to deal with subsequent MRI scans and treatment without batting an eyelid. I don't know why EFT works – it just does!\"<br><span class='authors'>J.P, General Manager SpringHealth Leisure ltd.</span>",
    "\"Within half an hour of working with Denis my shoulders had dropped about 6 inches, I was so calm that within 48 hours my eczema cleared\"<br><span class='authors'>Hannah, RACC</span>",
	"\"A month later and the chakra techniques are still working, I will be back\"<br><span class='authors'>Jo, Twickenham</span>",
	"\"My ability to respond to situations, tasks and events with positivity is a result!\"",
	"\"I feel that Denis has given me the tools to walk the tight rope of work, life and relationships with confidence and ease.\"<br><span class='authors'>Business Owner, Teddington</span>"	
  ],
  authors: [
    "",
    "",
    "",
	"",
	"",
	"",
	""
	
  ],
  restaurants: [
    "t",
    "y",
	"y",
    "y"
  ]
};

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]), 10000);
    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);
  };
}