var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var rotation_time = 6000; //time in milliseconds
var animation_time = 2000; //time in milliseconds

$(document).ready(function(){
	headline_count = $("div.scrolling_headline").size();
	current_headline = 0;
	var h1=$("#scrolling_headline"+current_headline).height();
	if ($("#scrollup_right").height())
		var h2=$("#scrollup_right").height();
	else
		var h2=$("#scrollup_left").height();
	h=Math.round((h2-h1)/2.3);
	
	$("#scrolling_headline"+current_headline).show().animate({top: h},animation_time);
	if (headline_count>1) headline_interval = setInterval(headline_rotate,rotation_time);
	old_headline = current_headline;
});

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count
	if ($("#scrollup_right").height())
		var h2=$("#scrollup_right").height();
	else
		var h2=$("#scrollup_left").height();
	var h1=$("#scrolling_headline"+current_headline).height();
	var h3=$("#scrolling_headline"+old_headline).height();

	$("#scrolling_headline"+old_headline).animate({top: -h3},animation_time, function() {
    	$(this).css('top', h2+'px');
    });
	h=Math.round((h2-h1)/2.3);
	$("#scrolling_headline"+current_headline).show().animate({top: h},animation_time);
	old_headline = current_headline;
}