/*
 * Superfish v1.4.2 - jQuery menu widget
 * Copyright (c) 2008 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
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

(function(jQuery){
	jQuery.fn.superfish = function(op){
		var bcClass = 'sfbreadcrumb',
			over = function(){
				var ul = jQuery(this), menu = getMenu(ul);
				getOpts(menu,true);
				clearTimeout(menu.sfTimer);
				ul.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var ul = jQuery(this), menu = getMenu(ul);
				var o = getOpts(menu,true);
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=(jQuery.inArray(ul[0],o.jQuerypath)>-1) ? true : false;
					ul.hideSuperfishUl();
					if (o.jQuerypath.length && ul.parents('.'+o.hoverClass).length<1){over.call(o.jQuerypath);}
				},o.delay);	
			},
			getMenu = function(jQueryel){ return jQueryel.parents('ul.sf-js-enabled:first')[0]; },
			getOpts = function(el,menuFound){ el = menuFound ? el : getMenu(el); return jQuery.fn.superfish.op = jQuery.fn.superfish.o[el.serial]; },
			hasUl = function(){ return jQuery.fn.superfish.op.oldJquery ? 'li[ul]' : 'li:has(ul)'; };

		return this.each(function() {
			var s = this.serial = jQuery.fn.superfish.o.length;
			var o = jQuery.extend({},jQuery.fn.superfish.defaults,op);
			o.jQuerypath = jQuery('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				jQuery(this).addClass(o.hoverClass+' '+bcClass)
					.filter(hasUl()).removeClass(o.pathClass);
			});
			jQuery.fn.superfish.o[s] = jQuery.fn.superfish.op = o;
			
			jQuery(hasUl(),this)[(jQuery.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out)
			.not('.'+bcClass)
				.hideSuperfishUl();
			
			var link = jQuery('a',this);
			link.each(function(i){
				var jQueryli = link.eq(i).parents('li');
				link.eq(i).focus(function(){over.call(jQueryli);}).blur(function(){out.call(jQueryli);});
			});
			
			o.onInit.call(this);
			
		}).addClass('sf-js-enabled');
	};
	jQuery.fn.extend({
		hideSuperfishUl : function(){
			var o = jQuery.fn.superfish.op;
			var not = (o.retainPath===true) ? o.jQuerypath : '';
			o.retainPath = false;
			var jQueryul = jQuery('li.'+o.hoverClass,this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call(jQueryul);
			return this;
		},
		showSuperfishUl : function(){
			var o = jQuery.fn.superfish.op,
				jQueryul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			o.onBeforeShow.call(jQueryul);
			jQueryul.animate(o.animation,o.speed,function(){ o.onShow.call(this); });
			return this;
		}
	});
	jQuery.fn.superfish.o = [];
	jQuery.fn.superfish.op = {};
	jQuery.fn.superfish.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		oldJquery	: false, /* set to true if using jQuery version below 1.2 */
		disableHI	: false, /* set to true to disable hoverIntent usage */
		// callback functions:
		onInit		: function(){},
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	jQuery(window).unload(function(){
		jQuery('ul.sf-js-enabled').each(function(){
			jQuery('li,a',this).unbind('mouseover','mouseout','mouseenter','mouseleave','focus','blur');
		});
	});
})(jQuery);

