function listenForEvents(siteId) {
  TCPSocket = Orbited.TCPSocket;

  stomp = new STOMPClient();
  stomp.onopen = function() {
    stomp.subscribe('', {
      exchange: 'amq.topic',
      id: Math.floor(Math.random()*11) + new Date().getTime(),
      routing_key: 'site-' + siteId + '.events.*'
    });
  };
  stomp.onclose = function(code) {
  };
  stomp.onerror = function(error) {
  };
  stomp.onerrorframe = function(frame) {
  };
  stomp.onconnectedframe = function() {
  };
  stomp.onmessageframe = function(frame) {
    displayNotification(Audiencc.parseJSON(frame.body));
  };
  stomp.connect(window.orbited_host, 61613, 'guest', 'guest');
}

var liveUpdateTimeout;
function displayNotification(json) {
  if (liveUpdateTimeout) {
    clearTimeout(liveUpdateTimeout);
  }
  var dialog = $('#live-update-dialog');
  $(dialog).hide();    
  // fill in details
  $('#live-update-dialog-body', dialog).html(json['friendly_body']);
  // Show it.
  $(dialog).show();
  liveUpdateTimeout = setTimeout("hideNotification()",3000);
}
function hideNotification() {
  $('#live-update').hide();
  liveUpdateTimeout = null;  
}
$(function() {
  $('#live-update-close-btn').click(function() {
    $('#live-update').hide();
  });
});