/*
 * Superfish - jQuery menu widget
 *
 * Copyright (c) 2007 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

(function($){
	$.fn.superfish = function(o){
		var defaults = {
			hoverClass	: "sfHover",
			delay		: 500,
			animation	: {opacity:"show"},
			speed		: "normal"
		};
		var over = function(){
			var $$ = $(this);
			clearTimeout(this.sfTimer);
			if (!$$.is("."+o.hoverClass)) {
				$$.addClass(o.hoverClass)
					.children("ul")
						.animate(o.animation,o.speed)
						.end()
					.siblings().removeClass(o.hoverClass);
			}
		};
		var out = function(){
			var $$ = $(this);
			this.sfTimer=setTimeout(function(){
				$$.removeClass(o.hoverClass)
				.children("ul")
					.hide();},o.delay);
				};
		o = $.extend(defaults, o || {});
		$("li[ul]",this)
			.hover(over,out)
			.find("a")
				.focus(function(){ $(this).parents("li[ul]").each(over); })
				.blur(function(){ $(this).parents("li[ul]").each(out); });
		return this;
	};
})(jQuery);
