
(function($) {
	$.fn.extend({
		tvgMenu: function() {
			
			$(this).css({ visibility: 'visible' });
			$(this).children('li').find('span').each(function() {
				$(this).replaceWith('<a href="javascript:void(0);" class="oldspan">'+$(this).html()+'</a>');
			});
			Cufon.replace($(this).find('a'), { hover: true });
	
			$(this).addClass('tvgmenu_applied');
			var $headers = $(this).children('li');
			$.each($headers, function(i) {
				
				// Near the bottom or top of the menu?
				if ((i + 1)/$headers.length > .6) {
					$(this).addClass('near_bottom');
				} else {
					$(this).addClass('near_top');
				}
				
				// Get submenu UL
				var $submenu = $(this).find('ul');
				$submenu.find('a:first').addClass('first');
				$submenu.find('a:last').addClass('last');
				$(this).mouseover(function() {
					$(this).addClass('hover');
				});
				$(this).mouseout(function() {
					$(this).removeClass('hover');
				});
			});
			return this;
		}
	})
})(jQuery);
