(function($) {
	function ticker_start() {
		var $scroller = $("#breaking_news_ticker_scroller");
		$scroller.css('left', 0);
		window.ticker_resume();
	}
	window.ticker_pause = function() {
		$("#breaking_news_ticker_scroller").stop();
	}
	window.ticker_resume = function() {
		var $scroller = $("#breaking_news_ticker_scroller");
		if($scroller.is(":animated")) return;
		var $last = $scroller.find(":last-child");
		var w = $last.position().left + parseInt($scroller.css('left'), 10);
		$scroller.animate({left: -$last.position().left}, w * 30, "linear", function() {
			setTimeout(ticker_start, 100);
		});
	}
	ticker_start();
	$(window).focus(function(){ ticker_resume(); });
	$(window).blur(function(){ ticker_pause(); });
})(jQuery);
