function voteSection(sectionId) {
    $.get('/catalog/voteSection/?sectionId=' + sectionId, function() {
        var votedCount = $('#section' + sectionId + 'Widget .user-count span').html();
        $('#section' + sectionId + 'Widget .button a.poidu').hide();
        $('#section' + sectionId + 'Widget .button a.nepoidu').show();

        if (!votedCount) {
            $('#section' + sectionId + 'Widget .user-count span').html(0);
            $('#section' + sectionId + 'Widget .user-count').removeClass('no-user');
        }
        $('#section' + sectionId + 'Widget .user-count b').html('+ Я иду');
    });
}

function unvoteSection(sectionId) {
    $.get('/catalog/unvoteSection/?sectionId=' + sectionId, function() {
        var votedCount = $('#section' + sectionId + 'Widget .user-count span').html();
        $('#section' + sectionId + 'Widget .button a.nepoidu').hide();
        $('#section' + sectionId + 'Widget .button a.poidu').show();

        if (votedCount == 0) {
            $('#section' + sectionId + 'Widget .user-count span').html('');
            $('#section' + sectionId + 'Widget .user-count').addClass('no-user');
            $('#section' + sectionId + 'Widget .user-count b').html('Будешь первым?');
        } else {
            $('#section' + sectionId + 'Widget .user-count b').html('слушателей идёт');
        }
    });
}

$(document).ready(function() {
    $('span:has(.info-user)').mouseenter(function() {
        $(this).children('.info-user').stop(true, true).fadeIn(500);
    }).mouseleave(function() {
        $(this).children('.info-user').stop(true, true).fadeOut(500);
    });
    $('img').mouseenter(function() {
        $(this).next().children('.info-user').stop(true, true).fadeIn(500);
    }).mouseleave(function() {
        $(this).next().children('.info-user').stop(true, true).fadeOut(500);
    });
    $('.spic-video').dialog({
      autoOpen: false,
      height: 449,
      width: 724,
      modal: true,
      resizable: false
    });

    // счеткик скачивания презентаций
    $('.present a').click(function(){
        var idPresent = this.id;
        var id = idPresent.substring(8, idPresent.length);
        $.ajax({url: '/catalog/downloadFileCounter/'+id+'/',
                async: false
        });
    });
});

