/* Vertical scrolling script inspired by: 
Robert Suppenbach ::webdevel.deezhosts.net
The JavaScript Source - http://javascript.internet.com 
Improved by martinheinsdorf@codesign.net */

var toScroll = new Array()
var news_item_slot = 0;
var news_item_index;
var scroller_delay;
var scroller_height;

function addItem(text) {
	toScroll[news_item_slot] = text;
	news_item_slot++;
}

function construct(){
    document.getElementById("firstNews").innerHTML = toScroll[0];
    document.getElementById("secondNews").innerHTML = toScroll[toScroll.length < 2? 0 : 1];
}

function move(div_id) {
	if (parseInt(document.getElementById(div_id).style.top) > 0 && parseInt(document.getElementById(div_id).style.top) <= 5) {
    	document.getElementById(div_id).style.top = "0px";
    	setTimeout("move('firstNews'); move('secondNews')", scroller_delay);
		return;
  	}
	if (parseInt(document.getElementById(div_id).style.top) >= - parseInt(document.getElementById(div_id).offsetHeight)) {
		document.getElementById(div_id).style.top = parseInt(document.getElementById(div_id).style.top) - 5 + "px";
    	setTimeout("move('" + div_id + "')", 50);
	}
	else {
		document.getElementById(div_id).style.top = scroller_height;
    	document.getElementById(div_id).innerHTML = toScroll[news_item_index];
		news_item_index++;
		news_item_index %= toScroll.length;
	}
}

function startScroll() {
	news_item_index = (toScroll.length > 2)? 2 : 0;
	document.getElementById("firstNews").style.top = '1px';
	document.getElementById("secondNews").style.top = scroller_height;
	move('firstNews');
}

window.onload = function() { 
   scroller_delay = 4000; // pause time in milliseconds
   scroller_height = "209px"; // must also change in CSS
   
   var articles = document.getElementById("news_source").getElementsByTagName("DIV");
   for (var article_index = 0; article_index < articles.length; article_index++) {
       addItem(articles[article_index].innerHTML);
   }
   construct();
   startScroll();
};
