(function(){
  var _a, getWordFormIndex, root;
  root = window || {};
  root.fb = root.fb || {};
  jQuery.extend(String.prototype, {
    trim: function() {
      return this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, "");
    },
    startsWith: function(str) {
      return this.match("^" + str) === str;
    },
    endsWith: function(str) {
      return this.match(str + "$") === str;
    },
    contains: function(substring) {
      return this.indexOf(substring) !== -1;
    }
  });
  jQuery.extend(Array.prototype, {
    clone: function() {
      return this.slice(0, this.length);
    },
    contains: function(element) {
      return this.indexOf(element) !== -1;
    }
  });
  !((typeof (_a = Array.indexOf) !== "undefined" && _a !== null)) ? (Array.prototype.indexOf = function(target) {
    var _b, _c, index, item;
    _b = this;
    for (index = 0, _c = _b.length; index < _c; index++) {
      item = _b[index];
      if (item === target) {
        return index;
      }
    }
    return -1;
  }) : null;
  fb.debounce = function(delay, atBegin, callback) {
    if (callback === undefined) {
      return fb.throttle(delay, atBegin, false);
    } else {
      return fb.throttle(delay, callback, atBegin !== false);
    }
  };
  fb.throttle = function(delay, no_trailing, callback, debounce_mode) {
    var last_exec, timeout_id, wrapper;
    timeout_id = undefined;
    last_exec = 0;
    if (typeof no_trailing !== 'boolean') {
      debounce_mode = callback;
      callback = no_trailing;
      no_trailing = undefined;
    }
    wrapper = function() {
      var args, clear, elapsed, exec, that;
      that = this;
      elapsed = +new Date() - last_exec;
      args = arguments;
      exec = function() {
        last_exec = +new Date();
        return callback.apply(that, args);
      };
      clear = function() {
        timeout_id = undefined;
        return timeout_id;
      };
      debounce_mode && !timeout_id ? exec() : null;
      timeout_id && clearTimeout(timeout_id);
      if (debounce_mode === undefined && elapsed > delay) {
        return exec();
      } else if (no_trailing !== true) {
        timeout_id = setTimeout((debounce_mode ? clear : exec), (debounce_mode === undefined ? delay - elapsed : delay));
        return timeout_id;
      }
    };
    $.guid ? (wrapper.guid = (callback.guid = callback.guid || $.guid++)) : null;
    return wrapper;
  };
  jQuery.fn.toggleChecked = function(value) {
    value ? this.attr('checked', 'checked') : this.removeAttr('checked');
    return this;
  };
  jQuery.fn.toggleVisibility = function(value, speed) {
    value ? this.show(speed) : this.hide(speed);
    return this;
  };
  jQuery.fn.flushBackground = function(animateToColor) {
    var fields;
    animateToColor = '#f34e2d';
    fields = this;
    return fields.animate({
      backgroundColor: animateToColor
    }, function() {
      return fields.animate({
        backgroundColor: '#ffffff'
      });
    });
  };
  root.XOR = function(a, b) {
    return (a || b) && !(a && b);
  };
  getWordFormIndex = function(value) {
    var _b;
    value = value < 0 ? value * -1 : value;
    if ((11 <= value) && (value <= 14)) {
      return 0;
    }
    if ((_b = (value % 10)) === 0) {
      return 0;
    } else if (_b === 1) {
      return 1;
    } else {
      return value % 10 >= 2 && value % 10 <= 4 ? 2 : 0;
    }
  };
  fb.pluralize = function(value, forms) {
    var wordFormIndex;
    wordFormIndex = getWordFormIndex(value);
    return forms[wordFormIndex].replace('{0}', value);
  };
  jQuery.fn.dropDown = function() {
    return this.each(function() {
      var toggleContent, toggleHandle;
      toggleHandle = $(this).find('.handle');
      toggleContent = $(this).find('.content');
      if ((typeof toggleHandle !== "undefined" && toggleHandle !== null) && toggleHandle.length > 0 && (typeof toggleContent !== "undefined" && toggleContent !== null) && toggleContent.length > 0) {
        toggleContent.toggleVisibility(toggleHandle.hasClass('open'));
        return toggleHandle.click(function(event) {
          toggleHandle.toggleClass('open');
          toggleContent.slideToggle('fast');
          event.preventDefault();
          return false;
        });
      }
    });
  };
})();
