$(document).ready(function () {

	var WidthField = 921;
	var CountItem = $(".SlideBoxItem").length;
	var DefaultActive = 0;
	var Active = 0;
	var WidthItem = Math.ceil((910/CountItem), 0);
	var Speed = 1000;

	Slide = function () {

		if (Active>=CountItem) Active = 0;
		if (Active<0) Active = (CountItem-1);

		$(".SlideBoxButton").animate({ left: Active*WidthItem+'px' }, Speed);

		$("#SlideBoxField").animate({ left: -Active*884+'px' }, Speed);
	};

	Start = function () {

		play = setInterval(function () {

			Active++;

			Slide();

		}, 4000);

	};

	if (CountItem)
	{
		$("#SlideBoxArrLeft, #SlideBoxArrRight").fadeIn();

		$("#SlideBoxPage").append('<a class="SlideBoxButton SlideBoxButtonActive" style="width: '+WidthItem+'px;"></a>');

		$("#SlideBoxField").css({ width: WidthField*CountItem+'px' });

		$("#SlideBoxArrRight").click(function () {

			Active++;

			Slide();

		});

		$("#SlideBoxArrLeft").click(function () {

			Active--;

			Slide();

		});

		$("#SlideBoxArrLeft, #SlideBoxArrRight").hover(function () {

			clearInterval(play);

		},
		function () {
			Start();
		});

		Start();
	}
});
