(function ($) {	
	$.fn.menu = function (options) {
		this.each(
			function () {
				var settings = $.extend({
					open: 'mouseenter',
					close: 'mouseleave',
					openClass: 'hover',
					delay: 500,
					animation: {
						open: {
							type: 'fadeIn',
							duration: 'slow'
						},
						close: {
							type: 'fadeOut',
							duration: 'slow'
						}
					}
				}, options);
				
				function onOpen (e) {
					var $this = $(this);
					var $submenu = $this.children('ul');
					$submenu.show();
					$submenu.position({
						my: 'left top',
						at: 'left bottom',
						of: this,
						collision: 'fit'
					});
				}
				
				function onClose (e) {
					var $this = $(this),
						$submenu = $this.children('ul');
					$submenu.hide();
				}
				
				var $items = $(this).find('li');
				$items[settings.open](onOpen);
				$items[settings.close](onClose);
			}
		);
	};
	
	$(document).ready(
		function () {
			$('.mainMenu').menu();
		}
	);
})(jQuery);
