// This adds spacer divs to the top nav elements and stretches them 100%.

$(document).ready(function($) {

	$('.top_box, .last_top_box').before('<div class="topnav_spacer"></div>');
	
	var mainWidth = $('#topNavInnertube').innerWidth();

	liCount = $('.top_box,.first_top_box,.last_top_box').length;

	var liPadding = 0;
	$('.top_box,.first_top_box,.last_top_box,.topnav_spacer').each(function(){
		liPadding += $(this).innerWidth() - $(this).width();
	});

	var spacerPadding = 0;
	$('.top_box,.first_top_box,.last_top_box,.topnav_spacer').each(function(){
		spacerPadding += $(this).innerWidth() - $(this).width();
	});

	var spacerWidth = 0;
	$('.topnav_spacer').each(function() {
		spacerWidth += $(this).innerWidth();
	});

	var maxWidth = (mainWidth - spacerPadding - liPadding - spacerWidth) / liCount;
    
	$('#topNavInnertube li,.top_section').each(function(i){
		$(this).width(maxWidth);
	});
});

