$(function() {
	$("#ProductsMenu a").click(function(){
		var index = $(this).index()+1;
		$("#ProductsMenu a").removeClass();
		$("#ProductsMenu a").eq(index-1).addClass("current"+index+"");
		$("#ProductsBig .item").css("display", "none");
		$("#ProductsBig .item").eq(index-1).css("display", "block");		
		return false;
	})

	/*scoller*/
	var ScrollerContentWidth, Scrolled, ScrollTimerId, AbsWidth;
	ScrollerContentWidth = ($(".scroller .dish:last").index()+1)*200;
	$(".scroller .content ").css("width", ScrollerContentWidth+"px" );

	AbsWidth = 600; //ширина блока контента c оверфлоу хидден

	$(".scroller .left, .scroller .right").click(function(){
		return false;
	})	

	function InitScrollerContent(){
		Scrolled = 	$(".scroller .contentarea .content").css("left").substring(0, $(".scroller .contentarea .content").css("left").length-2);
		return parseInt(Scrolled);
	}
	
	function Scroll(direction){
		if (direction == "right"){
			if (Math.abs(Scrolled) < ScrollerContentWidth - AbsWidth ){
				Scrolled = parseInt(Scrolled);				
				Scrolled-=2;
				$(".scroller .contentarea .content").css("left", Scrolled+"px");
			}
			ScrollTimerId = setTimeout(function(){Scroll(direction)}, '10');
		}
		
		if (direction == "left"){						
			if (Math.abs(Scrolled) > 0){
				Scrolled = parseInt(Scrolled);				
				Scrolled+=2;
				$(".scroller .contentarea .content").css("left", Scrolled+"px");
			}
			ScrollTimerId = setTimeout(function(){Scroll(direction)}, '10');
		}
	}
	

	$(".scroller .left").mousedown(function(){		
		var left = InitScrollerContent();		
		if (left == 0){
			return false;
		}
		if (left <= ScrollerContentWidth){
			ScrollTimerId = setTimeout(function(){Scroll("left")}, '0');
		}
	})

	$(".scroller .right").mousedown(function(){
		var left = InitScrollerContent();		
		if (left <= ScrollerContentWidth){
			ScrollTimerId = setTimeout(function(){Scroll("right")}, '0');
		}		
	})



	$(".scroller .right, .scroller .left").mouseup(function(){
		clearTimeout(ScrollTimerId);
	})
});


