// DO NOT OVERWRITE, THIS FILE IS MODIFIED

/*
 * 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,
			thisMenu = $(this),
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
/* 	ARIA Hack
	Author: SJ
	UTS Department
*/
// Begin hack. Writes a jump link so the menu can be escaped.
			$(this).parent().parent().parent().append('<p id="menuskiptargetholder"><a name="postMenuJump" id="postMenuJump" class="skip" href="#postMenuJump">End of Menu</a></p>');
			
			$(document).click(function() {
				$(this).hideSuperfishUl();
			});
			
			// Track the status of the alt + ctrl key for the CTRL + ALT + M combo
			var isAltKey = false,
			isCtrlKey = false;
			$(document).keydown(function (e) {
				switch (e.keyCode) {
					case 17:
						isCtrlKey = true;
					break;
					case 18:
						isAltKey = true;
					break;
					case 77:
						// Go to the menu when CTRL + ALT + M is called
						if (isCtrlKey && isAltKey) {
						$(thisMenu).find("a:first").focus();
						return false;
						}
					break;
					case 36:
						if (isCtrlKey && isAltKey) $("#skiplink").focus();
						return false;
					break;
				}
			});
			$(document).keyup(function (e) {
				switch (e.keyCode) {
					case 17:
						isCtrlKey = false;
					break;
					case 18:
						isAltKey = false;
					break;
				}
			});
// First set up the roles of the menubar and their child elements.
			$(this).attr("role","menubar");
			$(this).find("a").attr("role","menuitem");
			$(this).find("ul").attr("role","menu");
// Find all menu elements and make them accessible via space-bar on keyboard
				$(this).find("li").each(function() {
					$(this).keydown(function(e) {
						if (e.keyCode == 32) {
							window.location = $(this).find("a:first").attr("href");
							return false;
						}
					});
				});
				// Set up the elements in the top menu-bar
				$(this).children().each(function() {
					$(this).keydown(function(e) {
						switch (e.keyCode) {
							case 37:
							// Navigate to the left element in the top menu bar
								$(this).prev().find("a:first").focus();
								return false;
							break;
							case 38:
							// Navigate into the sub-menu
								$('ul a:first',this).focus();
								return false;
							break;
							case 39:
							// Navigate to the right element in the top menu bar
								$(this).next().find("a:first").focus();
								return false;
							break;
							case 40:
							// Navigate into the sub-menu
								$('ul a:first',this).focus();
								return false;
							break;
							case 27:
							// Hide the open sub-menu
								$(this).find("ul").css("visibility","hidden");
								$(this).find("ul").css("display","none");
							// Un-highlight the current selected element
								$(this).removeClass("sfHover");
							// Escape from the menu itself to the next element immediately after the menu
								$("#postMenuJump").focus();
								return false;
							break;
						}
					});
					// Set up all the elements that don't have a sub-menu in them
					$(this).find("li:not(ul)").each(function() {
						$(this).keydown(function(e) {
							switch (e.keyCode) {
								case 37:
								// Escape to the higher level menu
									$(this).removeClass(sf.defaults.hoverClass);
									// Bug with IE 8.0 causes the DOM to have an extra child in the tree
									if ($.browser.msie && $.browser.version == 8) {
										$(this).parent().parent().parent().find("a:first").focus();
									} else {
										$(this).parent().parent().find("a:first").focus();
									}
									return false;
								break;
								case 27:
								// Same as case 37
									$(this).removeClass(sf.defaults.hoverClass);
									if ($.browser.msie && $.browser.version == 8) {
										$(this).parent().parent().parent().find("a:first").focus();
									} else {
										$(this).parent().parent().find("a:first").focus();
									}
									return false;
								break;
								case 38:
								// Move up to the sub-menu element immediately above this
									$(this).prev().find("a:first").focus();
									return false;
								break;
								case 39:
								// Don't do anything, this element has no sub-menu
									return false;
								break;
								case 40:
								// Move down to the sub-menu element immediately below this
									$(this).next().find("a:first").focus();
									return false;
								break;
							}
						});
					});
					
					// Set up all the elements that DO have a sub-menu in them
					$(this).find("li:has(ul)").each(function() {
						$(this).keydown(function(e) {
							switch (e.keyCode) {
								case 37:
								// Escape to the higher-level menu
									$(this).removeClass(sf.defaults.hoverClass);
									$(this).parent("a:first").focus();
									return false;
								break;
								case 27:
								// Same as case 37
									$(this).removeClass(sf.defaults.hoverClass);
									$(this).parent("a:first").focus();
									return false;
								break;
								case 38:
								// Move to the sub-menu element immediately above this
									$(this).prev("a:first").focus();
									return false;
								break;
								case 39:
								// Enter into the next sub-menu that this element is a parent of
									$('ul a:first',this).focus();
									return false;
								break;
								case 40:
								// Move to the sub-menu element immediately below this
									$(this).next("a:first").focus();
									return false;
								break;
							}
						});
					});
					
					// We finally have to make sure that navigation cycles, that is
					// when the selector reaches the bottom, it automatically goes back
					// to the top. We don't have to worry about defining any other arrows
					// because the previous functions bound them already.
					
					// Select all top placed elements in each sub-menu
					$(this).find("ul").find("li:first-child").each(function() {
						// Look for an arrow up
						$(this).keydown(function(e) {
							if (e.keyCode == 38) {
									// Find the last placed element in the sub-menu and select it
									$(this).parent().children("li:last-child").find("a:first").focus();
									return false;
							}
						});
					});
					
					// Select all bottom placed elements in each sub-menu
					$(this).find("ul > li:last-child").each(function() {
						// Look for an arrow down
						$(this).keydown(function(e) {
							if (e.keyCode == 40) {
									// Find the first placed element in the sub-menu and select it
									$(this).parent().find("a:first").focus();
									return false;
							}
						});
					});
				});
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
				$('>a:first-child',this).attr("aria-haspopup","true");
			})
			.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);});
			});
			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.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.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(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			$ul.attr("aria-hidden","true");
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			$ul.attr("aria-hidden","false");
			return this;
		}
	});

})(jQuery);
