$(document).ready(function() {
   if($("li.notification-menu-item").length != 0) {
        fetchNewNotificationCount();
        setUpInterValCounterForAnimation();
        setInterval('fetchNewNotificationCount()', 20000);
   }
});

function setUpInterValCounterForAnimation()
{
    setInterval("animateUnreadCount()", 800);
}

function animateUnreadCount()
{

    var object = $(".total-amount-unread-messages");

    if(object.text() != '0') {
        if(object.css('color') == 'rgb(255, 255, 255)') {
            object.animate({color: "#707171"});
        }else   {
            object.animate({color: "white"});
        }
    }else   {
        object.css('color', '#707171');
    }
}

function updateUnreadNotifications(amount)
{

    $(".total-amount-unread-messages").text(amount);

}

function fetchNewNotificationCount()
{
    
    $.ajax({
        url      : 'fileadmin/template/ajax/updatesping.php',
        type     : 'POST',
        dataType : 'json',
        success  : function(json) {

            if(json.result == 'success') {
                updateUnreadNotifications(json.new_updates);
            }

        }
    });

}



