var TabManager = new Class({
	Implements: [Options, Events, Log],
	
	options: {
		selectedIndex: 0
	},
	
	// Variables
	tabs: [],
	selectedTab: null,
	
	initialize: function(tabsInfo, options)
	{
		this.enableLog();
		//this.disableLog();
		this.log("TabManager::initialize(" + tabsInfo + ", " + options + ")");
		
		this.setOptions(options);

		// Create tabs
		this.createTabs(tabsInfo);
		
		this.show(tabsInfo[this.options.selectedIndex].name);
	},
	
	show: function(name)
	{
		this.log("TabManager::show(" + name + ")");
		
		if(this.selectedTab != name)
		{
			this.selectedTab = name;
			
			// Hide all other tabs
			this.hideTabs();
		
			// Show clicked tab
			this.tabs.each(function(tab){
				
				if(name == tab.name)
				{
					tab.show();
				} 
				
			}.bind(this));
		}
		
	},
	
	hideTabs: function()
	{
		this.log("TabManager::hideTabs()");
		
		this.tabs.each(function(tab){
			tab.hide();
		}.bind(this));
	},
		
	createTabs: function(tabsInfo)
	{
		this.log("TabManager::createTabs(" + tabsInfo + ")");

		tabsInfo.each(function(info) {
			this.addTab(info);
		}.bind(this));

	},
	
	addTab: function(info)
	{
		this.log("TabManager::addTab(" + info + ")");
		
		var name = info.name;
		var tab = info.tab;
		var content = info.content;
		
		var tab = new Tab(this, name, tab, content);
		
		this.tabs.include(tab);
	}
	
});
