(function ($) {

	$.fn.contactSpacer = 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 $inner = $(this).children('span').first();
							var $span = $('<span class="menuSpacerItem" />').css('padding', '0 ' + gap + 'px')
							
							$inner.before($span);
							$span.append($inner);
						});
					}
				}
			}
		});
	};
})(jQuery);

