
var lbRealtime = function(opts)
{
    var self  = this;
    var opts_ = opts;

    this.intervalNotifications = 10000;
    this.intervalMessages      = 10000;

    this.init = function()
    {
        interval_n = this.intervalNotifications;
        interval_m = this.intervalMessages;

        setTimeout(function() { self.checkNotifications(); }, interval_n);
        setTimeout(function() { self.checkMessages(); }, interval_m);
    }

    this.checkNotifications = function()
    {
        interval_n = this.intervalNotifications;

        $.ajax({
            url: "/profile/unreadNotificationsCount",
            type: "get",
            success:function(d)
            {
                var i = parseInt(d);
                if (i == -1)
                    return false;

                $(".notifications-count").html("" + i);
                setTimeout(function() { self.checkNotifications(); }, interval_n);
            }
        });
    }

    this.checkMessages = function()
    {
        interval_m = this.intervalMessages;

        $.ajax({
            url: "/profile/unreadMessagesCount",
            type: "get",
            success:function(d)
            {
                var i = parseInt(d);
                if (i == -1)
                    return false;

                $(".messages-count").html("" + i);
                setTimeout(function() { self.checkMessages(); }, interval_m);
            }
        });
    }
/**
 *
    this.init = function()
    {

        if (typeof EventSource == "undefined")
            return false;

        var eventSource = new EventSource("sse.php");

        eventSource.addEventListener('recvnotification', function(e)
        {
            e = e || event, msg = '';
            console.log('recvnotification: ', e.data);

            var response = JSON.parse(e.data);
            if (! response.id) {
              console.log("Error occured parsing Response: ", e.data);
              return false;
            }

        }, false);

        eventSource.addEventListener('recvmessage', function(e)
        {
            e = e || event, msg = '';
            console.log('recvmessage: ', e.data);

            var response = JSON.parse(e.data);
            if (! response.id) {
              console.log("Error occured parsing Response: ", e.data);
              return false;
            }

        }, false);

        eventSource.addEventListener('ping', function(e)
        {
            e = e || event, msg = '';
            //console.log('ping: ', e.data);
        }, false);

        eventSource.addEventListener('error', function(e)
        {
            e = e || event, msg = '';

            switch( e.target.readyState ){
            case EventSource.CONNECTING:
                break;

            // if error was fatal
            case EventSource.CLOSED:
                console.log("Connection closed.");
                break;
            }

        }, false);
    }
 *
 **/
};



