/**
* -------------------------------------------------------------------------------
* @class Core
* 	Classe principal do site.
* -------------------------------------------------------------------------------
*/
var oCore = $extend(
	new Storage({
		initialTab: 0
	}), {
	
		init: function(){
			if($defined(arguments[0]))
				this.Store.load(arguments[0]);
			
			/** Inicializa as bordas arredondadas nos elementos simples. */
			Nifty('div.apoio div,div.page', 'big');
			Nifty('div.main', 'big tr tl');
			
			/** Inicializa as abas. */
			this.Tabs.init(this.Store.get('initialTab'));
			
			/** Estilo do menu lateral. */
			this.sidebarFix();
		},
		
		/**
		* Corrige o estilo do sidebar se o navegador for o IE (pois nenhuma das
		* versões lida bem com alinhamento vertical.
		*/
		sidebarFix: function(){
			if(!window.ie)
				return;
			
			$$('.bt-box').each(function(oElement){
				oElement.removeClass('bt-box').addClass('bt-box-ie');
			});
		}
		
	}
);

/**
* -------------------------------------------------------------------------------
* @class Tabs
* @extends Core
* 	Gernecia as abas do site.
* -------------------------------------------------------------------------------
*/
oCore.Tabs = $extend(
	new Storage({
		containerId: 'nav',
		tabId: 'tab-',
		selectedTabClassName: 'selected',
		selectedTab: null
	}), {
	
		init: function(){
			var iTab = $pick(arguments[0], 0);
			var sBrowser = null;
			
			if(window.ie)
				sBrowser = 'ie';
			else if(window.gecko)
				sBrowser = 'gecko';
			else
				sBrowser = 'others';
			
			$(this.Store.get('containerId')).addClass('nav-' + sBrowser);
			
			if(!$defined(this.Store.get('selectedTab')))
				this.select(iTab);
			
			return this;
		},
		
		select: function(){
			var iTab  = $pick(arguments[0], 0);
			var aTabs = $$('#' + this.Store.get('containerId') + ' li');
			
			if(0 == aTabs.length)
				return false;
			
			var sClassName	= this.Store.get('selectedTabClassName');
			var oElement	= null;
			
			aTabs.each(function(oElement){
				oElement.removeClass(sClassName);
			});
			
			if(0 == iTab){
				this.Store.replace('selectedTab', null);
				oElement = $(aTabs[0]);
			}
			else{
				this.Store.replace('selectedTab', iTab);
				oElement = $(this.Store.get('tabId') + iTab.toString());
			}
			
			return oElement.addClass(sClassName);
		}
		
	}
);

/**
* -------------------------------------------------------------------------------
* @class Util
* @extends Core
* 	Funções utilitárias de uso comum que não lidam com DOM ou Ajax.
* -------------------------------------------------------------------------------
*/
oCore.Util = {
	
	mapaLocalizacao: function(){
		window.open(getGlobal('enderecoNormal') + 'site/mapa/', 'Janela_Mapa', 'width=660, height=550');
	}
	
};