// jquery.justifyNav.js plug-in
// This software is licensed under the MIT License
// Copyright (c) 2011 High Integrity Design, LLC.    
// highintegritydesign.com
//

(function($) {
$.fn.justifyNav = function() {
  return this.each(function() {
   var $this = $(this),
    $children = $this.children(),
    containerWidth = $this.width(),
    linksWidth = 0,
    count = $children.length;
   $children.each(function() {
    linksWidth += $(this).width();
   });

   // Don't give the last item or the 2nd to last item any right margin, then float the last item right.
   // This will account for small errors in JQuery's calculation of the item widths.
   // Otherwise the list can overflow the container!
   var linkSpacing = Math.floor((containerWidth - linksWidth) / (count - 1));
   $children
    .css('margin-right', linkSpacing + "px")
    .filter(":last")
     .css({"margin-right":0,"float":"right"})
     .prev()
      .css({"margin-right":0});
  });
};
})(jQuery);
