$(document).ready(function() {
	
	/* var inte = null;
	
	inte = setInterval( function() { 
	$( "div#rotaIn img" ).animate( {"left": "+=50px" } , "slow"); 
	}  , 1000 ) */
	dir = -1;
	$('.lewa').click( function(){ dir = -1 } ).css('cursor','pointer');
	$('.prawa').click( function(){ dir = 1 } ).css('cursor','pointer');
	przewin( '#rotaIn-old div', 1 );
});

function przewin( cnt )
{
	if( dir==-1 )
	{
		size = $(cnt).children().eq(0).outerWidth();
		$(cnt).animate({'margin-left':'-'+size+'px'},2000,'linear',function(){
			$(cnt).children().eq(0).clone().appendTo(cnt);
			$(cnt).css('margin-left','0px').children().eq(0).remove();
			przewin( cnt );
		});
	}
	else
	{
		len = $(cnt).children().length-1;
		size = $(cnt).children().eq(len).outerWidth();
		$(cnt).css('margin-left','-'+size+'px').children().eq(len).clone().prependTo(cnt);
		$(cnt).animate({'margin-left':'-0px'},2000,'linear',function(){
			$(cnt).children().eq(len+1).remove();
			przewin( cnt );
		});
	}
}

/* function przewin( cnt, krk )
{
	if( dir==-1 )
	{
		size = $(cnt).children().eq(0).outerWidth();
		$(cnt).stop(true,true).animate({'margin-left':'-'+parseInt(krk*(size/10))+'px'},500,'linear',function(){
			if( krk==10 )
			{
				$(cnt).children().eq(0).clone().appendTo(cnt);
				$(cnt).css('margin-left','0px').children().eq(0).remove();
			}
			przewin( cnt, krk<10 ? krk+1 : 1 );
		});
	}
	else
	{
		len = $(cnt).children().length-1;
		size = $(cnt).children().eq(len).outerWidth();
		if( krk==1 ) $(cnt).children().eq(len).clone().prependTo(cnt);
		$(cnt).css('margin-left','-'+parseInt((size/10)*(11-krk))+'px')
		$(cnt).stop(true,true).animate({'margin-left':'-'+parseInt((size/10)*(10-krk))+'px'},500,'linear',function(){
			if( krk==1 ) $(cnt).children().eq(len+1).remove();
			przewin( cnt, krk<10 ? krk+1 : 1 );
		});
	}
} */

