﻿function rotateText(el, textGroup) {
setOpacity(el, 0);
var t = rotateText.texts[textGroup];
var t = t[Math.floor(Math.random() * (t.length - 1))];
el.innerHTML = t;
unfadeText(el, textGroup);
}
rotateText.texts = {
quotes: [
"<b>MYTH:</b><br>One donor can only assist with one donation. <P><b>FACT:</b><br>In fact, one organ donor can save the lives of eight people, and assist the lives of nearly 50 more!",
"<b>MYTH:</b><br>Emergency room doctors will not try very hard to save my life if they know I'm an organ donor. <P><b>FACT:</b><br>In fact, donation only occurs after all efforts to save your life have been exhausted and death has been legally declared.",
"<b>MYTH:</b><br>If I sign my donor card then I can't change my mind. <P><b>FACT:</b><br>If at any time you wish to revoke your offer to donate your organs, simply tell your nearest relative or have your driver’s license or donor card changed.",
"<b>MYTH:</b><br>Only healthy people can be organ donors. <P><b>FACT:</b><br>In fact, anyone can be an organ and tissue donor regardless of age or previous illness.",
"<b>MYTH:</b><br>Organ donors have to have closed caskets at their funeral because their bodies have been severely damaged in the process of removing organs and tissue. <P><b>FACT:</b><br>In fact, removal of tissues or organs will not interfere with customary funeral arrangements."
]
};

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);
};
}
