// JavaScript Document
var timer;
$(document).ready(function(){
	$('#newsTicker').css('width', '834px');
	$("#newsTicker").hover(
		function()
		{
			clearTimeout(timer);
		},
		function()
		{
			setWidth();
		}
	);
	setWidth();
});
function moveLayer(width)
{
	maxLeft = (0 - (width / 2) + 2) - 50; // 2;
	var objLeft = $('#newsTicker').css('left');
	if(!isNaN(parseInt(objLeft)))
	{
		$('#newsTicker').css('left', ((parseInt(objLeft) <= maxLeft)?0:parseInt(objLeft)-1)+'px');
	}
	else
	{
		$('#newsTicker').css('left', '0px');
	}
	timer = setTimeout ("moveLayer("+width+");", 25); 
}

// Ensure the width of the scroller is divisible by 2. This allows smooth flowing of the scrolled content
function setWidth()
{ 
	if($('#newsScroller').length == 0 || $('#newsTicker').length == 0)
	{
		return false;
	}
	tableObj = $('#newsScroller')[0];
	obj = $('#newsTicker')[0];
	objWidth = getOffset(tableObj);
	HalfWidth = Math.floor(objWidth / 2);
	newWidth = (HalfWidth * 2) + 2;
	obj.style.width = newWidth;
	moveLayer(newWidth);
}

// Get width and height of layer
function getOffset(obj) 
{
	oWidth = obj.offsetWidth
	return oWidth
}

function mes(message)
{
	$('#debug').html(message);
}
