﻿// Fix navbar widths

//Prototype version below
//Event.observe(window, "load", function(){
//Prototype version Above

    $(document).ready(function(){
	// ugh... had to dig this up to round down our result since IE6 and 7 were making it wrap to the next line or not showing it at all.
	function roundDown(value,num){
		var a,b,c,i;
		a = String(value);
		b = a.indexOf('.');
		c = a.length;
		
		if (num==0) {
			if (b!=-1) {
				a = a.substring(0,b);
			} 	
		}
		else {
			if (b==-1) {
				a = a + ".";
				for (i=1;i<=num;i++)
				a = a + "0";
			}
			else {
				a = a.substring(0,b+num+1);
				for (i=c;i<=b+num;i++)
					a = a + "0";
			}
		}
		return a;
	}

	// 802 is the width of the whole top menu
	var seperator_width_percentage_to_subtract = 100/(500 - $("#top_nav ul li.top_nav_seperator").length)

    var top_nav_lis = $("#top_nav ul li.main_level");

    var width = (roundDown(((100/top_nav_lis.length) - seperator_width_percentage_to_subtract),1) + '%');

    top_nav_lis.each(function(){
       $(this).width(width)
       if ($.browser.msie && $.browser.version < 8 ) {
         // set the left margin negative to re-position the menu under the right link for IE
         $(this).children('span').css("marginLeft", '-' + $(this).width() + 'px');
         // set the width of the span explicitly so that width 100% works on the span's anchor tags for the bottom border
         $(this).children('span').css("width", $(this).children('span').width());
         //alert($(this).width());
       }
    })
  }

)
