var scrollItems;
var scrollPos = 0;
var itemWidth = 0;
var timmer;


$(document).ready(function(){
	scrollItems = $("#scroll div.items div.screenshots").length;
	itemWidth = parseInt($("div.screenshots").css("width"));
	
	$("#scroll").mouseover(function(){
		$(document).stopTime();
	}).mouseout(function(){
		startTime();
	});
	
	$("#scroll div.scrollInd a").click(function(){
		idScreenShot = parseInt($(this).attr("idScreenShot"));
		gotoItem(idScreenShot);
	});
	
	startTime();
});

function startTime(){
	$(document).everyTime(3000, function(i) {
		moveScroll();
	});
}

function moveScroll(){
	scrollPos++;
	if(scrollPos == scrollItems){
		scrollPos = 0;
	}
	gotoItem(scrollPos);
}

function gotoItem(position){
	posLeft = position * itemWidth;
	
	$("#scroll div.items").animate({
		left : 0 - posLeft
	}, 250);
	
	$("#scroll div.scrollInd a").attr("class", "scrollControl");
	$("#scroll div.scrollInd a#ind" + position).attr("class", "scrollControlSel");
}

