var LoginLightbox = {

disableForms:
  function() {
    Form.disable($('lightbox_login_form'));
    Form.disable($('lightbox_signup_form'));
  },

enableForms:
  function() {
    Form.enable($('lightbox_login_form'));
    Form.enable($('lightbox_signup_form'));
  },

loadingSignup: 
  function() {
    Element.appear($('lightbox_signup_spinner'));
    $$('.lightbox_error_field').each(function(e) { e.hide(); });
    LoginLightbox.disableForms();
  },

loadingLogin: 
  function() {
    Element.appear($('lightbox_login_spinner'));
    $$('.lightbox_error_field').each(function(e) { e.hide(); });
    LoginLightbox.disableForms();
  },

complete:
  function() {
    LoginLightbox.initRecaptcha();
    $('lightbox_login_spinner').hide();
    $('lightbox_signup_spinner').hide();
    $('lightbox_bad_login').hide();
    LoginLightbox.enableForms();
  },

updateSignup: 
  function(response) {
    try{
      LoginLightbox.complete();

      if(response.success) {
        window.location = window.location.pathname; 
        return;
      } // success

      if(!response.success) { 
        for(var i = 0; i < response.errors.user.length; i++) {
          var error = response.errors.user[i];
          var errorNode = $('error_user_' + error[0]);
          if(errorNode) { 
            errorNode.innerHTML = error[1]; 
            Element.appear(errorNode);
          }
        } // for

        for(var i = 0; i < response.errors.account.length; i++) {
          var error = response.errors.account[i];
          var errorNode = $('error_account_' + error[0]);
          if(errorNode) { 
            errorNode.innerHTML = error[1];
            Element.appear(errorNode);
          }
        } // for

        if(!response.errors.recaptcha.valid) {
          $('error_account_recaptcha').innerHTML = "Recaptcha failed, please try again.";
          Element.appear($('error_account_recaptcha'));
        } // if 
      } // if
    } catch(e) { console.log("%o", e); }
  }, // update

updateLogin: 
  function(response) {
    try{
      LoginLightbox.complete();

      if(response.success) {
        window.location = window.location.pathname; 
        return;
      } // success

      if(!response.success) {
        Element.appear($('lightbox_bad_login'));
      } // not success
    } catch(e) { console.log("%o", e); }
  }, //updateLogin

initRecaptcha: 
  function() {
    Recaptcha.create('6LfIFQEAAAAAAICLFtcbWmkjY5zgI5jaXBs114JT', 
        'lightbox-account-recaptcha', { theme: "white" });
  } // initRecaptcha
}; // LoginLightbox
