// JavaScript Document
function TabsManager(el)
{
	this.container = $('#'+el);
	this.current = 0;
	
	if ( !this.container ) return false;
}

TabsManager.prototype = {
	
	show:function( index )
	{
		var tabContent = $('#tabContent'+index);
		var currentContent = $('#tabContent'+this.current);
		
		if ( !tabContent ) return false;
		if ( tabContent.css('display') != 'none' ) return true;
		
		if ( index != this.current )
		{
			/*currentContent.fadeOut("fast", 
									function() { tabContent.fadeIn('fast') }
								   );*/
			currentContent.css('display', 'none');
			tabContent.css('display', '');
		}
		else /*tabContent.fadeIn('fast');*/ tabContent.css('display', '');
		
		this.setCurrent(index);
	},
	
	setCurrent:function( tab_index )
	{
		// Set current
		this.current = tab_index;
		// Clear styles and mark new tab as current
		var links = $('#'+this.container.attr('id')+' a');
		for( i = 0; i < links.length; i++ )
		{
			if ( i == (tab_index - 1) ) 
			{	
				// Styles
				$(links[i]).addClass('current');
				$(links[i]).blur();
			}
			else $(links[i]).removeClass('current');
		}	
	}
}

$(document).ready(
	function(){
		window.tabs = new TabsManager('tabs');
		if ( $('#tabContent0') != 'undefined' )
		{	
			window.tabs.show(0); // pre-select first tab
			window.tabs.setCurrent(0);
		}
		else
		{
			window.tabs.show(1); // pre-select first tab
			window.tabs.setCurrent(1);
		}
   }
);