﻿// 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/(802 - $("#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());
       }
    })
  }

)

// //This was the prototype implementation that I removed because my image rotator was craeted with jquery and I didn't want to mess with 2 frameworks

// do some browser sniffing to make the dropdown have the right margin... annoying
//Prototype.Browser.IE6=Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6;
//Prototype.Browser.IE7=Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==7;  

//	// 802 is the width of the whole top menu
//	var seperator_width_percentage_to_subtract = 100/(802 - $$("#top_nav ul li.top_nav_seperator").length)

//    var top_nav_lis = $$("#top_nav ul li.main_level");
//    top_nav_lis.each(function(li){
//       var width = (roundDown(((100/top_nav_lis.length) - seperator_width_percentage_to_subtract),1) + '%');
//       li.style.width = width
//       
////       if (Prototype.Browser.IE6 || Prototype.Browser.IE7) {
//       if ($.browser.msie && $.browser.version < 8 )) {
//         // set the left margin negative to re-position the menu under the right link for IE
//         li.down('span').style.marginLeft = '-' + li.getWidth() + 'px';
//         // set the width of the span explicitly so that width 100% works on the span's anchor tags for the bottom border
//         li.down('span').style.width = li.down('span').getWidth();
//       }
//    })
//  }

//)
