//pre-load images
var listImg = new Image();
listImg.src = '';
var treeImg = new Image();
treeImg.src = '';
var formImg = new Image();
formImg.src = '';
var autoImg = new Image();
autoImg.src = '';

function makeNews(c,l,f,i){
	this.copy = c;
	this.link = l;
	this.follow = f;
	this.img = i;
	this.write = writeNews;
}

function writeNews(){
	var str = '';
	str += this.copy + '<br>';
        str +=  '<a href="' + this.link + '">' + this.follow + '</a>';
	return str;
}

var newsArray = new Array();
newsArray[0] = new makeNews("\"<span style=\"font-size:13px; line-height: 180%;\"><i>I would anticipate that after an initial flurry of everybody getting really excited, happy, sad...about [OpenNotes], that it...probably would be a wash after three to six months.\"</i></span><br><br>- a doctor at BIDMC",'','',listImg).write();

newsArray[1] = new makeNews("\"<span style=\"font-size:13px; line-height: 180%;\"><i>...[W]ho is the master audience of the progress note? Is it the doc? Is it the patient?...And, is it possible to serve all those masters with one document and do it well?\"</i></span><br><br>- a doctor at GHS",'','',listImg).write();

newsArray[2] = new makeNews("\"<span style=\"font-size:13px; line-height: 180%;\"><i>If I'm thinking somebody else is reading this note, is it going to take me longer to complete...?\"</i></span><br><br>- a doctor at GHS",'','',listImg).write();

newsArray[3] = new makeNews("\"<span style=\"font-size:13px; line-height: 180%;\"><i>...[OpenNotes] gives me an opportunity to have a real good dialogue with my physician, to make sure that we're both on the same page...\"</i></span><br><br>- a patient at BIDMC",'','',listImg).write();

newsArray[4] = new makeNews("\"<span style=\"font-size:13px; line-height: 180%;\"><i>By having the opportunity to review their medical records, maybe we can...get the message across that, you know, your health is really your responsibility, not all ours. It's a partnership.\"</i></span><br><br>- a doctor at GHS",'','',listImg).write();

newsArray[5] = new makeNews("\"<span style=\"font-size:13px; line-height: 180%;\"><i>I'm so afraid that doctors are going to say, 'My God, I never had enough time. Now, look what [OpenNotes] is doing to me...'\"</i></span><br><br>- a patient at BIDMC",'','',listImg).write();


var nIndex = 0;
var timerID = null;
function rotateNews(){
	var len = newsArray.length;
	if(nIndex >= len)
		nIndex = 0;
	document.getElementById('stories').innerHTML = newsArray[nIndex];
	nIndex++;
	timerID = setTimeout('rotateNews()',7000);
}
function pauseNews() {
	if (timerID != null) {
		clearTimeout(timerID);
		timerID = null;
	}
}

function playNews() {
	if (timerID == null) {
		timerID = setTimeout('rotateNews()', 1000);
	}
}

