/*!
 * bgMover 0.5.0
 * Examples and documentation at: 
 * http://www.app-agentur-bw.de/showcase/bgmover
 * 2011 AREA-NET GmbH (www.app-agentur-bw.de | www.area-net.de)
 * Version: 0.5.0 (17-MARCH-2011)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Requires:
 * jQuery v1.3.2 or later
 * 
 */

(function($){
    $.fn.bgMover = function(options) {
    
        var _class  = this;
                
        var settings = {
          'delay'  : 10,
          'width'  : 100,
          'top'    : 0
        }

        return this.each(function(){        
          var delay     = 0; 
          var currentX  = -1;
          
          
          var _this = $(this);
          if(options) { 
            $.extend(settings, options);
          }
          
          var positionX = -Math.round((settings.width - _this.width())/2); 
          
          _this.css('background-position', positionX + 'px ' + settings.top + 'px');
          
          _this.mousemove(function(event){
              if(currentX == -1) currentX = event.pageX;
              delay =  currentX - event.pageX;
              if(Math.abs(delay) >= settings.delay ){
                  if(delay > 0){
                    positionX--;    
                  }else{
                    positionX++;      
                  }
                  currentX = event.pageX;
                  _this.css('background-position', positionX + 'px ' + settings.top + 'px');
              }         
          });
          
        });
    }    
})(jQuery);
