(function($) {
    $.fn.animatedBackground = function(options) {

    // build main options before element iteration by extending the default ones
    var opts = $.extend({}, $.fn.animatedBackground.defaults, options);

	function startAnimation() {
		$.fn.animatedBackground.startAnimation($(this), opts);
	}
	
	function stopAnimation() {
		$.fn.animatedBackground.stopAnimation($(this), opts);
	}

    // for each side note, do the magic.
    return $(this)
        .css( {backgroundPosition: opts.backgroundPositionInit} )
        .mouseover(startAnimation)
        .mouseout(stopAnimation)
        .focus(startAnimation)
        .blur(stopAnimation)
    };

    // plugin defaults
    $.fn.animatedBackground.defaults = {
		backgroundPositionInit : "0 0",
		backgroundPositionStart : "(0 0)",
		backgroundPositionEnd : "(0 0)",
		durationStart : 500,
		durationEnd : 500,
		complete : null
    };

	$.fn.animatedBackground.startAnimation = function($el, opts) {
		$el.stop().animate({backgroundPosition:opts.backgroundPositionStart}, {duration:opts.duration});
	}
	
	$.fn.animatedBackground.stopAnimation = function($el, opts) {
		var animationConfig = { duration:opts.duration };
		if (opts.complete)
			animationConfig.complete = opts.complete;

		$el.stop().animate({backgroundPosition:opts.backgroundPositionEnd}, animationConfig);
	}

})(jQuery);

