$(document).ready(function() {
	var $container=$('#home-sticky-1');

	$('div#home-sticky>div').each(function() {
		$headline=$(this).html();
		if (this.id=='home-sticky-1') $container.empty();
		$('<div></div>').addClass('headline').append($headline).appendTo($container);
	});
	var fadeHeight=$container.height() / 4;
	for (var yPos=0; yPos<fadeHeight; yPos +=2) {
		$('<div></div>').css({
			opacity: yPos/fadeHeight,
			top: $container.height()-fadeHeight+yPos
		}).addClass('fade-slide').appendTo($container);
	}

	var currentHeadline=0, oldHeadline=0;
	var hiddenPosition=$container.height()+10;
	var headlineCount=$('div.headline').length;
	var pause;
	
	$('div.headline').eq(currentHeadline).css('top',0);
	
	var headlineRotate=function() {
		currentHeadline=(oldHeadline+1) % headlineCount;
		$('div.headline').eq(oldHeadline).animate(
			{top:  -hiddenPosition}, 'slow', function() {
				$(this).css('top',hiddenPosition);
			});
		$('div.headline').eq(currentHeadline).animate(
			{top: 0}, 'slow', function() {
				pause=setTimeout(headlineRotate,5000);
			});
		oldHeadline=currentHeadline;
	};
	pause=setTimeout(headlineRotate,5000);
});

