$(document).ready(function() {

	if($('#widget_liveScoreboard')) {

		var gameDivWidth = 126;  // 126 = width+padding+margin of one game
		var games2show = 4;
		var ajaxRegets = 0;
		var animationInterval = 5000; // 5 seconds
		var marginIncrement = gameDivWidth * games2show;
		var numGames = $('.lsbGame').size();
		var totalw = numGames * gameDivWidth;
		if (totalw<510)
			totalw = 510;

		$('#lsbGames').css('width',totalw);

		function animate () {
			var curMargin = parseInt($('#lsbGames').css('marginLeft'));
			if ( curMargin - marginIncrement < -(totalw-marginIncrement)) {
				// if animating will cost the left margin to be more than the whole total width
				// ... it means we've reached the end, go back to beginning
				$('#lsbGames').animate({marginLeft: 0},800);
			}
			else {
				$('#lsbGames').animate({marginLeft: '-='+marginIncrement},500);
			}
		}
		var animationInterval = setInterval(animate,animationInterval);
		
		
		function regetData() { 
			$.ajax({
				url: '/news/widget/scoreboard.php',
				data: ({ 'ajax': 1 }),
				success: function(resp) {
					$('#lsbGames').html(resp);
					++ajaxRegets;
					if (ajaxRegets<4) { // limit amount of tracks
						_gaq.push(['_trackPageview', '/scoreboard/front']);
					}
				}
			});
		}
		var regetInterval = setInterval(regetData,120000);  // every 2 minutes
	
	}
	
})
