(function(context,$) {

  "use strict";

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

  context.JK.SignupHelper = function(app) {

    if(!app) throw "no app defined";

    var logger = context.JK.logger;
    var rest = context.JK.Rest();
    var $self = $(this);
    var $parent = null;
    var $signupCancel = null;
    var $showSigninDialog = null;
    var EVENTS = context.JK.EVENTS;

    function events() {
      $signupCancel.click(function(e) {
        app.layout.closeDialog('signup-dialog');
        e.stopPropagation();
        return false;
      });

      $showSigninDialog.click(function(e) {
        $self.triggerHandler(EVENTS.SHOW_SIGNIN);
        return false;
      })
    }

    function initialize(_$parent){
      $parent = _$parent;

      $showSigninDialog = $parent.find('.show-signin-dialog')
      $signupCancel  = $parent.find('.signup-cancel')

      if($showSigninDialog.length == 0) throw "no $showSigninDialog found";
      if($signupCancel.length == 0) throw "no $signupCancel form found";
      events();
    }
    
    this.initialize = initialize;
    
    return this;
  }
})(window, jQuery);