(function() {
  var Gallery;
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  Gallery = (function() {
    function Gallery(options) {
      var _ref, _ref2, _ref3, _ref4;
      this.options = options;
      this.moveRight = __bind(this.moveRight, this);
      this.moveLeft = __bind(this.moveLeft, this);
      this.root = this.options.root ? this.options.root : void 0;
      if (!((_ref = this.root) != null ? _ref.jquery : void 0)) {
        return;
      }
      this.wrapper = this.root.find('.wrapper');
      if (!(((_ref2 = this.wrapper) != null ? _ref2.jquery : void 0) && this.wrapper.size())) {
        return;
      }
      this.list = this.root.find('ul');
      if (!(((_ref3 = this.list) != null ? _ref3.jquery : void 0) && this.list.size())) {
        return;
      }
      this.items = this.root.find('li');
      if (!(((_ref4 = this.items) != null ? _ref4.jquery : void 0) && this.items.size())) {
        return;
      }
      this.left = options.left ? $(options.left) : void 0;
      this.right = options.right ? $(options.right) : void 0;
      if (!(this.left && this.right)) {
        return;
      }
      this.left.click(this.moveLeft);
      this.right.click(this.moveRight);
      this.current = 0;
      this.groups = Math.ceil(this.items.size() / 3);
      this.animating = false;
      this.items.slice(3).hide();
      this.itemWidth = this.items.first().outerWidth(true);
      this.resize();
      this.updateControls();
    }
    Gallery.prototype.resize = function() {
      var items, listWidth, wrapperWidth;
      this.options.items = items = this.options.items ? this.options.items : 3;
      wrapperWidth = this.itemWidth * items;
      listWidth = this.itemWidth * this.items.size();
      this.wrapper.css({
        width: wrapperWidth,
        marginLeft: (this.root.width() - wrapperWidth) / 2
      });
      return this.list.css({
        width: listWidth
      });
    };
    Gallery.prototype.updateControls = function() {
      if (this.current === 0) {
        this.left.fadeOut('fast');
        this.canMoveLeft = false;
      } else {
        this.left.fadeIn('fast');
        this.canMoveLeft = true;
      }
      if (this.current === this.groups - 1) {
        this.right.fadeOut('fast');
        return this.canMoveRight = false;
      } else {
        this.right.fadeIn('fast');
        return this.canMoveRight = true;
      }
    };
    Gallery.prototype.moveLeft = function(e) {
      e.preventDefault();
      if (!(this.canMoveLeft && !this.animating)) {
        return;
      }
      this.animating = true;
      this.current--;
      this.updateControls();
      return this.list.fadeOut('fast', __bind(function() {
        var slice, slicePos;
        slicePos = this.current * 3;
        slice = this.items.slice(slicePos, slicePos + 3);
        this.items.hide();
        slice.show();
        return this.list.fadeIn('fast', __bind(function() {
          return this.animating = false;
        }, this));
      }, this));
    };
    Gallery.prototype.moveRight = function(e) {
      e.preventDefault();
      if (!(this.canMoveRight && !this.animating)) {
        return;
      }
      this.animating = true;
      this.current++;
      this.updateControls();
      return this.list.fadeOut('fast', __bind(function() {
        var slice, slicePos;
        slicePos = this.current * 3;
        slice = this.items.slice(slicePos, slicePos + 3);
        this.items.hide();
        slice.show();
        return this.list.fadeIn('fast', __bind(function() {
          return this.animating = false;
        }, this));
      }, this));
    };
    return Gallery;
  })();
  $.fn.gallery = function(options) {
    if (options == null) {
      options = {};
    }
    options.root = $(this);
    return $(this).data('gallery', new Gallery(options));
  };
  $.extend($.easing, {
    easeInOutQuad: function(x, t, b, c, d) {
      if ((t /= d / 2) < 1) {
        return c / 2 * t * t + b;
      }
      return -c / 2 * ((--t) * (t - 2) - 1) + b;
    }
  });
  this.cadastrar = function(e) {
    var email, nascimento, nome;
    e.preventDefault();
    nome = $('#nome').val();
    email = $('#email').val();
    nascimento = $('#nascimento').val();
    return $.ajax({
      url: window.location.toString(),
      data: {
        nome: nome,
        email: email,
        nascimento: nascimento
      },
      dataType: 'json',
      type: 'POST',
      beforeSend: function() {
        return $('#form').block();
      },
      complete: function() {
        return $('#form').unblock();
      },
      error: function() {
        return humane.error('Houve um erro ao salvar suas informações. Por favor, tente mais tarde.');
      },
      success: function(response) {
        if (response.error) {
          humane.error(response.error);
        }
        if (response.result) {
          nome = $('#nome').val('');
          email = $('#email').val('');
          nascimento = $('#nascimento').val('');
          return humane.success(response.result);
        }
      }
    });
  };
  $(function() {
    $('#gallery').gallery({
      left: '.control-left',
      right: '.control-right'
    });
    humane.timeout = 5000;
    humane.waitForMove = true;
    humane.clickToClose = true;
    $.blockUI.defaults.css.color = '#E2007A';
    $.blockUI.defaults.css.border = null;
    $.blockUI.defaults.css.backgroundColor = null;
    return $.blockUI.defaults.message = '<img src="' + BASE_URL + '/image/loader.gif" alt="Aguarde..." title="Aguarde..." width="16" height="11" />';
  });
}).call(this);

