/**
 * @author Jean-Paul Gorman
 * v. 1.03
 * =============================
 * Usage
 * 
 	$('#top-heading nav.nav ul li:not(.selected) a').bgAnimate({
		outPosition:"0 99px",
		overPosition:"0 0",
		easingType: 'easeOutCubic',
		target:'h3', // if the target is not
		speedIn: 200,	
		speedOut: 200		
	});
 */
	(function($){
		$.fn.bgAnimate = function (options) {
			
			var opts = $.extend({}, $.fn.bgAnimate.defaults, options);		
			var animateObject = null;
			
			return this.each(function () {
										
					// only apply to items that don't have class 'selected'
					if($(this).hasClass('selected') == false){
						
						// do background position with target
						if(opts.target != null){
							
							$(this).children(opts.target).css( {backgroundPosition: opts.outPosition} ); // set initial background position
							
							// attach mouseover effects
							$(this)
							.mouseover(function(){
								$(this).children(opts.target).stop().animate({backgroundPosition:"("+opts.overPosition+")"}, {easing: opts.easingType},{duration:opts.speedIn})
							})
							.mouseout(function(){
								$(this).children(opts.target).stop().animate({backgroundPosition:"("+opts.outPosition+")"}, {easing: opts.easingType}, {duration:opts.speedOut})
							});
						}else{
						// do background position without target
						
							// attach mouseover effects
							$(this)
							.css( {backgroundPosition: opts.outPosition} ) // set initial background position
							.mouseover(function(){
								$(this).stop().animate({backgroundPosition:"("+opts.overPosition+")"}, {easing:  opts.easingType},{duration:opts.speedIn})
							})
							.mouseout(function(){
								$(this).stop().animate({backgroundPosition:"("+opts.outPosition+")"}, {easing:  opts.easingType}, {duration:opts.speedOut})
							});
						}
					}
			});
		}
		
		$.fn.bgAnimate.defaults = {
			outPosition:null,
			overPosition:null,
			easingType:'easeInCubic',	
			target: null,	
			speedIn: 200,	
			speedOut: 200
		}

	})(jQuery);
