
jQuery.fn.extend({
/**
 * Smooth menu widget for jQuery.
 * Orginaly a port of fancy menu from from http://devthought.com/cssjavascript-true-power-fancy-menu/
 * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
 * @link http://meta20.net/Smooth_menu_widget_for_jQuery
 * @version 0.5
 * @param	{Array}		options
 * Allowed options:
 * - delay: in miliseconds
 * - easein: see easing.js
 */
 
	SmoothMenu: function(options) {
		this.each(function(){
			var defaultPosition;
			var $menu = $(this)
				.css({position: 'relative'});
			options = $.extend(options || {}, {
				delay: 200,
				easein: 'linear'
			});
			var $selection = $('<li class="selection"><div></div></li>')
				.css({position: 'absolute'})
				.appendTo($menu)
				.hide();
			if ( $menu.find('li.selected').size() )
				setDefaultPosition(
					$menu.find('li.selected').get(0)
				);
			$menu.find('li:not(.selection) > *').each(function(){
				$(this).mouseover(function(){
					moveSelectionTo(this);
				});
				$(this).mouseout(function(){
					moveSelectionTo(this);
				});
				$(this).click(function(){
					if (! defaultPosition )
						setDefaultPosition(this, true);
				});
			});
			// functions
			function moveSelectionTo(el) {
				if (! defaultPosition ) {
					setDefaultPosition(el, true)
				} else {
					$selection.stop();
					$selection.get(0).shouldBeHere = el.offsetLeft;
					$selection.animate({
							left:	el.offsetLeft,
							width:	el.offsetWidth,
							height:	el.offsetHeight,
							top:	el.offsetTop
						},
						options.delay,
						options.easein
					);
				}
			}
			function setDefaultPosition(el, useEffect) {
				$selection.css({
					left:	el.offsetLeft,
					width:	el.offsetWidth,
					height:	el.offsetHeight,
					top:	el.offsetTop
				});
				// colision with $selection.stop();
//				if (useEffect)
//					$selection.fadeIn()
//				else
					$selection.show();
				defaultPosition = el;
			}
		});
	}
});