// borderline cases for ul.works
var counter = 0;
function checkBorderlineCases(){
	var listNum = $("ul.works > li").length;
	if (counter < listNum - 4)
		{$(".forward").css("display", "block");}
	else 
		{$(".forward").css("display", "none");}
	
	if (counter > 0)
		{$(".back").css("display", "block");}
	else 
		{$(".back").css("display", "none");}
}

// define width for ul.works
$(document).ready(
	function(){
		checkBorderlineCases();
		var listNum = $("ul.works > li").length;
		var listWidth = listNum*130;
		$("ul.works").css("width", listWidth);
	}
)

// scroll back and forward
$(document).ready(
	function(){
		$(".forward").click(function(){
			var listNum = $("ul.works > li").length;
			counter+=1;
			checkBorderlineCases();
			if (counter > (listNum - 4)){
				counter = (listNum - 4);
				return false
			}
			$("ul.works").animate({left: "-=130"}, 400);
		})
		$(".back").click(function(){
			var listNum = $("ul.works > li").length;
			counter-=1;
			checkBorderlineCases();
			if (counter < 0){
				counter = 0;
				return false;	
			}
			$("ul.works").animate({left: "+=130"}, 400);
		})
	}
)
