/**
 * @author normen
 */

alreadyInShowTab = false;

function showTab(newTabId)
{
	// return in case we're already fading
	if (alreadyInShowTab) {
		return;
	}

	// find current tab button
	var curButton = $('#pageNavigation li .active');
	var curTabId = parseInt(curButton.get(0).id.substr(6,10));
	
	// return if requested tab is already visible
	if (curTabId === newTabId) {
		return;
	}
	
	var newButton = $('#pageNavigation li #tabBtn' + newTabId);
	curButton.removeClass('active');
	newButton.addClass('active');
	
	alreadyInShowTab = true;
	
	tc = $('#tabContainer');
	curTab = $('#tabContent' + curTabId);
	newTab = $('#tabContent' + newTabId);
	
	// make current tab invisible
	curTab.animate({ opacity: 0 },'fast','',function(){
		// animate current tab's height to new tab's height
		tc.animate({ height: newTab.height() },'fast','',function() {
			curTab.hide();
			newTab.fadeIn('fast',function() {
				curTab.css('opacity',1);
				alreadyInShowTab = false;
			});
		});
	});
} 

