(function (context, $) {

  "use strict";

  context.JK = context.JK || {};

  context.JK.ShutdownDialog = function (app) {
    var logger = context.JK.logger;

    function show() {
      context.JK.Banner.showAlert(
        { title: "Close JamKazam Application",
          buttons: [
            {name: 'CANCEL', click: function() {
              logger.debug("'CANCEL SHUTDOWN' selected")
              context.JK.Banner.hide();
            }},
            {name: 'SHUT DOWN', click: function() {
              logger.debug("'COMPLETELY SHUT DOWN THE APP' selected")
              context.jamClient.ShutdownApplication()
            }},

          ],
          html: $('#template-shutdown-prompt').html()});
    }

    function initialize() {
      // guard against old clients
      if(context.jamClient.RegisterQuitCallback) {
        context.jamClient.RegisterQuitCallback("window.JK.ShutdownDialogCallback");
      }
    }

    function quitCallback(options) {
      logger.debug("shutdown event");
      show();
    }

    this.initialize = initialize;

    context.JK.ShutdownDialogCallback = quitCallback;

    return this;

  }
})(window, jQuery);