(function ($) {

	$.fn.menuSpacer = function (options) {

		// Create some defaults, extending them with any options that were provided
		var settings = $.extend({
		}, options);

		return this.each(function () {
			if ($(this).is('ul')) {
				var $List = $(this);

				if ($List.children().size() > 0) {
					var $Children = $List.children();

					var innerWidth = 0;
					$Children.each(function () {
						innerWidth += $(this).outerWidth(true);
					});

					var outerWidth = $List.width();

					var totalGap = outerWidth - innerWidth;

					if (totalGap > 0) {
						var gap = Math.floor(totalGap / ($Children.size() * 2));
						$Children.each(function () {
							var $link = $(this).children('a').first();
							var $span = $('<span class="menuSpacerItem" />').css('padding', '0 ' + gap + 'px').html($link.html());
							$link.empty().append($span);
						});
					}
				}
			}
		});
	};
})(jQuery);

