﻿
/*
* 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($) {
	$.fn.superfish = function(op) {

		var sf = $.fn.superfish,
			c = sf.c,
			over = function() {
				var menuItem = $(this); //mouseover item
				var menu = getMenu(menuItem); //get menu base ul
				clearTimeout(menu.sfTimer); //clear the 'hide' timeout
				menuItem.showSuperfishUl(); //show dropdown
				menuItem.siblings().hideSuperfishUl(); //hide other dropdowns
			},
			out = function() {
				var menuItem = $(this); //mouseout item
				var menu = getMenu(menuItem); //get menu base ul
				var o = sf.op; //get options
				clearTimeout(menu.sfTimer); //clear the 'hide' timeout
				menu.sfTimer = setTimeout(function() { menuItem.hideSuperfishUl(); }, o.delay); //reset the 'hide' timeout
			},
			getMenu = function($menu) {
				var menu = $menu.parents('ul.' + c.menuClass + ':first')[0];
				sf.op = sf.o[menu.serial];
				return menu;
			};

		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({}, sf.defaults, op);
			sf.o[s] = sf.op = o;

			var itemsWithChildren = $('li:has(div)', this);
			itemsWithChildren[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over, out).not('.' + c.bcClass).hideSuperfishUl();

			var $a = $('a', this);
			$a.each(function(i) {
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function() { over.call($li); }).blur(function() { out.call($li); });
			});
			o.onInit.call(this);

		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.c = {
		bcClass: 'sf-breadcrumb',
		menuClass: 'sf-js-enabled',
		anchorClass: 'sf-with-ul',
		arrowClass: 'sf-sub-indicator',
		shadowClass: 'sf-shadow'
	};
	sf.defaults = {
		hoverClass: 'AspNet-Menu-Hover',
		pathClass: 'overideThisToUse',
		pathLevels: 1,
		delay: 0,
		animation: { opacity: 'show' },
		speed: 'normal',
		autoArrows: false,
		dropShadows: false,
		disableHI: false, 	// true disables hoverIntent detection
		onInit: function() { }, // callback functions
		onBeforeShow: function() { },
		onShow: function() { },
		onHide: function() { }
	};
	$.fn.extend({
		hideSuperfishUl: function() {
			var o = sf.op;
			o.retainPath = false;
			var topLevel = $('li.' + o.hoverClass, this).add(this).removeClass(o.hoverClass)
			var $ul = topLevel.find('>div');
			$ul.hide();
			$ul.css('display', 'none');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl: function() {
			var o = sf.op;
			var sh = sf.c.shadowClass + '-off';
			var flyoutDiv = $('>div', this);
			o.onBeforeShow.call(flyoutDiv);
			flyoutDiv.animate(o.animation, o.speed, function() { o.onShow.call(flyoutDiv); });
			this.addClass(o.hoverClass);
			return this;
		}
	});

})(jQuery);

