(function($) {
	function ticker_start() {
		
		var $scroller = $("#breaking_news_ticker_scroller");
		
		//getting the left css value of the '#breaking_news_ticker_scroller' div which contents are getting scrolled
		var css_left = $scroller.css("left");
		
		//Checking that whether left css value is zero. If not zero the start will occur from 100 px left.
		if(css_left != '0px') {
			$scroller.css('left', -830);
		} else {
			$scroller.css('left', -830);
		}
		
		window.ticker_resume();
	}
	
	//pause the scroller when mouse enters to the content this function is called to stop the scrolling the content.
	window.ticker_pause = function() {
		$("#breaking_news_ticker_scroller").stop();
	}	
	
	//resume the scroller. This function resumes the scroller. on mouse out and when page loads this functions scrollss the content
	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 * 15, "linear", function() {
			setTimeout(ticker_start,1);
		});
	}
	
	ticker_start();
	$(window).focus(function(){ ticker_resume(); });
	$(window).blur(function(){ ticker_pause(); });
})(jQuery);
