var globalPollingClient = null;

var viewUri = '/activityViewer/index.html';
var pollInterval = 30;
globalPollingClient = new PollingClient( viewUri, 'message', pollInterval );
//globalPollingClient.onUpdateDoNotify( '<a href="' + viewUri + '">You Have New Activity Messages</a>.' );
globalPollingClient.resume();
globalPollingClient.start();

// register AV event message consumer
$( function() {
  var notifyWidget;

  IM.registerMQConsumer( {
    queueName: "activityViewerEvents",
    onMessage: function( message ) {

      if( ! ( notifyWidget instanceof jQuery ) || parseInt(notifyWidget.length) < 1 )
      {
        notifyWidget = $( '#meerkat' );
      }

      if( notifyWidget.length === 1 )
      {

        //  exit early if global polling client exists and is paused
        if (typeof window.globalPollingClient !== "undefined" && window.globalPollingClient !== null) {
          if (!window.globalPollingClient.isActive()) {
            return;
          }
        }

        //  exit early if polling client exists and is paused
        if (typeof window.pollingClient !== "undefined" && window.pollingClient !== null) {
          if (!window.pollingClient.isActive()) {
            return;
          }
        }

        $( '.meerkatContent', notifyWidget ).html( '<a href="' + viewUri + '">You Have New Activity Messages</a>.' );

        meerkat( meerkat.ActivityNotifyOptions );

        setTimeout( function ()
        {
          $( '.meerkatClose', notifyWidget ).click();
        }, 5000 );
      
       $('#dockedActivityMsg').addClass('docked').html('You Have New Activity');
       
      }
    }
  } );
} );

