/**
 * jquery.shake.js
 * Copyright 2011 Parse3
 * Questions, Comments:
 * Timothy Leverett
 * tleverett@parse3.com
 */
(function($){
  $.fn.shake = function (options)
  {
    var settings;
    
    function shakeEach( index, element )
    {
      var $this, initPos, a, b, c, d;
      
      $this = $(this);
      a = {};
      b = {};
      c = {};
      d = Math.abs( settings.dif );
      
      initPos = $this.css('position');
      
      $this.css('position','relative');
      
      switch ( settings.dir.toLowerCase() )
      {
        case 'vertical':
          a.top = c.top = '+=' + d + 'px';
          b.top = '-=' + (2*d) + 'px';
          break;
        case 'horizontal':
        default:
          a.left = c.left = '+=' + d + 'px';
          b.left = '-=' + (2*d) + 'px';
          break;
      }
      
      $this.animate(a, settings.duration).animate(b, settings.duration).animate(c, settings.duration);
    }
    
    settings = {
      'dif':5,
      'dir':'horizontal',
      'duration':50
    };
    $.extend( settings, options );
    
    $(this).each( shakeEach );
  };
})(jQuery);
