/* News rotator 
	Flemming Rothmann, 2005
	Based on ideas found on the net
	Handles more rotator areas on an html page.
*/

function rotatorBlock(area,timeout,transdelay) {
	this.area = area;
	this.newsArray = new Array();
	this.nIndex = 0;
	this.timerID = null;
	this.delay = timeout;
	this.transdelay = transdelay;
}


function rotatorMakeNews(h,c,l,f,i){
	this.heading = h;
	this.story = c;
	this.link = l;
	this.follow = f;
	this.img = new Image();
	if (i != null && i != '') {
		this.img.src = i;
	} else {
		this.img = null;
	}
	this.write = writeNews;
}

function writeNews(){
	var str = '';
	if (this.heading.length > 0) {
		str += '<span class="subheading">' + this.heading + '</span><br>';
	}
	if (this.img != null) {
		str += '<a href="' + this.link + '">';
		str += '<img border="0" src="' + this.img.src + '"></a><br>';
	} else {
		str += '<br>';
	}
	str += this.story + '<br>';
    str +=  '<br><div align="right"><a href="' + this.link + '">' + this.follow + '</a></div>';
	return str;
}

var rotatorItems = Array();

function addNews(heading,story,link,follow,image) {
	rotatorItems[rotatorItems.length - 1].newsArray[rotatorItems[rotatorItems.length - 1].newsArray.length] = new rotatorMakeNews(heading,story,link,follow,image).write();
}

function blankNews(what) {
	document.getElementById(rotatorItems[what].area).innerHTML = "<div></div>"
	rotatorItems[what].timerID = setTimeout('rotatorGoNext(' + what + ')',rotatorItems[what].transdelay);
}

function rotatorGoNext(what){
	var len = rotatorItems[what].newsArray.length;
	if(rotatorItems[what].nIndex >= len)
		rotatorItems[what].nIndex = 0;
	document.getElementById(rotatorItems[what].area).innerHTML = rotatorItems[what].newsArray[rotatorItems[what].nIndex];
	rotatorItems[what].nIndex++;
	rotatorItems[what].timerID = setTimeout('blankNews(' + what + ')',rotatorItems[what].delay);
}
function rotatorDoPause(what) {
	if (rotatorItems[what].timerID != null) {
		clearTimeout(rotatorItems[what].timerID);
		rotatorItems[what].timerID = null;
	}
}

function rotatorStartPlaying(what) {
	if (rotatorItems[what].timerID == null) {
		rotatorItems[what].timerID = setTimeout('rotatorGoNext(' + what + ')', 1000);
	}
}

function rotatorInitialStartup() {
	if (initTimerID != null) {
		clearTimeout(initTimerID);
		initTimerID=null;
	}
	for (x=0; x<rotatorItems.length; x++) {
		rotatorStartPlaying(x);
	}
}
var initTimerID = setTimeout('rotatorInitialStartup()', 2200);


// This is what to add from the page
// Note: addNews works on last index of rotatorItems, i.e. the most recently added.
// - You create a new rotator item, and then add all you want.
// syntax:
// new rotatorBlock(htmlElement,Showdelay,Transitiondelay)

/*rotatorItems[rotatorItems.length] = new rotatorBlock('stories',5000, 600);
addNews("XML tree control","Build an XML-Based Tree Control With JavaScript","http://www.devx.com/getHelpOn/Article/11874","More Info...","dhtml.gif");
addNews("Forms validation","Automate Your Form Validation","http://www.devx.com/gethelpon/10MinuteSolution/16474","Full Story...","web.gif");

rotatorItems[rotatorItems.length] = new rotatorBlock('bingo',4900,650);
addNews("Item lists","Move Items Between Lists With JavaScript","http://www.devx.com/GetHelpOn/10MinuteSolution/16372","All about it...","watch.gif");
addNews("Forms","Create Fast, Smooth Multi-Page Forms With JavaScript","http://www.devx.com/webdev/Article/10483","More Info...","form.gif");
addNews("See you","...around some time, pal","","Read on...",null);
*/
/*
<html>
<head>
<title>News Rotator</title>
<style>
a{
	text-decoration: none;
}
a:hover{
	text-decoration: underline;
}
</style>
<script language="JavaScript" src="rotate.js"></script>
</head>
<body >
<table cellpadding="0" cellspacing="0" width="140" height="150" style="border: 1px rgb(254,189,45) solid; font: 9pt Verdana;font-weight: bold;">
<tr style="height:14pt; width: 140;">
<td style="background-color: rgb(254,189,45); padding: 5px; text-align: center;">Bla bla</td>
</tr>
<tr>
<td><div id="stories" style="padding: 5px; height:300;">WAIT...</div></td>
</table>

<table cellpadding="0" cellspacing="0" width="140" height="150" style="border: 1px rgb(254,189,45) solid; font: 9pt Verdana;font-weight: bold;" ID="Table1">
<tr style="height:14pt; width: 140;">
<td style="background-color: rgb(254,189,45); padding: 5px; text-align: center;">blurp blurp</td>
</tr>
<tr>
<td><div id="bingo" style="padding: 5px; height:00;">WAIT...</div></td>
</table>
</body>
</html>

*/