/* first page news ticker */

var newsitems = Array();
var scroll_index = 0;
var scroll_height = 0;
var s;
var scroll_timeout = 100;
var pause = false;
var min_height;

function setup_scroller() {
	
	if ((s = document.getElementById('scroller')) != null) {
	
		var tmp = s.getElementsByTagName('DIV');
		newsitems = [];
		for (var i = 0; i< tmp.length; i++) {
			if (tmp[i].className == 'newsall') {
				newsitems[0] = tmp[i];
			}
		}
		scroll_height = $('.newsall').height();
		var copynews = newsitems[0].cloneNode(true);
		newsitems[0].parentNode.appendChild(copynews);
		newsitems[newsitems.length] = copynews;
		
		if (newsitems.length > 0) {
			for (i=0; i<newsitems.length; i++) {
				newsitems[i].style.top = i * scroll_height + "px";
				newsitems[i].style.display = 'block';
			}

			min_height = -scroll_height;
			
			if (newsitems.length > 0) {
//				setInterval(scroll, scroll_timeout)
				setTimeout(scroll, scroll_timeout);
			}
		}
		
		/* pause */ 
		$('#scroller').mouseover(function() {
			pause = true;
		});

		$('#scroller').mouseout(function() {
			pause = false;
		});
	}
}

function scroll() {
	
	if ( pause != true ) {
		for (i=0; i<newsitems.length; i++) {
			
			current_top = parseInt(newsitems[i].style.top);
			
			if (current_top < min_height) {
				newsitems[i].style.top = ((newsitems.length-1) * scroll_height) + "px";
				current_top =  ((newsitems.length-1) * scroll_height);
			}
			
			newsitems[i].style.top = (current_top - 1) + "px";
			
		}
	
	}
	
	setTimeout(scroll, scroll_timeout);
}

/*
	INIT
*/

$(document).ready(function() {
	setup_scroller();
});



