(function($) {
	$.fn.menu = function(options) {
		if(this.length) {
		
			// User variables
			var settings = $.extend({
				overlay : '.background',
				buttons : '.navigation_button',
				activeButton : '.active_navigation_button',
				showClass : 'button_on',
				hideClass : 'button_off',
				dropdowns : 'ul.subelements'
			}, options);
		
			return this.each(function() {

				// Global variables
				var navigation = $(this);
				var overlay = navigation.find(settings.overlay);
				var buttons = navigation.find(settings.buttons + ',' + settings.activeButton);
				var dropdowns = navigation.find(settings.dropdowns);
				var background;
				var fadeOut = {
					opacity : 0,
					duration : 250
				};
				
				// Functions
				$.fn.addBackground = function(className) {
					return this.each(function() {
						$(this).after($('<span class="' + className + '" />'));
					});
				};
				$.fn.fadeTo = function(options) {
					var settings = $.extend({
						opacity : 1,
						duration : 'normal'
					}, options);
					return this.each(function() {
						var node = $(this);
						if(settings.opacity > 0) {
							node
								.stop()
								.css('opacity', 0)
								.show()
								.animate({
									opacity : settings.opacity
								}, settings.duration);
							node.filter = '';
						} else {
							node
								.stop()
								.animate({
									opacity : settings.opacity
								}, settings.duration, function() {
									$(this).hide();
								});
						};
					});
				};
				
				// Initial actions
				overlay.hide();
				dropdowns.hide();
				buttons.each(function() {
					var button = $(this);
					if(button.attr('className') !== settings.activeButton.slice(1, settings.activeButton.length)) {
						button.children('a')
							.css('backgroundImage', 'none')
							.addBackground(settings.hideClass)
							.addBackground(settings.showClass)
					};
				});
							
				// Events				
				buttons.hover(function() {
					var button = $(this);
					
					// Show the dropdown
					var dropdown = button.find(settings.dropdowns);
					if(dropdown.children('li').length > 1) {
						dropdown.fadeTo({
							opacity : .9
						});
					};
					
					// Show the background
					background = button.children('span').eq(0).fadeTo();
					
					// Show the overlay
					overlay.fadeTo({
						opacity : .5
					});
					
					// Pause the banner
					window.clearInterval(controller.interval);
					
				}, function() {
				
					// Hide the background
					background.fadeTo(fadeOut);
					
					// Hide the dropdiwn
					dropdowns.hide();
					
					// Hide the overlay
					overlay.fadeTo(fadeOut);
					
					// Let the banner continue
					controller.Run();
				});
				
			});
		};
	};
})(jQuery);
