$(document).ready(function(){
	//Java script is enabled so show the tab row
	
	//hide each of the tabs
	var i = 0;
	var tabs = $(".tabpanel");
	var numTabs = tabs.size();
	var width = (100 / numTabs);
	tabs.each(function(){
		//first tab is active
		if(i != 0){
			$(this).hide();
		}
		
		//move the title into the tab row
		
		var title = '';
		$(this).children(".title").each(function(){
			title = $(this).text();
			$(this).remove();	
		});	
		
		//first tab is active
		var cls = '';
		if(i == 0){
			cls = "activelink";
		}

		//add a tab header in the tab row.
		$('#tabrow').append('<td class="relatedcolumn" width="'+width+'%"><div name="'+$(this).attr("id")+'" class="relatednav"><span class="'+cls+'"><a href="#">'+title+'</a></div></td>');

		i++;		
	});	
	
	$(".relatednav").click(function(){
		//turn all tabs inactive
		$(".relatednav span").each(function(){
			$(this).removeClass('activelink');
		});			
		$(".tabpanel").each(function(){
			$(this).slideUp('slow');
		});
		
		//make this tab active
		$(this).children("span").addClass('activelink');
		var panelId = $(this).attr("name");
		$('#'+panelId).slideDown('slow');

		return false;
	});	
});
