function tabNav(e)
{
	// Stop the click on the hyperlink from going anywhere
	Event.stop(e);
	
	// Use the href of the clicked link for id of tab to show
	var href = this.href;
	var contentToShowId = href.substring(href.search(/#/) + 1);
	
	// Find the current tab and remove the current flag
	$$('#tabs #tabnav li a.current').invoke('removeClassName', 'current');
	
	// Add the current flag to the list item which is the parent of the clicked link
	this.addClassName('current')
	
	var currentContent = $$('#tabs div.current').invoke('removeClassName', 'current');

	/*@cc_on
	/*@if (@_jscript_version < 5.7)
		$(currentContent[0].id).hide();
		$(contentToShowId).show();
	@else @*/
		new Effect.Fade(currentContent[0].id, {duration: 0.3});
		new Effect.Appear(contentToShowId, {queue: 'end', duration: 0.3});
	/*@end
	@*/

	$(contentToShowId).addClassName('current')
}

function resizeTabs()
{
	var tabs = $('tab_container');
	if(tabs)
	{
		var maxHeight = $$('#tabs .tab_body').invoke('show').invoke('getHeight').max();
		$$('#tabs .tab_body:not(.current)').invoke('hide');
		tabs.setStyle(
		{
			height: maxHeight + 'px'
		});
	}
}

document.observe('dom:loaded', function()
{	
	// Lower middle tab navigation
	if($('tabs'))
	{
		// Add extra elements for styles
		$$('#tabnav ul li a').each(function(a)
		{
			var wrapper = document.createElement('span');
			$(wrapper).update(a.innerHTML);
			a.replaceChild(wrapper, a.firstChild);
		});
		new Insertion.Bottom('tabnav', '<div><div></div></div>');
		
		// Setup event handlers
		$$('#tabs #tabnav li a').each(function(o)
		{
			Event.observe(o, 'click', tabNav.bindAsEventListener(o))
		});
		
		// Hide all but current tab body
		$$('#tabs div.tab_body:not(.current)').invoke('hide');
	}

});

