
/*
 * Superfish v1.4.8 - 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 sf = $jquery.fn.superfish,
			c = sf.c,
			$jqueryarrow = $jquery(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $jquery$jquery = $jquery(this), menu = getMenu($jquery$jquery);
				clearTimeout(menu.sfTimer);
				$jquery$jquery.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $jquery$jquery = $jquery(this), menu = getMenu($jquery$jquery), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($jquery.inArray($jquery$jquery[0],o.$jquerypath)>-1);
					$jquery$jquery.hideSuperfishUl();
					if (o.$jquerypath.length && $jquery$jquery.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$jquerypath);}
				},o.delay);	
			},
			getMenu = function($jquerymenu){
				var menu = $jquerymenu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($jquerya){ $jquerya.addClass(c.anchorClass).append($jqueryarrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $jquery.extend({},sf.defaults,op);
			o.$jquerypath = $jquery('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$jquery(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$jquery('li:has(ul)',this)[($jquery.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $jquery('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $jquerya = $jquery('a',this);
			$jquerya.each(function(i){
				var $jqueryli = $jquerya.eq(i).parents('li');
				$jquerya.eq(i).focus(function(){over.call($jqueryli);}).blur(function(){out.call($jqueryli);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($jquery.browser.msie && $jquery.browser.version < 7)) menuClasses.push(c.shadowClass);
			$jquery(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $jquery.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($jquery.browser.msie && $jquery.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$jquery.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$jquerypath : '';
			o.retainPath = false;
			var $jqueryul = $jquery(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($jqueryul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$jqueryul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($jqueryul);
			o.onBeforeShow.call($jqueryul);
			$jqueryul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($jqueryul); o.onShow.call($jqueryul); });
			return this;
		}
	});

})(jQuery);

