
function News(newsDiv, newsDelay) {
	
	this.scrolldelay = parseInt(newsDelay); 	
	this.newsElement = document.getElementById(newsDiv);
	
	this.newsArray = new Array();
	this.newsItem = -1;
	
	this.newsContainer = document.createElement("div");
	this.newsContainer.setAttribute("id","newsContainer");

	this.prepare();
	this.clear();
	this.display();
}

News.prototype.prepare = function() {
	parentElement = this.newsElement;
	y = 0;
	
	for( i = 0; i < parentElement.childNodes.length; i++ ) {
		var list = parentElement.childNodes.item(i);
		
		if(list.nodeName == "UL") {
			for( x = 0; x < list.childNodes.length; x++ ) {
				var listItem = list.childNodes.item(x);
				if(listItem.nodeName == "LI") {
					this.newsArray[y] = listItem.innerHTML;
					y++;
				}
			}
		}
	}
	return this.newsArray;
}

News.prototype.clear = function() {
	this.newsElement.innerHTML = "";
}

News.prototype.display = function() {
	var News = this;
	
	this.newsItem++;
	this.newsContainer.innerHTML = this.newsArray[this.newsItem];
	this.newsElement.appendChild(this.newsContainer);
	
	function timerRelay() {
		News.display();
	}
	
	// call loop function
	if(this.newsItem < this.newsArray.length-1) {
		var newsScroll = setTimeout(timerRelay, this.scrolldelay);
	} 
	
	// reset
	if(this.newsItem == this.newsArray.length-1) {
		this.newsItem = -1;
		var newsScroll = setTimeout(timerRelay, this.scrolldelay);
	} 
}


