(function($){
	$.fn.dropDownMenu = function(options){
		var defaults = {
			menu: 'auto',
			prefix: 'menu',
			showDelay: 100,
			hideDelay: 100,
			transition: 'slide',
			onTime: 300,
			offTime: 300,
			rtl: false
		};
		var showInt, hideInt, _el, _menu;
		var options = $.extend(defaults, options);
		
		var setup = function(){
			setMenu(options.menu);
			options.showDelay = parseInt(options.showDelay);
			options.hideDelay = parseInt(options.hideDelay);
		}
		
		var setMenu = function(menu){
			switch(menu){
				case 'auto':
					_menu = _el.children('ul');
					break;
				default:
					_menu = $(menu);
					break;
			}
		};
		
		var showHandler = function(){
			clearTimeout(showInt);
			clearTimeout(hideInt);
			_menu.bind('mouseenter', showHandler);
			_menu.bind('mouseleave', hideHandler);
			if (options.showDelay == 0){
				showMenu();
			} else {
				showInt = setTimeout(showMenu, options.showDelay);
			}
		}
		
		var hideHandler = function(){
			clearTimeout(showInt);
			clearTimeout(hideInt);
			if (options.hideDelay == 0){
				hideMenu();
			} else {
				showInt = setTimeout(hideMenu, options.hideDelay);
			}
		}
		
		var showMenu = function(){
			switch(options.transition){
				case 'slide':
					_menu.slideDown(options.onTime);
					break;
				case 'fade':
					_menu.fadeIn(options.onTime);
					break;
				case 'show':
					_menu.show(options.onTime);
					break
				case 'none':
				default:
					_menu.show();
					break;
			}
		}
		
		var hideMenu = function(){
			switch(options.transition){
				case 'slide':
					_menu.slideUp(options.offTime);
					break;
				case 'fade':
					_menu.fadeOut(options.offTime);
					break;
				case 'show':
					_menu.hide(options.offTime);
					break
				case 'none':
				default:
					_menu.hide();
					break;
			}
		}

		return this.each(function(){
			_el = $(this).css('cursor', 'pointer');
			setup();
			var left = _el.position().left;
			if (options.rtl){
				left += (_el.width() - _menu.width() + parseInt(_el.css('paddingLeft')));
			}
			_menu.css('left', left).hide();
			_el.bind('mouseenter', showHandler);
			_el.bind('mouseleave', hideHandler);
		});
	};
})(jQuery);
