
function carrouselCyclique(id, nb_visibles, width, vitesse)
{
	placeFake(id,nb_visibles,width);
	
	$('#'+id+' a.next').bind('click',function(){
		nextPasCenter(id, nb_visibles, width, vitesse);
		return(false);
	});
	
	$('#'+id+' a.prev').bind('click',function(){
		previousPasCenter(id, nb_visibles, width, vitesse);
		return(false);
	});
}

function placeFake(id,nb_visibles,width)
{
	//placement des fake;
	
	var fake_left='';
	var fake_right='';
	var total;
	var fake_tmp1='';
	var fake_tmp2='';
	
	$('#'+id+' .fake').remove();
	
	total=$('#'+id+' .item-cyclique').length;

	$('#'+id+' .item-cyclique').each(
		function(i)
		{
			fake_left+='<div class="item-cyclique fake">'+$(this).html()+'</div>';
			
			if(total<=nb_visibles)
			{
				if(total+i<nb_visibles)
				{
					//juste rempli avec rien Ã  droite
					fake_right+='<div class="item-cyclique fake">'+$(this).html()+'</div>';
					fake_tmp1+='<div class="item-cyclique fake">'+$(this).html()+'</div>';
				}
				else
				{
					fake_tmp2+='<div class="item-cyclique fake">'+$(this).html()+'</div>';
				}
			}
			else
			{
				if(i<nb_visibles)
				{
					//juste rempli avec rien Ã  droite
					fake_tmp2+='<div class="item-cyclique fake">'+$(this).html()+'</div>';
				}
			}
		}
	);
	$('#'+id+' .items-cyclique').prepend(fake_left);
	$('#'+id+' .items-cyclique').append(fake_right+fake_tmp2+fake_tmp1);
	
	$('#'+id+' .items-cyclique').css('left','-'+(width*total)+'px');
		
}

function nextPasCenter(id, nb_visibles, width, vitesse)
{
	var total;
	var left;
	var totalNonFake;
			
	$('#'+id+' a.next').unbind('click').bind('click',function(){return(false)});
			
	totalNonFake=$('#'+id+' .item-cyclique').length-$('#'+id+' .fake').length;
	total=$('#'+id+' .item-cyclique').length;
	left=parseInt($('#'+id+' .items-cyclique').css('left'));
			
	$('#'+id+' .items-cyclique').animate({left:'-='+240},vitesse,function(){
				
		$('#'+id+' a.next').bind('click',function()
		{
			nextPasCenter(id, nb_visibles, width, vitesse);return(false);
		});
	
		if(parseInt($(this).css('left'))<((-1)*width*(total-nb_visibles-1)))
		{
			$(this).css('left','-'+(width*totalNonFake)+'px');
		}
		return false;
	});	
	return false;
}
		
		
function previousPasCenter(id, nb_visibles, width, vitesse)
{
	var total;
	var left;
	var totalNonFake;
			
	$('#'+id+' a.prev').unbind('click').bind('click',function(){return(false)});
			
	totalNonFake=$('#'+id+' .item-cyclique').length-$('#'+id+' .fake').length;
	total=$('#'+id+' .item-cyclique').length;
	left=parseInt($('#'+id+' .items-cyclique').css('left'));
			
	$('#'+id+' .items-cyclique').animate({left:'+='+240},vitesse,function()
	{
				
		$('#'+id+' a.prev').bind('click',function()
		{
			previousPasCenter(id, nb_visibles, width, vitesse);return(false);
		});
		
		if(parseInt($(this).css('left'))>=0)
		{
			$(this).css('left','-'+(width*totalNonFake)+'px');
		}
				
		return false;
	});

	return false;
}

