$(document).ready(function() {


	//grab the width and calculate left value
	var item_width = $('.center li').outerWidth();
	var left_value = item_width * (-1); 

    //move the last item before first item, just in case user click prev button
	$('.center').each(function() {
		$(this).siblings('li:first').before($(this).siblings('li:last'));
	});
	
	//set the default item to the correct position
	$('.center ul').css({'left' : left_value});
	
	var animating_vehicle_box = false;
	//if user clicked on prev button
	$('.prev').click(function() {
		var selector = $(this).parent('div').attr('id');
		
		//get the right position
		var left_indent = parseInt($('#' + selector + ' ul').css('left')) + item_width;
		
		//slide the item
		//console.log('Prev CallBack: '+animating_vehicle_box);
		if(!animating_vehicle_box) {
			animating_vehicle_box = true;
			$('#' + selector + ' ul').animate({'left' : left_indent}, 200, "linear", function() {
																							  
				animating_vehicle_box = false;																			  
	
				//move the last item and put it as first item
				$('#' + selector + ' li:first').before($('#' + selector + ' li:last'));           
	
				//set the default item to correct position
				$('#' + selector + ' ul').css({'left' : left_value});
	
			});
		}

		//cancel the link behavior
		return false;

	});

    //if user clicked on next button
	$('.next').click(function() {
		var selector = $(this).parent('div').attr('id');
	
		//get the right position
		var left_indent = parseInt($('#' + selector + ' ul').css('left')) - item_width;
		
		
		//console.log('Next CallBack: '+animating_vehicle_box);
		//slide the item
		if(!animating_vehicle_box) {
			animating_vehicle_box = true;
			$('#' + selector + ' ul').animate({'left' : left_indent}, 200, function()  {
	
				animating_vehicle_box = false;																			  
	
				//move the first item and put it as last item
				$('#' + selector + ' li:last').after($('#' + selector + ' li:first'));                 	
	
				//set the default item to correct position
				$('#' + selector + ' ul').css({'left' : left_value});
	
			});
		
		}

		//cancel the link behavior
		return false;

	});        



});



