var scrllTimer;
var cursorPosition = 0;
var scrollDirection = 1;
var scrollSpeed = 1;
var scrollOffset = 0;
var marginItem = 0;
function startScroll(){
	if( cursorPosition <= $('div#scroll').offset().left + (($('div#scroll').width()/2) + ($('div#scroll').width()/8)) ){
		scrollDirection = -1;
		scrollSpeed = (($('div#scroll').offset().left + (($('div#scroll').width()/2) + ($('div#scroll').width()/8))) - cursorPosition) / 100;
	}else{
		scrollDirection = 1;
		scrollSpeed = (cursorPosition - ($('div#scroll').offset().left + (($('div#scroll').width()/2) + ($('div#scroll').width()/8)))) / 100;
	}

	$('div#scroll span.scroll:first-child').css("marginLeft", (parseInt($('#scroll span.scroll:first-child').css("marginLeft").replace(/auto/i, 0)) + (scrollDirection * parseFloat(scrollSpeed))) + "px");
	var curItem = $("div#scroll span.scroll:first-child");
	var lastItem = $("div#scroll span.scroll:last-child");
	var leftMargin = parseFloat(curItem.css('marginLeft'));
	if ((leftMargin >= 1 && scrollDirection == 1) || (leftMargin < -(curItem.width() + 1) && scrollDirection == -1)){
		curItem.css({marginLeft:'0', marginRight:'1px'});
		if(scrollDirection == 1){
			$('div#scroll').remove("span.scroll:last-child");
			lastItem.css('marginLeft', -(curItem.width() + leftMargin)+'px');
			lastItem.prependTo('div#scroll');
		}
		else{
			$('div#scroll').remove("span.scroll:first-child");
			curItem.appendTo('div#scroll');
		}
	}
	
	scrllTimer = setTimeout("startScroll()",1);
	return true;
}

$(document).ready(function() {
		$('#scroll').hover(
			function(e){
				cursorPosition = e.pageX;
				startScroll(); 
			},
			function(e){
				cursorPosition = e.pageX;
				clearTimeout(scrllTimer); 
			}
		)
		.mousemove(function(e){
			cursorPosition = e.pageX;
		});
});
