/*var news;

function news_received(data){
	data = data.substring(data.indexOf('<!--END DEMOS SNIPPET-->'), data.indexOf('<!--FOOTER CHUNK -->'));
	data = data.substring(data.indexOf('<h3>'));
	while (data.indexOf('Read more</a></p>') > -1){
		var part = data.substring(data.indexOf('<h3>'), data.indexOf('Read more</a></p>')) + 'Read more</a></p>';
		data = data.substring(part.length);
		alert(part);
	}
}

$.get("index.php", {id:"7"}, news_received);
*/
var newsbox;
var currentIndex = 1;
var current;
var next;
var suspendScrolling = false;

function keepOnScrolling(){
	if (parseInt(current.style.top) <= -175){
		current.style.display = 'none';
		next.parentNode.removeChild(current);
		next.parentNode.appendChild(current);
		current = next;
		currentIndex++;
		next = document.getElementById('news' + currentIndex);
		if (!next){
			currentIndex = 0;
			next = document.getElementById('news' + currentIndex);
		}
		current.style.top = '0px';
		next.style.top = '25px';
		next.style.display = '';
		window.setTimeout(keepOnScrolling, 5000);
	}else{
		if (!suspendScrolling){
			current.style.top = (parseInt(current.style.top) - 2) + 'px';
			next.style.top = (parseInt(next.style.top) - 2) + 'px';
		}
		window.setTimeout(keepOnScrolling, 15);
	}
}

function initScrolling(){
	current = document.getElementById('news0');
	if (!current){
		return;
	}
	next = document.getElementById('news1');
	if (!next){
		next = current.cloneNode(true);
		next.id = 'news1';
		current.parentNode.appendChild(next);
	}
	newsbox = current.parentNode;
	newsbox.style.overflow = 'hidden';
	newsbox.onmouseover = function() { suspendScrolling = true; };
	newsbox.onmouseout = function() { suspendScrolling = false; };
	current.style.top = '0px';
	next.style.top = '25px';
	next.style.display = '';
	window.setTimeout(keepOnScrolling, 5000);
}
