/**
 * Sliding menu plugin
 * makes an animated div slide along the bottom of the menu and position directly below 
 * the item A tag, it adjusts its width accordingly.
 * 
 * @author Grant Ockwell
 */
(function($) {
	var animationTimer = null;

	$.fn.extend({
		
		slideMenu: function() {
			$(function() {
			
				$('#menu-slide').hide();

				if ($('a.topnavSelected').length > 0) {
					setTimeout("$('a.topnavSelected').mouseover()", 500);
				} else {
					$('#menu').mouseleave(function() {
						animationTimer = setTimeout("$('#menu-slide').fadeOut('slow')", 200);
					});
				}
				
				
			});
		
			return this.each(function() {
				$(this).find('A').mouseover(function() 
				{
					if (animationTimer) { 
						clearTimeout(animationTimer); 
					}
					
					$('#menu-slide').clearQueue();
					
					if ($('#menu-slide:hidden').length == 1) {
						$('#menu-slide').fadeIn();
					} 
					
					$('#menu-slide').animate({
						left: $(this).position().left,
						width: $(this).outerWidth()
					}, 500);
					
					
				}).mouseout(function() 
				{
					if ($('a.topnavSelected').length > 0) {
						animationTimer = setTimeout("$('#menu-slide').animate({left: $('a.topnavSelected').position().left, width: $('a.topnavSelected').outerWidth()}, 600)", 200);
					} 
				});
			});
		}
	})
})(jQuery);
