// JavaScript Document

function sortNumber(a,b)
			{
			return b-a;
			}
			

function resizeNav()	{
				var navcontainer = document.getElementById("navcontainer");
				var subnavcontainer = document.getElementById("subnavcontainer");
				var totalwidth = 0;
				var linkCount = navcontainer.getElementsByTagName("a").length;
				var sublinkCount = 0;
				if (subnavcontainer != null)	{
					sublinkCount = subnavcontainer.getElementsByTagName("a").length;
				}
				var myArray = new Array(linkCount);
			
			for (x=0; x<linkCount; x++)	{
				linkwidth = navcontainer.getElementsByTagName("a")[x].offsetWidth;
				totalwidth = totalwidth + linkwidth;
				myArray[x] = linkwidth;
			}
			
			
			myArray.sort(sortNumber);
			var maxSize = myArray[0] + 30;
			
			//98 - 10 links per row
			//140 - 7 links per row
			//196 - 5 link per row
			
			tadjust = 0;
			
			if (maxSize * linkCount > 980)	{
			
				tadjust = 1;
			
				if (maxSize < 98)	{
					maxSize = 97;
					numPerRow = 10;
					}
				
				if (maxSize < 140 && maxSize > 98)	{
					maxSize = 139;
					numPerRow = 7;
					}
					
				if (maxSize > 140 && maxSize < 196)	{
					maxSize = 195;
					numPerRow = 5;
					}
				
					numRows = Math.ceil(linkCount / numPerRow);
					finalRowStart = Math.floor(linkCount / numPerRow);
					bottomBorderElementEnd = (finalRowStart * numPerRow);
					
					var height = (numRows * 25) + "px";
					navcontainer.style.height = height;
					document.getElementById("navcontainerwrap").style.height = height;
				
			}
			
					
					
					
					
					for (x=0; x<linkCount; x++)	{
						navcontainer.getElementsByTagName("a")[x].style.width = maxSize+"px";
						
			
			
						if(tadjust == 1)	{
							
						
							if (x < bottomBorderElementEnd)	{
								navcontainer.getElementsByTagName("a")[x].setAttribute("className", "bottom");
								navcontainer.getElementsByTagName("a")[x].setAttribute("class", "bottom");
							}
							
							if ((x+1) % numPerRow == 0 && x > 0)	{
								if (x < bottomBorderElementEnd)	{
									navcontainer.getElementsByTagName("a")[x].setAttribute("className", "endbottom");
									navcontainer.getElementsByTagName("a")[x].setAttribute("class", "endbottom");
								}
								else	{
									navcontainer.getElementsByTagName("a")[x].setAttribute("className", "end");
									navcontainer.getElementsByTagName("a")[x].setAttribute("class", "end");
								}
								navcontainer.getElementsByTagName("a")[x].style.width = navcontainer.getElementsByTagName("a")[x].offsetWidth + 1 + "px";
							}
						}
						
						
				}
				
				
				for (x=0; x<sublinkCount; x++)	{
						subnavcontainer.getElementsByTagName("a")[x].style.width = maxSize+"px";
						
				}
						
			
			}
