/* Counts all unread messages every 5 seconds to update the count bubble */
var value = 0;
pollModeratorMessage()
setInterval(pollModeratorMessage, 5000);

function pollModeratorMessage()
{
    $.getJSON("count.php", function(data)
    {

        var adminCount = parseInt(data.adminCount);
        var inboxCount = parseInt(data.inboxCount);
        var totalCount = adminCount + inboxCount;

        /* Handle adminBubble */
        if (adminCount > 0)
        {
            document.getElementById('adminCount').innerHTML = adminCount;
            document.getElementById('adminCountBubble').style.display = 'table';
        }
        else if(document.getElementById('adminCountBubble'))
        {
            document.getElementById('adminCountBubble').style.display = 'none';
        }

        /* Handle inboxBubble */
        if (inboxCount > 0)
        {
            document.getElementById('inboxCount').innerHTML = inboxCount;
            document.getElementById('inboxCountBubble').style.display = 'table';
        }
        else
        {
            document.getElementById('inboxCountBubble').style.display = 'none';
        }

        /* Handle inboxBubble */
        if (totalCount > 0)
        {
            document.getElementById('totalCount').innerHTML = totalCount;
            document.getElementById('totalCountBubble').style.display = 'table';
        }
        else
        {
            document.getElementById('totalCountBubble').style.display = 'none';
        }
    });
}
