// JavaScript Document

	var scroller_headline_count;
	var scroller_headline_interval;
	var scroller_current_headline = 0;
	var scroller_old_headline = 0;


$(document).ready(function(){
						   
	$("#scrollup").randomize("div.headline");
	
	scroller_headline_count = $("div.headline").size();
	$("div.headline:eq(" + scroller_current_headline + ")").css('top', '5px');
	
	scroller_headline_interval = setInterval(headline_rotate,1200);		   
						   
});

function headline_rotate() {
	scroller_current_headline = (scroller_old_headline + 1) % scroller_headline_count; 
	$("div.headline:eq(" + scroller_old_headline + ")").animate({top: -205},"slow", function() {
		$(this).css('top','210px');
	});
	$("div.headline:eq(" + scroller_current_headline + ")").show().animate({top: 5},"slow");  
	scroller_old_headline = scroller_current_headline;
}

(function($) {

	$.fn.randomize = function(childElem) {
	  return this.each(function() {
		  var $this = $(this);
		  var elems = $this.children(childElem);
	
		  elems.sort(function() { return (Math.round(Math.random())-0.5); });  
	
		  $this.remove(childElem);  
	
		  for(var i=0; i < elems.length; i++)
			$this.append(elems[i]);      
	
	  });    
	}
})(jQuery);

