function przesun (ilosc){
    var aktualny = 0;
    $("div#rotator div.item").each(function(index){
        if($(this).hasClass("start")){
          aktualny = index; 
        }
    });
    var nastepny = aktualny + 1;
    if(nastepny >= ilosc){
        nastepny = 0;
    }
    $("div#rotator div.item:eq("+aktualny+")").css("z-index","2");
    $("div#rotator div.item:eq("+nastepny+")").css({"left":"0","z-index":"1"}).addClass("start")
    $("div#rotator div.item:eq("+aktualny+")").animate(
        {"left":"+=950px"},
        1000,
        function() {
        $(this).removeClass("start").css("left","950px");
      });
}

$(document).ready(function(){ 
    $("div#rotator div.item").css({"left":"950px","z-index":"2"});
    var count = $("div#rotator div.item").size();
    var pokazLosowy = parseInt(Math.random()*100)%count;
    $("div#rotator div.item:eq("+pokazLosowy+")").css({"left":"0","z-index":"1"}).addClass("start");

    var refreshIntervalId = setInterval(function(){przesun(count)}, 5000);
    $("div#rotator span.next").click(function(){
        clearInterval(refreshIntervalId);
        przesun(count);
        refreshIntervalId = setInterval(function(){przesun(count)}, 5000);
    });
});
