var ulWidth = 0;
var liWidths = [];
var liSize = 0;
var currentNum = 0;
var currentLeft = -10;
$(document).ready(function(){
	//setting up the length of the ul
	$('#homeConScroller li').each(function(i){
		ulWidth += $(this).width();
		ulWidth += parseInt($(this).css('margin-right').replace('px',''));
		liWidths[i] = ($(this).width())+parseInt($(this).css('margin-right').replace('px',''));
		//console.log(ulWidth);
		//console.log(liWidths);
	});
	liSize = liWidths.length;
	//console.log(liSize);
	$('#homeConScroller ul').width(ulWidth);
	runScroller();
	
	$('#homeConScroller ul li').hover(
		function(){	$('#homeConScroller ul').pauseAnimation();	},
		function(){	$('#homeConScroller ul').resumeAnimation();	}
	);
});

function runScroller() {
	//console.log(currentNum);
	//console.log(liWidths[currentNum]);
	/*$('#homeConScroller ul').animate({
		left:-currentLeft		 
	},800,function(){ pauseScroller() });
	*/
	speed = liSize * 5500;
	$('#homeConScroller ul').startAnimation({
		left:-ulWidth
	},speed, 'linear', function(){ resetScroller() });
}

function pauseScroller() {
	if(currentNum == liSize-3) {
		currentNum = -1;
		currentLeft = -10;
	} else {
		currentLeft += liWidths[currentNum];
	}
	//console.log('currentLeft: '+currentLeft);
	currentNum++;
	setTimeout("runScroller()",4000);
}

function resetScroller(){
	$('#homeConScroller ul').css('left','960px');
	runScroller();
}


