$(document).ready(function(){
        all=document.getElementById("alldivs").getElementsByTagName("div").length;
        insertButts();
        slide();
});

count=0;

function insertButts(){
    var button = document.getElementById("buttons");
    var buttsDiv='';
    for(i=1;i<=all;i++)
    {
        
        var buttsDiv=buttsDiv+'<span id="butt'+i+'" style="width:21px;height:21px;font-size:10px;padding:5px 8px;background:url(noakt-b.gif) no-repeat;color:white;font-family:Garamond;cursor:pointer;" onclick="showAkcja('+i+')">'+i+'</span>&nbsp;&nbsp;';
        
    }
    button.innerHTML=buttsDiv;
}
function position(count,action){
 if(action=='next'){
    if((count+1)<=all) return count+1;
    else return 1;
    
 }else if(action=='previous'){
    if((count-1)>=1) return count-1;
    else return all;
    
    
 }
}

slides='';
function slide(info){
    clearTimeout(slides);
    if(info=='start') count=position(count,'previous');
    //last=position(count,'previous');
    if(count!=0) document.getElementById("butt"+count).style.backgroundImage='url(noakt-b.gif)';
    if(count!=0) document.getElementById("akcja"+count).style.display='none';
    count=position(count,'next');
    document.getElementById("butt"+count).style.backgroundImage='url(akt-b.gif)';
    $("#akcja"+count).fadeIn('slow');
    //count=position(count,'next');
    slides=setTimeout("slide()",5000);
}


function stopSlide(){
    clearTimeout(slides);
}

function showAkcja(id){
    stopSlide();
    //count=id;
    document.getElementById("butt"+count).style.backgroundImage='url(noakt-b.gif)';
    document.getElementById("akcja"+count).style.display='none';
    document.getElementById("butt"+id).style.backgroundImage='url(akt-b.gif)';
    $("#akcja"+id).fadeIn('slow');
    count=id;   
    
}

