var ulWidth;
var lock;
var left;
var scrollStarted = false;
var x = 1;
var counter = 0;

function moveOne(){
if(!lock){
	lock = true;
	counter = counter - x;

	oneLength = ((ulWidth)/3);
	
	startpos = -oneLength;

	distance = $(".home-scroller-wrapper ul li").width()+6;

	leftVal = $(".home-scroller-wrapper ul").css('left');
	leftVal = parseFloat((""+leftVal).replace(/px/,""));


	$(".home-scroller-wrapper ul").animate({left:leftVal+(distance * x)},600,'swing', 
		function(){
			lock = false;
			if(counter==items||counter==-items){
				$(".home-scroller-wrapper ul").css({left:startpos})
				counter=0;}
		});
	}
}


$(document).ready(function(){

	$(".home-scroller-left").show();
	$(".home-scroller-right").show();

	$(".home-scroller-wrapper").width(509);

	items = $(".home-scroller-wrapper ul li").size();

	$(".home-scroller-wrapper").css({overflow:'hidden'});

	repeat = $(".home-scroller-wrapper ul").html();

	repeat = repeat+repeat;

	$(".home-scroller-wrapper ul").append(repeat);
	ulWidth= items * 3 * ($(".home-scroller-wrapper ul li").width()+6);

	$(".home-scroller-wrapper ul").css({width:ulWidth,position:'relative',left:-(ulWidth/3)});

	$(".home-scroller-left a").click(function(){x=1; moveOne();});
	$(".home-scroller-right a").click(function(){x=-1; moveOne();});
	
});
