var pos = 0;
var height = 80;
var newsEl;
var changeTime = 4000;
var newsCount = 0;
var currentNewsCount = 0;

/* *********************************************************************
 * initScrollNews
 */
function initScrollNews() {
	newsEl = dojo.query(".NewsSelector")[0];
	if (newsEl==null) {
		return;
	}
	
	//alert(newsEl.id);
	newsEl.style.position = "relative";
	newsCount = dojo.query(".NewsSelector .newsEntry").length
	//alert(newsCount);
	currentNewsCount = 0;
	window.setTimeout("scrollBy()", changeTime);	
}

/* *********************************************************************
 * initScrollNews
 */
function scrollBy() {
	if (currentNewsCount < newsCount - 1) {
		pos = pos - 1;
		newsEl.style.top = pos + "px";
		newsEl.style.height = height;
	} else {
		pos = 0;
		currentNewsCount = 0;
		newsEl.style.top = pos + "px";
		newsEl.style.height = height;
		window.setTimeout("scrollBy()", changeTime);
		return;
	}	

	//newsEl.innerHTML = newsEl.style.top + "," + newsEl.innerHTML;//debug
	if ( ((pos % height) == 0) || (pos==0) ) {
		currentNewsCount = currentNewsCount + 1;
		window.setTimeout("scrollBy()", changeTime);
	} else {
		window.setTimeout("scrollBy()", 1);
	}
}

/* *********************************************************************/
/* *********************************************************************/
/* *********************************************************************
 * DoJo onLoad
 */
dojo.addOnLoad(function() { // no linebreak here, because IE doesn't like that
		initScrollNews();
	}
)
