var ArticleScrollTimer = null;
var ArticleScrollTimerTime = 7000;

$(function () {
    //SCROLOVANIE PRACOVNYCH PONUK
    //upravime si vysku scrolleru aby nebola vyzsia ako max
    $('#scrollcontainerContent').css('paddingTop',1);
    $('#scrollcontainerContent').css('paddingBottom',1);
    $('#jobscroller').css('marginBottom',0);
    var jobScrollerCurH = $('#jobscrollerContent').height();
    if (jobScrollerCurH < $('#jobscroller').height()) {
        $('#jobscroller').height(jobScrollerCurH);
        //skopirujeme ponuky
        $('#jobscrollerContent div.scrollitem').clone().appendTo($('#jobscrollerContent'));
    } else if (jobScrollerCurH - $('#jobscrollerContent div.scrollitem:eq(0)').height() < $('#jobscroller').height()) {
        $('#jobscrollerContent div.scrollitem').clone().appendTo($('#jobscrollerContent'));
    }
    
    //celo-klikatelny clanok na hlavnej stranke
    $('dl', '#hmArticles').each(function (idx, el) {
        $(el).css('cursor','pointer').click(function () {
            location.href = $('a:eq(0)',this).attr('href');
            return false;
        });
    });
    
    //SCROLOVANIE CLANKOV
    ArticleScrollTimer = window.setTimeout(function () {
        ArticleScroll();
    },ArticleScrollTimerTime);
    $('#hmArticlesPager div.hm-pagerpage').each(function (idx,el) {
        $(el).click(function () {
            if (ArticleScrollTimer) {
                window.clearTimeout(ArticleScrollTimer);
                ArticleScrollTimer = null;
            }
            ArticleScrollDisplay(idx);
            return false;
        });
    });
});

function ArticleScroll() {
    var nextDisplayIdx = 0;
    $('#hmArticlesPager div.hm-pagerpage').each(function (idx,el) {
        if ($(el).is('.hm-pagerpage-active')) {
            nextDisplayIdx = idx + 1;
        }
    });
    if ($('#hmArticles div.hm-article:eq(' + nextDisplayIdx + ')').length == 0) {
        nextDisplayIdx = 0;
    }
    ArticleScrollDisplay(nextDisplayIdx);
    ArticleScrollTimer = window.setTimeout(function () {
        ArticleScroll();
    },ArticleScrollTimerTime);
}

function ArticleScrollDisplay(idxDisplay) {
    //vsetky zrusime a jedno zobrazime
    $('#hmArticles div.hm-article').each(function (idx, el) {
        var jel = $(el);
        if (idx == idxDisplay) {
            jel.css('z-index',10);
            jel.show();
            $('#hmArticlesPager div.hm-pagerpage:eq('+idx+')').addClass('hm-pagerpage-active');
        } else {
            jel.css('z-index',1);
            jel.hide();
            $('#hmArticlesPager div.hm-pagerpage:eq('+idx+')').removeClass('hm-pagerpage-active');
        }
    });
}