var indexPhoto = 1;

// celkovy pocet fotek
var photosCount = 5;

// rychlost animace fotky
var speedAnimate = 4000;

// animace fotek
var photo_animate;
var photo_hover = false;

function changePhoto()
{
    indexPhoto = indexPhoto + 1;

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

function runAnimate()
{
    $("#main_banner #pict" + indexPhoto).fadeOut(1000);
    changePhoto();
    $("#main_banner #pict" + indexPhoto).fadeIn(1000);
    photo_animate = setTimeout(function() { runAnimate(); }, speedAnimate);
}

function switchPict(id)
{
    // znovuspusteni animace, pokud na ni uzivatel uz neni mysi
    //indexPhoto = indexPhoto - 1;
    $("#main_banner #pict" + indexPhoto).fadeOut(1000);
    $("#main_banner #pict" + id).fadeIn(1000);
    indexPhoto = id;
    photo_hover = false;
}

function actualizeTime()
{
    var el = $("#presny-cas-time");

    if (!el || !el.length) {
        return;
    }

    time = new Date();
    h = time.getHours();
    m = time.getMinutes();
    s = time.getSeconds();

    h = ((h < 10) ? "0" : "") + h;
    m = ((m < 10) ? "0" : "") + m;
    s = ((s < 10) ? "0" : "") + s;

    el.html(h + ":" + m + ":" + s);
}

function planTimeActualization()
{
    actualizeTime();
    setTimeout("planTimeActualization()", 900);
}

$(document).ready(function()
{
    // stop / start animace fotky
    $("#main_banner").hover(
        function() {
            // zastaveni animace, pokud na ni uzivatel najel mysi
            clearTimeout(photo_animate);
            photo_hover = true;
        },
        function () {
            if (photo_hover == true) runAnimate();
        }
    );

    var presny_cas = $("#pc");
    var weather = presny_cas.html();

    if (presny_cas && presny_cas.length) {
        presny_cas.html("<a href=\'http://www.presnycas.cz/\' onclick=\'return !window.open(this.href)\'>Přesný čas</a>:&nbsp;<span id=\'presny-cas-time\'></span>" + weather);
        planTimeActualization();
    }

});


