/**
*	Simple jQuery Carousel
*	Author: Arik Yudin, 2012
*/

/*  Settings parameters */
var ItemWidth = 196;	// Specifies each item width
var ItemsAtOnce = 3;	// Specifies how much items to display at once
/* Endof settings */


$(document).ready(function(){

var shift = 0;

for (i=1;i<ItemsAtOnce+1;i++){
	var selector = $('#promotionsblock ul li:nth-child('+i+')').html();
	$('#promotionsblock ul').append('<li>'+selector+'</li>');
}

var $numOfItems = $('#promotionsblock ul li').length;

$('#promotionsblock ul').css({width:($numOfItems * ItemWidth)});

$('#nextarrow').click(function(){
	if (Math.abs(shift) < ItemWidth * ($numOfItems - ItemsAtOnce)){
		shift -= ItemWidth;
		shiftBlock(shift);
	}
	
	else {
		shift = 0;		
		$('#promotionsblock ul').css({left:shift});
		shift -= ItemWidth;
		shiftBlock(shift);
	}
	
});
$('#prevarrow').click(function(){
	if (Math.abs(shift) > 0){
		shift += ItemWidth;
		shiftBlock(shift);
	}
	else {
		shift -= ItemWidth * ($numOfItems - ItemsAtOnce);
		$('#promotionsblock ul').css({left:shift});
		shift += ItemWidth;
		shiftBlock(shift);
	}

});

});

function shiftBlock(shift){
	$('#promotionsblock ul').animate({left: 0+shift},500);
	$('#prevarrow').focus();
}
