$(document).ready(function()
{	
	var count = 0;
	var cur = 0;		
	
	$('.scroll-text').each(function() {
		$(this).hide();
		count++;
	});
	
	scroll(1);
	
	function scroll(item) {
		if(item < 1) item = 1;
		if(item > count) item= 1;
		
		var text = $("#text" + item);
		
		text.css("display", "inline-block");
		$('#scroll-carrier').css("display", "inline-block");
		$('#hider').css("left", $('#EtusivuTiedotteet').offset().left);
		$('#hider').css( "width", text.width() );
		$('#hider').animate({
			left: '+=' + ( text.width() + 5 ),
			width:'-=' + ( text.width() - 10)
		}, 2000, function() {
			$("#scroll-carrier").fadeOut(1000, function() {
				text.animate({
					opacity: '1'
				}, 4000, function() {
					text.hide();
					scroll(item + 1);
				});
			});
		});
	
	}
	
});
