/**
 *
 * jquery.endlessScroller.js version 0.81b
 * requires jQuery
 * Copyright (c) 2011 Brionne Godby (http://www.evilgeekstudios.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */
(function($){  
	$.fn.popDown = function(options){
		var defaults = {
			menuTarget:'.nav',
			subTarget:'.subNav',
			target:'rel',
			animSpeed:500
		};
		var options = $.extend(defaults, options);

		return this.each(function(){
			var container = this;
			var menu=$(options.menuTarget, container);
			var subMenu=$(options.subTarget, container);
			var subMenuHeight=subMenu.height();
			subMenu.height(0);
			$(container).mouseleave(function(){
				if(subMenu.is(':animated'))
					subMenu.stop();
				subMenu.animate({height:0}, options.animSpeed, function(){
					$(this).css('display', 'none');
				});
			});
			$(subMenu).mouseenter(function(){
				if(subMenu.is(':animated'))
					subMenu.stop();
					
				subMenu.css('display', 'block').animate({height:subMenuHeight}, options.animSpeed);
			});
			
			menu.find('a').each(function(){
				var targetVal=$(this).attr(options.target);
				if(targetVal>'' && $(targetVal).children().length>0){
					$(this).mouseenter(function(){
						if(subMenu.is(':animated'))
							subMenu.stop();
						
						subMenu.css('display', 'block').animate({height:subMenuHeight}, options.animSpeed);
						subMenu.children().not('.bottom').hide();
						$(targetVal).show();
					});
				}else{
					$(this).mouseenter(function(){
						if(subMenu.is(':animated'))
							subMenu.stop();

						subMenu.animate({height:0}, options.animSpeed, function(){
							$(this).css('display', 'none');
						});
					});	
				}
				
			});
			
			
		});
	};
})(jQuery);
