/*
e.g.
<div id="alldivs" style="height:250px;" onmouseover="stopSlide()" onmouseout="slide('start')">
    <div id="akcja1">tresc danej zakladki</div>
    <div id="akcja2" (...)
</div>
*/
$(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="font-size:10px;padding:2px 4px;background-color:#fff;border:1px solid #81C3EB;color:#F09F03;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.backgroundColor='#fff';
    if(count!=0) document.getElementById("akcja"+count).style.display='none';
    count=position(count,'next');
    document.getElementById("butt"+count).style.backgroundColor='#D5EEFE';
    $("#akcja"+count).fadeIn('slow');
    //count=position(count,'next');
    slides=setTimeout("slide()",7000);
}


function stopSlide(){
    clearTimeout(slides);
}

function showAkcja(id){
    stopSlide();
    //count=id;
    document.getElementById("butt"+count).style.backgroundColor='#fff';
    document.getElementById("akcja"+count).style.display='none';
    document.getElementById("butt"+id).style.backgroundColor='#D5EEFE';
    $("#akcja"+id).fadeIn('slow');
    count=id;   
    
}
