(function() {
  var checkboxIsChecked, isValidEmail, lengthIsGreaterThan, moduleSpacing, name, padding, paras, validateForm;
  var __indexOf = Array.prototype.indexOf || function(item) {
    for (var i = 0, l = this.length; i < l; i++) {
      if (this[i] === item) return i;
    }
    return -1;
  };
  moduleSpacing = {
    article: '40px',
    aside: '20px'
  };
  for (name in moduleSpacing) {
    padding = moduleSpacing[name];
    paras = $("#main " + name + " .content p");
    $(paras[paras.length - 1]).css('padding-bottom', padding);
  }
  if ($('#home')) {
    $('#slideshow img:gt(0)').hide();
    setInterval(function() {
      return $('#slideshow :first-child').fadeOut().next('img').fadeIn().end().appendTo('#slideshow');
    }, 4000);
  }
  if ($('body#contact').length) {
    $('body#contact .required input').keyup(function(e) {
      if (validateForm($(this).closest('form'))) {
        return $('input[type=submit]').removeAttr('disabled');
      } else {
        return $('input[type=submit]').attr('disabled', 'disabled');
      }
    });
    $('body#contact textarea').keyup(function(e) {
      if (validateForm($(this).closest('form'))) {
        return $('input[type=submit]').removeAttr('disabled');
      } else {
        return $('input[type=submit]').attr('disabled', 'disabled');
      }
    });
  }
  if ($('body#signup').length) {
    $('body#signup .required input').keyup(function(e) {
      if (validateForm($(this).closest('form'))) {
        return $('input[type=submit]').removeAttr('disabled');
      } else {
        return $('input[type=submit]').attr('disabled', 'disabled');
      }
    });
    $('body#signup input[type=checkbox]').click(function(e) {
      if (validateForm($(this).closest('form'))) {
        return $('input[type=submit]').removeAttr('disabled');
      } else {
        return $('input[type=submit]').attr('disabled', 'disabled');
      }
    });
  }
  if ($('body#player-edit').length) {
    $('body#player-edit .required input').keyup(function(e) {
      if (validateForm($(this).closest('form'))) {
        return $('input[type=submit]').removeAttr('disabled');
      } else {
        return $('input[type=submit]').attr('disabled', 'disabled');
      }
    });
    $('body#player-edit form').change(function(e) {
      if (validateForm($(this).closest('form'))) {
        return $('input[type=submit]').removeAttr('disabled');
      } else {
        return $('input[type=submit]').attr('disabled', 'disabled');
      }
    });
  }
  lengthIsGreaterThan = function(str, min_length) {
    if (str) {
      return str.length > min_length;
    } else {
      return false;
    }
  };
  isValidEmail = function(email) {
    var re;
    re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
  };
  checkboxIsChecked = function(checkbox) {
    return $(checkbox).is(':checked');
  };
  validateForm = function(form) {
    var required, validations, _i, _len, _ref;
    validations = [];
    _ref = $(form).find('.required');
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      required = _ref[_i];
      if ($(required).find('input[type=email]').length) {
        validations.push(isValidEmail($(required).find('input[type=email]').first().val()));
      } else if ($(required).find('input[name=email]').length) {
        validations.push(isValidEmail($(required).find('input[name=email]').first().val()));
      } else if ($(required).find('input[type=password]').length) {
        validations.push(lengthIsGreaterThan($(required).find('input[type=password]').first().val(), 0));
      } else if ($(required).find('input[type=text]').length) {
        validations.push(lengthIsGreaterThan($(required).find('input[type=text]').first().val(), 0));
      } else if ($(required).find('textarea').length) {
        validations.push(lengthIsGreaterThan($(required).find('textarea').first().val(), 9));
      } else if ($(required).find('input[type=checkbox]').length) {
        validations.push(checkboxIsChecked($(required).find('input[type=checkbox]')));
      }
    }
    return __indexOf.call(validations, false) < 0;
  };
  if ($('body#single-game').length) {
    $('body#single-game .comment-form textarea').focus(function(e) {
      $(this).animate({
        'height': '3em'
      });
      return $(this).parent().find('input[type=submit]').fadeIn('slow');
    });
    $('body#single-game .comment-form textarea').blur(function(e) {
      if ($(this).val().length === 0) {
        $(this).parent().find('input[type=submit]').fadeOut('fast');
        return $(this).animate({
          'height': '1.25em'
        });
      }
    });
    $('body#single-game .comment-form textarea').keyup(function(e) {
      var form;
      form = $(this).closest('form');
      if (validateForm(form)) {
        return $(form).find('input[type=submit]').removeAttr('disabled');
      } else {
        return $(form).find('input[type=submit]').attr('disabled', 'disabled');
      }
    });
  }
  if ($('body#login').length) {
    $('body#login input').keyup(function(e) {
      var form;
      form = $(this).closest('form');
      if (validateForm(form)) {
        return $(form).find('input[type=submit]').removeAttr('disabled');
      } else {
        return $(form).find('input[type=submit]').attr('disabled', 'disabled');
      }
    });
  }
  if ($('body#forgot-username').length) {
    $('body#forgot-username input').keyup(function(e) {
      var form;
      form = $(this).closest('form');
      if (validateForm(form)) {
        return $(form).find('input[type=submit]').removeAttr('disabled');
      } else {
        return $(form).find('input[type=submit]').attr('disabled', 'disabled');
      }
    });
  }
  $('form').submit(function() {
    return $(this).find('input[type=submit]').attr('disabled', 'disabled');
  });
  $('form#locale_switcher a').click(function() {
    $('form#locale_switcher #locale').val($(this).attr('data'));
    return $('form#locale_switcher').submit();
  });
}).call(this);

