/**
 * jQuery.dropLine - Dropline menu for jQuery.
 * 
 * Copyright (c) 2010 Chris Froese
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Date: 2010-02-25
 * Version: 1.1
 *
 * CHANGES
 * 2010-02-25: Added animation check to prevent animation queue build up.
 */

(function($) {
	$.fn.dropLine = function(settings) { 
		var config = {'downspeed': 400, 'upspeed': 200, 'activeClass': 'current'};
		if (settings) {$.extend(config, settings);}
		return this.each(function(i) {
			var $this = $(this);
			$this.mouseout(function() {
				$this.find('li.'+config.activeClass+' ul:hidden:eq(0)').show();
			});
			$this.children('li').each(function() {
				// has sub nav?
				var ulCount = $(this).children('ul').length;
				// yes has sub nav.
				if (ulCount > 0) {
					$(this).hover(
						// over
						function() {
							$liUl = $(this).children('ul:eq(0)');
							// don't show if already being animated
							if ($liUl.queue().length <= 1) {
								$liUl.show();
							}
							// fix ie 6 overflow issue.
							if (document.all && !window.XMLHttpRequest) {
								$(this).find('ul').css({overflow: 'visible'});
							}
						},
						// out
						function() {
							$(this).children('ul:visible:eq(0)').hide();
						}
					);
				}
				if ($(this).hasClass(config.activeClass)) {
					$(this).find('ul').css({display:'block', visibility:'visible', 'z-index': 100});
				} else {
					$(this).find('ul').css({display:'none', visibility:'visible', 'z-index': 200});
				}
			});
		});
	};
})(jQuery);
