// JavaScript Document
 
 		var tab_left_margin = 0;
		var tab_right_margin = 0;
		
		var extra_padding = 0;
		var apply_extra_padding = 0;
		
		var tab_total_left_margin = 0;
		var tab_total_right_margin = 0;
		
		var total = 0;
		var tabs_table_width = 658;
		var tabs_width = new Number();
		var tabs_width = 0;
		var tabs_difference = 0;
		var tab_padding = 0;
		var classId = new String();
			
  		var parent = document.getElementById("tablist");
        var childCount = parent.getElementsByTagName("li").length;
		
		var addextraleft_padding;
		var addextraright_padding;
		
		var last_tab_left_padding = new Number();
		
		var tab_total = new Number();

		total = Number(childCount);
		
 
function changestyle(tab_num)
{
	
	var i=1;
	
	// Loop through all the tabs to reset the styles back to normal

	for (i=1;i<=total;i++)
	{
		
		// So, if the tab weve got to is not the one we want then just make its style transparent

		if (i!=tab_num)
		{
			document.getElementById("active"+i).style.background = "transparent";
			document.getElementById("tab"+i).style.background = "transparent";

		// Otherwise do you restyling business

		} else {
			
			// If its the first tab then make sure the left corner looks right
			
			if (i==1)
			{
				document.getElementById("tab"+i).style.background = "#EFEFEF url(tabs/first_corner.gif) left top no-repeat";
				document.getElementById("active"+i).style.background = " url(tabs/selectedrightcorner.gif) right top no-repeat";
			
			// If its the last tab then make sure the last corner looks right
			
			} else if (i==total)	{
				document.getElementById("tab"+i).style.background = "#EFEFEF url(tabs/selectedleftcorner.gif) left top no-repeat";
				document.getElementById("active"+i).style.background = " url(tabs/new_end_corner.gif) right top no-repeat";
				
			// For all the rest, just do the usual left and right corners	
				
			} else	{
				document.getElementById("tab"+i).style.background = "#EFEFEF url(tabs/selectedleftcorner.gif) left top no-repeat";
				document.getElementById("active"+i).style.background = " url(tabs/selectedrightcorner.gif) right top no-repeat";
	
			}
			
		}
		
	}
}
 
 
//Function to get the element width  
function get_width(id) 
{

        if(document.getElementById) {
            var elem = document.getElementById(id);
        } else if (document.all){
            var elem = document.all[id];
        }
 
        var yPos = elem.offsetWidth; 
		return yPos; 
}
  
	window.onload=function()
	{
		
		var tab_left_margin = 0;
		var tab_right_margin = 0;
		
		var extra_padding = 0;
		var apply_extra_padding = 0;
		
		var tab_total_left_margin = 0;
		var tab_total_right_margin = 0;
		
		var total = 0;
		var tabs_table_width = 658;		
		
		var tabs_width = new Number();
		var tabs_width = 0;
		var tabs_difference = 0;
		var tab_padding = 0;
		var classId = new String();
			
  		var parent = document.getElementById("tablist");
        var childCount = parent.getElementsByTagName("li").length;

		var addextraleft_padding;
		var addextraright_padding;
		
		var last_tab_left_padding = new Number();
		
		var tab_total = new Number();
		
		// Total number of tabs

		total = Number(childCount);
		
		// Loop through each tab and grab its width
								
		for (var i = 1; i < total+1; i++)
			{
				tabwidth = get_width("tab"+i);
				
				tabs_width = tabs_width + Number(get_width("tab"+i));
			}
		
		//Work out the different between the table width and the total tabs width
		tabs_difference = Number(tabs_table_width) - Number(tabs_width);
				
		//Divide the difference by the number of tabs
		tab_padding = tabs_difference / total;
		
		//Round DOWN to the nearest whole number - if you dont do this thing will balls up
		
		tab_padding = Math.floor(tab_padding);
		
		// This is the new width of all the tabs now we've rounded down
		
		adjustedwidth = tab_padding*total;
		
		// And this is the remaning pixels that we need to add on somewhere
		
		remainingbit = Number(tabs_table_width) - Number(tabs_width) - Number(adjustedwidth);
		
		// Now divide it by two so we can stick a bit on the start and a bit on the end
		
		remainingbit = remainingbit/2;
				
			//Loop through the tabs and apply the padding
			for (var i = 1; i < total+1; i++)
			{
				
				//If its the first tab then do this (same as others but can be changed if you need
				if (i == 1)
				{
					
					tabwidth = get_width("tab"+i);
					newwidth = tabwidth + tab_padding + remainingbit;
					document.getElementById("tab"+i).style.width = newwidth + "px";
										
				} 
				
				// On the very last tab, stick the tiny bit of remaning pixels from the rounding down
				else if (i == total) 
				
				{	
					tabwidth = get_width("tab"+i);
					newwidth = tabwidth + tab_padding + remainingbit;
					document.getElementById("tab"+i).style.width = newwidth + "px";
									
				} 
				
				else
				
				// All the ones in the middle
				{
				
					tabwidth = get_width("tab"+i);
					newwidth = tabwidth + tab_padding;
					document.getElementById("tab"+i).style.width = newwidth + "px";
							
				}
				
			
		}
		

 }
