/* 	Scrolling ticker
*/

var interval = 700;
var pause = 3000;
var tickerHeight = 17;
var divID = 'nieuwsticker';
var topMargin = 2;
var i;

window.addEvent('domready', function() {
	startticker();
});


function startticker() {

	if (ge(divID)) {
		
		i = ge(divID).getElementsByTagName("div");
		
		activeItem = 0;
		
		if (i[activeItem]) {
			i[activeItem].style.visibility = 'visible';
		}
		
		if (i.length > 1) {
		  timeoutID = setTimeout('nextItem()', pause);
		}

	 } else {
	 	
	 	setTimeout('startticker()', 100)
	 
	 }

}


function nextItem() {
	var prevItem = activeItem;
	activeItem = (prevItem == i.length - 1) ? 0 : prevItem + 1;
	scrollticker(prevItem, activeItem);
}


function scrollticker(from, to) {
    var setTop = new Fx.Style(i[to], 'top');
    setTop.set(0 - tickerHeight);
    $(i[to]).effect('top',{
			onStart: function(){ i[to].style.visibility = 'visible';},
            duration: interval,
			transition:Fx.Transitions.Cubic.easeOut
		}).start(0 - tickerHeight, topMargin);
    $(i[from]).effect('top',{
			onComplete: function(){ i[from].style.visibility = 'hidden'; timeoutID = setTimeout('nextItem()', pause);},
            duration: interval,
			transition:Fx.Transitions.Cubic.easeOut
    }).start(topMargin, tickerHeight);
}