var indexPhoto = 1;

// pocet fotek
var photosCount = 1;

// rychlost animace fotky
var speedAnimate = 5000;

var photo_animate;
var photo_hover = false;

$(document).ready(function() {
    photosCount = $('#banners a.banner').length;

    if (document.getElementById('banner-2')) {
        photo_animate = setTimeout(function() { runAnimate(); }, speedAnimate);

        // stop / start animace fotky
        $('#banners').hover(
            function() {
                // zastaveni animace, pokud na ni uzivatel najel mysi
                clearTimeout(photo_animate);
                photo_hover = true;
            },
            function() {
                // znovuspusteni animace, pokud na ni uzivatel uz neni mysi
                photo_animate = setTimeout(function() { runAnimate(); }, speedAnimate);
                photo_hover = false;
            }
        );
    }
});

function changePhoto()
{
    indexPhoto = indexPhoto + 1;

    if (indexPhoto > photosCount) {
        indexPhoto = 1;
    }
}

function runAnimate()
{
    $('#banner-' + indexPhoto).fadeOut(800);
    changePhoto();
    $('#banner-' + indexPhoto).fadeIn(800);

    if (!photo_hover) {
        photo_animate = setTimeout(function() { runAnimate(); }, speedAnimate);
    }
}

