// AI Cycle text cycler created by Morgan Adams, Adams Immersive, adamsi.com.
// This code is deployed on stephengpost.com and may not be used on other sites without permission.

var items = new Array();

items.push('<p>“The lessons Post learned make up this practical resource that urges purposeful giving, even while feeling the stings of disappointment and hardship. Post’s work is more than a feel-good read. It’s today’s handbook for survival.”</p><p class="attribution">—<em>Publishers Weekly</em> January 2011</p>');

items.push('<p>“Stephen Post... has written a deeply moving and comforting book about the pain and the healing of being uprooted.... It is wise and profoundly healing.”</p><p class="attribution">—George E. Vaillant MD, professor of psychiatry, Harvard Medical School</p>');

items.push('<p>“I hereby add my voice to the much deserved praise of Stephen G. Post’s book on the healing power of love. It is a lasting contribution to the humanities in medicine.”</p><p class="attribution">—Richard Selzer, MD, Yale University School of Medicine</p>');

items.push('<p>“In this inspiring book, Stephen Post convincingly shows how helping others leads to win-win situations: not only does benevolence enhance others’ well-being... but, as a bonus, it also contributes significantly to our own physical and mental well-being.”</p><p class="attribution">—Matthieu Ricard, Buddhist monk and scientist of compassion</p>');

items.push('<p>“an engaging spiritually wise reflection on the challenge of moving from one place and one job to another. He draws on his expertise in the scientific research on helping, loving, religion and altruism as he constructs a moving personal narrative.”</p><p class="attribution">—Sydney Callahan, Ph.D., nationally syndicated columnist for Commonweal Magazine</p>');

items.push('<p>“America needs this timely, persuasive and morally refreshing call to help our neighbors. Once again, Stephen Post offers us the gift of good news that volunteerism, altruism and philanthropy are forms of therapy for our own souls.”</p><p class="attribution">—Rev. Dr. Robert M. Franklin, president, Morehouse&nbsp;College</p>');

items.push('<p>“For over two decades, Stephen Post has produced the most impressive body of work cogently arguing for love’s central role at the interface of science, medicine and spirituality.”</p><p class="attribution">—Gregory L. Fricchione, MD, professor of psychiatry, Harvard Medical School and director of the Benson-Henry Institute for Mind Body Medicine, Massachusetts General Hospital</p>');

items.push('<p>“In reflecting on his life’s challenges and transitions, Stephen Post weds solid science with practical wisdom, and conveys the resulting truths with inspiring life stories.  With graceful prose he points to way to human flourishing—through self-giving love.”</p><p class="attribution">—David G. Myers, professor of psychology education, Hope College</p>');

items.push('<p>“Stephen Post has long championed the simple but sublime truth that by helping others we help ourselves.”</p><p class="attribution">—John Witte, director and distinguished professor, Center for Law and Religion, Emory University</p>');

items.push('<p>“In an elegant and thoughtful reflection on his family’s move from their settled life in Ohio to their new home in New York, Stephen Post uncovers ‘hidden gifts’ among life-changing challenges.”</p><p class="attribution">—The Rev. Dr. Walter J. Smith, S.J., Ph.D., president and CEO, HealthCare Chaplaincy</p>');

var delay = 6;
var fadetime = 1.5;
var fps = 24;
var steps = parseInt(fadetime*fps);
var f;
var cycle;
var cyclefader;
var autotimer;
var fadetimer;
var numitems = items.length;
var current = Math.floor(Math.random()*numitems);

function docycle() {
	cycle = document.getElementById("cycle");
	cyclefader = document.getElementById("cyclefader");
	f = 1.0;
	fade(f);
	cycle.innerHTML = items[current];
	clearTimeout(autotimer);
	autoplay();
	fadein();
}

function fadein() {
	f = f-1.0/steps;
	fade(f);
	fadetimer = setTimeout("fadein()",1000/fps);
	if (f <= 0.0) {
		clearTimeout(fadetimer);
	}
}

function fadeout() {
	f = f+1.0/steps;
	fade(f);
	fadetimer = setTimeout("fadeout()",1000/fps);
	if (f >= 1.0) {
		clearTimeout(fadetimer);
		docycle();
	}
}

function fade(o) {
	o = Math.max(Math.min(o,1.0),0.0);
	cyclefader.style.opacity = o;
	cyclefader.style.filter = 'alpha(opacity='+parseInt(100*o)+')'; // IE
}

function autoplay() {
	current = current+1;
	if (current==numitems) {
		current = 0;
	}
	autotimer = setTimeout("fadeout()",1000*delay);
}
