//pre-load images
var listImg = new Image();
listImg.src = 'assets/images/banz/125x125prosto.png';
var treeImg = new Image();
treeImg.src = 'assets/images/banz/125x125hedon.png';
var formImg = new Image();
formImg.src = 'assets/images/banz/125x125twotip.png';

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 += '<a href="' + this.link + '">';
	str += '<img border="0" src="' + this.img.src + '"></a>';
	
	return str;
}

var newsArray = new Array();
newsArray[0] = new makeNews("Move Items Between Lists With JavaScript",'http://www.prosto.com','Read More',listImg).write();

newsArray[1] = new makeNews("Build an XML-Based Tree Control With JavaScript",'http://www.hedon.com','More Info',treeImg).write();

newsArray[2] = new makeNews("Automate Your Form Validation",'http://www.twotip.com','Full Story',formImg).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()',6000);
}
function pauseNews() {
	if (timerID != null) {
		clearTimeout(timerID);
		timerID = null;
	}
}

function playNews() {
	if (timerID == null) {
		timerID = setTimeout('rotateNews()', 1000);
	}
}

