     @refreshGfx()
     @.$('form').addClass('auth-form-login')
     false
-  
+
   toggleComplete: ->
     @state = 'complete'
     @logoutOnHide = true
     @refreshGfx()
     @.$('form').addClass('auth-form-complete')
     false
-  
-  
+
+
   cancelDialog: () ->
     @hide() if $.inArray(@state, ["complete","password_change","name_change"]) >= 0
-  
+
   logoutUser: ->
     window.location.replace('/logout')
-    
+
   hide: (args) =>
     args = {} unless args
-    
+
     @logoutOnHide = args.logout if args.logout != undefined
     @callbackOnHide = args.callback if args.callback != undefined
 
     @.$('.modal').modal('hide')
     false
-  
+
   clearLastState: ->
     @.$('form').removeClass('auth-form-login').removeClass('auth-form-register').removeClass('auth-form-restore')
     false
-    
+
   submitFormFromState: (e) ->
     switch @state
       when "restore"          then @submitRestore()
       when "register"         then @submitRegister()
       when "login"            then @submitLogin()
       when "complete"         then @submitComplete()
-    
+
     e.preventDefault()
     false
-  
+
   buildErrors: (errors) ->
     t = "<ul style='text-align: left;'>"
     $.each errors, (index,error) ->
       t += "<li><strong>#{error.ref_node}</strong> #{error.message}</li>" if error.type == "field"
     t += "</ul>"
-  
+
   submitRestore: ->
-    
+
     submitData = {}
     submitData.email = @.$('#session_email').val()
-    
+
     $.ajax
       type: 'POST'
       url: "/v1/users/restore.json"

    submitData.user.email = @.$('#session_email').val()
    submitData.user.password = @.$('#session_password').val()
    submitData.user.confirm_registration = true
    
    $.ajax
      type: 'PUT'
      url: "/v1/users/#{session.get('user').id}.json"

        @callback(@callbackArgs) if @callback && @callbackOnHide
        $(@el).remove()
      , 500

  refreshGfx: ->
    @clearLastState()
    if @state == 'restore'
      @.$("button.auth-submit").text("Restore")
      @.$("a.auth-dialog-help-one").text("Register an account").data('auth-dialog-state','register')
      @.$("a.auth-dialog-help-two").text("Use an existing account").data('auth-dialog-state','login')

    else if @state == 'register'
      @.$("button.auth-submit").text("Continue")
      @.$("a.auth-dialog-help-one").text("Forgot password?").data('auth-dialog-state','restore')
      @.$("a.auth-dialog-help-two").text("Use an existing account").data('auth-dialog-state','login')

    else if @state == 'complete'
      @.$("button.auth-submit").text("Complete Registration")
      @.$("a.auth-dialog-cancel").text("Cancel")

    else
      @.$("button.auth-submit").text("Login")
      @.$("a.auth-dialog-help-one").text("Forgot password?").data('auth-dialog-state','restore')
      @.$("a.auth-dialog-help-two").text("Register an account").data('auth-dialog-state','register')


  triggerAction: (e) ->
    action = @.$(e.target).data('auth-dialog-state')
    @toggleStateFromAction(action)

  toggleStateFromAction: (action) ->

    switch action
      when "restore"          then @toggleRestore()
      when "register"         then @toggleRegister()
      when "login"            then @toggleLogin()
      when "complete"         then @toggleComplete()

    false


  toggleRestore: ->
    @state = 'restore'
    @logoutOnHide = false
