/**
 * @class Roo.gui.HeaderTabs
 * @extends Ext.TabPanel
 *
 * The HeaderTabs are at the top of the application, providing a switch between the functionality.
 * In reality only a row of tabs without content, other parts are listening to events fired from this component.
 *
 * @author ssmeman
 * @version 1.0
 */

/**
 * @constructor
 * @param {Object} config Configuration options
 */
Roo.gui.HeaderTabs = Ext.extend(Ext.TabPanel, {

	//soft config (can be changed from outside)
	id : 'headerTabs'
	,tabWidth : 180
	,resizeTabs : true

	,constructor : function(config) {
		// constructor pre-processing - configure listeners here
		config = config || {};
		config.listeners = config.listeners || {};

		Ext.applyIf(config.listeners, {
			beforetabchange : {scope : this, fn : function(tabpanel, newTab, currentTab) {
				if (newTab.id == 'uitleg' && Roo.flamingoInitialized) {
					if (window.location.href.indexOf('?') > 0) {
						window.location.href = window.location.href.substring(0, window.location.href.indexOf('?'));
					} else {
						window.location.href = window.location.href;
					}
				}
			}}
			,tabchange : {scope : this, fn : function(tabpanel, activeTab) {
				var lastFilterName = Roo.currentTabFilter.name;

				switch (activeTab.id) {
				case 'uitleg' :
					Roo.currentTabFilter = { name : 'NONE' };
					break;
				case 'juridisch' :
					var showOntwerp = (Ext.getCmp('designCheckbox')).getValue();
					if(showOntwerp) {
						Roo.currentTabFilter = { name : 'ACTUEEL' };
					} else {
						Roo.currentTabFilter = { name : 'JURIDISCH' };
					}
					break;
				case 'visie' :
					Roo.currentTabFilter = { name : 'VISIE' };
					break;
				case 'instructie' :
					Roo.currentTabFilter = { name : 'INSTRUCTIE' };
					break;
				}

				Roo.currentTabTitle = activeTab.title;
				console.info("Application.tabPanel.listeners(): panel title set to: %s", Roo.currentTabTitle);

				if (activeTab.id == 'uitleg') {
					// fire changeCard event to change to uitleg, only reset flamingo State in FF
					if (Ext.isGecko) {
						Roo.flamingoInitialized = false;
						nrConfigsComplete = 0;
					}
					tabpanel.fireEvent('changedCard', { 'id' : 'uitleg' });
				} else {
					// fire changeCard event to change to main
					tabpanel.fireEvent('changedCard', { 'id' : 'main' });

					if(lastFilterName !== 'NONE') {
						// only fire this event, if we're not coming from the "homepage", because then it's fired from onFlamingoInitialized()
						tabpanel.fireEvent('changedFilter', {
							'filter' : Roo.currentTabFilter.name
							,'lastFilterName' : lastFilterName
							,'panelTitle' : Roo.currentTabTitle
						});
					}
				}
			}}
		});

		// call parent contructor
		Roo.gui.HeaderTabs.superclass.constructor.apply(this, arguments);
	}

	,initComponent : function() {

		var config = {
			border : false
			,plain : true
			,activeTab : 'uitleg'

			,items : [{
				id : 'uitleg'
				,title : messages.application.uitleg.title()
				,tabTip : messages.application.uitleg.tabTip()
			},{
				id : 'juridisch'
				,title : messages.application.juridisch.title()
				,tabTip : messages.application.juridisch.tabTip()
			},{
				id : 'visie'
				,title : messages.application.visie.title()
				,tabTip : messages.application.visie.tabTip()
			},{
				id : 'instructie'
				,title : messages.application.instructie.title()
				,tabTip : messages.application.instructie.tabTip()
			}]

			,activateByTabFilter : function(tabFilter) {
				switch (tabFilter) {
					case 'JURIDISCH' :
						if (Roo.currentTabFilter.name != 'ACTUEEL') {
							this.activate('juridisch');
							(Ext.getCmp('designCheckbox')).setValue(false);
						}
						break;
					case 'ACTUEEL' :
						this.activate('juridisch');
						(Ext.getCmp('designCheckbox')).setValue(true);
						break;
					case 'VISIE' :
						this.activate('visie');
						break;
					case 'INSTRUCTIE' :
						this.activate('instructie');
						break;
				}
			}
		};

		// apply config
		Ext.apply(this, config);
		Ext.apply(this.initialConfig, config);

		// call parent
		Roo.gui.HeaderTabs.superclass.initComponent.apply(this, arguments);
	}
});

// register xtype
Ext.reg('headerTabs', Roo.gui.HeaderTabs);