/**
* -------------------------------------------------------------------------------
* Core
* 	Classe principal do site
* -------------------------------------------------------------------------------
* Criado em....: 11/10/2007
* Alterado em..: -
* -------------------------------------------------------------------------------
* Changelog
* -------------------------------------------------------------------------------
*/

var Core = Class.create({
	
	initialize: function(){
		document.observe('contentloaded', (function(){
			/**
			* Redimensiona os elementos para ajustar a página
			*/
			this.resizePage();
			
			/**
			* Marca um item do menu
			*/
			this.selectMenuItem( (('undefined' != typeof _globalVars.itemSelecionado) ? _globalVars.itemSelecionado : 0) );
			
			/**
			* Ajusta os controle da pesquisa
			*/
			var sTextoPadraoPesquisar = 'Pesquisar...';
			
			$('q')
				.observe('focus', function(){
					if(sTextoPadraoPesquisar == $F(this))
						this.setStyle('color:#000;').value = '';
				})
				.observe('blur', function(){
					if($F(this).empty())
						this.setStyle('color:#BBB;').value = sTextoPadraoPesquisar;
				})
				.setStyle('color:#BBB;')
				.value = sTextoPadraoPesquisar;
			
			$('lupa').observe('click', function(oEvent){
				oEvent.stop();
				
				if(sTextoPadraoPesquisar == $F('q'))
					$('q').value = '';
				
				$('frmPesquisa').submit();
			});
		}).bind(this));
	},
	
	resizePage: function(){
		if( false === !!$('menu-principal') )
			return;
		
		var iHeight = 0;
		var iViewportHeight = document.viewport.getHeight();
		var hContainerDimensions = $('container').getDimensions();
		
		if( iViewportHeight <= hContainerDimensions.height )
			iHeight = $('conteudo').getHeight();
		else
			iHeight = (iViewportHeight - ($('topo').getHeight() + $('rodape').getHeight()));
		
		$('menu-principal').setStyle('height:' + iHeight.toString() + 'px;');
	},
	
	selectMenuItem: function(iItem){
		var aItens = $$('#menu-principal > a');
		
		if( true === !!aItens[iItem] )
			aItens[iItem].addClassName('selecionado');
	}
	
});

//-------------------------------------------------------------------------------
var oCore = new Core();
//-------------------------------------------------------------------------------
