(function(context,$) {
  "use strict";

  context.JK = context.JK || {};
  context.JK.TwitterHelper = function(app) {
    var logger = context.JK.logger;
    var twitterReadyDeferred = null;
    var $self = $(this);
    var connected = false;

    function ready() {
      return twitterReadyDeferred;
    }

    function initialize(_twitterPublicAccountName) {
      twitterReadyDeferred = $.Deferred();

      context.twttr = (function (d,s,id) {
        var t, js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
        js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
        return context.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
      }(document, "script", "twitter-wjs"));

      context.twttr.ready(function (twttr) {
        // bind events here
        twitterReadyDeferred.resolve();
      });

      ready()
        .done(function() {
          context.twttr.events.bind('follow', function (event) {
            var followedUserId = event.data.user_id;
            var followedScreenName = event.data.screen_name;
            JK.GA.trackJKSocial(JK.GA.Categories.jkFollow, JK.GA.JKSocialTargets.twitter, JK.clientType());
          });
        })

      return this;
    }

    this.initialize = initialize;
    this.ready = ready;
  };
})(window, jQuery);