(function($) {

  /**
   * Small helper that highlights an element so that it
   * blinks two (or more) times.
   */
  $.fn.highlight = function(max, duration, callback) {
    var
      i = 0, self = this, max = (!max || max <= 0) ? 2 : max,
      duration = (!duration) ? 300 : duration;
    (function fade() {
      self.animate({opacity: 0.3}, 300, function() {
        self.animate({opacity: 1.0}, 300, function() {
          (++i < max) ? fade() : (callback && callback());
        })})})()};

  /**
   * Like highlight but hides the element after flashing.
   * The default highlight count is one.  The actual hiding
   * happens after the timeout which defaults to 5000.
   */
  $.fn.highlightAndHide = function(max, duration, fadeDuration, timeout) {
    var self = this;
    this.highlight(max || 1, duration, function() {
      window.setTimeout(function() {
        self.animate({
          opacity:  'hide',
          height:   'hide'
        }, fadeDuration || 'slow')}, timeout || 5000)});
  };

  /**
   * Nifty helper function to shuffle an array or array like object.
   */
  $.shuffeArray = function(arr) {
    var tmp, rand;
    for (var i = 0, n = arr.length; i < n; ++i) {
      rand = Math.floor(Math.random() * arr.length);
      tmp = arr[i]; 
      arr[i] = arr[rand]; 
      arr[rand] = tmp;
    }
    return arr;
  };

})(jQuery);
