/** 
 * @projectDescription	Simple Navigation Animation Stagger
 * @author 	Matt Hobbs (http://nooshu.com/)
 * @version 	0.1 
 */
(function($){
	$.fn.staggerNaver = function(customOptions){
		var options = $.extend({}, $.fn.staggerNaver.defaultOptions, customOptions);
		return this.each(function(i){
			var $this = $(this);
			var $listItems = $this.find("li");
			var listItemLength = $listItems.length;
			
			//Check see for run on one page and on the selected page
			if(options.onePageOnly){
				if($(options.onePageSelector).length){
					$listItems.css({opacity: 0});
				}
			} else {
				$listItems.css({opacity: 0});
			}
			
			function outer(){
				var a = 0;
				function inner(){
					//If we are at the end of the animation, stop
					if(a === listItemLength){
						return;
					} else {
						$listItems.eq(a).animate({opacity: 1}, options.animateTime, options.easing, function(){
							animator();
						});
						a++;
					}
				}
			return inner;
			}
			
			//Create closure
			var animator = outer();
			
			//Check see for run on one page and on the selected page
			if(options.onePageOnly){
				if($(options.onePageSelector).length){
					animator();
				}
			} else {
				animator();
			}
		});
	};
	
	//Set our plug-in defaults
	$.fn.staggerNaver.defaultOptions = {
		animateTime: 210,
		easing: "swing",
		onePageOnly: false,
		onePageSelector: "#home"
	};
})(jQuery);
