(function(a){
	a.fn.webwidget_menu_glide = function(p) {
		var p = p || {};
		var h = p && p.menu_margin           ? p.menu_margin           : '10';
		var i = p && p.menu_width            ? p.menu_width            : '100';
		var j = p && p.menu_height           ? p.menu_height           : '20';
		var m = p && p.sprite_speed          ? p.sprite_speed          : 'fast';
		var y = p && p.menu_selectedclass    ? p.menu_selectedclass    : 'selected';
		var z = p && p.sprite_class          ? p.sprite_class          : 'sprite';

		h += 'px';
		i += 'px';
		j += 'px';

		var n = a(this);

		if(n.children('ul').length == 0 || n.find('li').length == 0) {
			n.append('Require menu content');
			return null;
		}
		
		s_m(n.children('ul').children('li'), h, i, j);

		s_m_t_c(n.find('a'), j);

		if (n.children('ul').children('li').is('.' + y)) {
			var o = n.children('ul').children('li').filter('.' + y).offset();
			i = n.children('ul').children('li.' + y).innerWidth();
		} else {
			var o = n.children('ul').children('li:first').offset();
		}

		var q = o.left + 'px';
		
		s_m_s_c(n.find('.webwidget_menu_glide_sprite'), i, j, q);

		n.children('ul').children('li').hover(function() {
			
			var b = $(this).offset();

			var c = b.left + 'px';
			
			if (!$(this).is('.' + y)) {
				$(this).children('a').addClass(z);
			} else {
				$(this).children('a').addClass(z);
			}
			
			n.find('.webwidget_menu_glide_sprite').stop().animate({
				left:c,
				width: $(this).width() + 10
			}, m)
			
		}, function() {
			
			if (!$(this).is('.' + y)) {
				$(this).children('a').removeClass(z);
			}

			n.find('.webwidget_menu_glide_sprite').stop().animate({
				left: q,
				width: i
			}, m)
		});

		n.children('ul').children('li').children('ul').children('li').hover(function(){}, function(){});
		
		function s_m_t_c(a, c) {
			a.css('line-height', c);
		}
		
		function s_m(a, b, c, d) {
			style = 'margin-right:' + b + '; width: ' + c + 'px; height: ' + d + ';';
			a.attr('style', style)
		}
		
		function s_m_s_c(a, c, d, e) {
			a.css('width', c);
			a.css('height', d);
			a.css('left', e)

		}
	}
})(jQuery);
