
// FUNÇÕES QUE PRECISAM DO DOCUMENTO PRONTO
$(function(){
	$("#filtroSegmento").change(function(){
		// PROCESSA O FILTRO
		$.post('portifolio/segmento/'+$(this).val(), false, getRetornoSegmento, "json");
		// O RETORNO FAZ O REDIRECIONAMENTO
	});
});
function getRetornoSegmento(data){
	if(data.rs == 'ok'){
		window.location = SITE_URL;
	}
}
/*
 *
 * Função PageLoad
 *
 * Esta função é chamada quando:
 *
 * 1. depois de chamar $.historyInit();
 * 2. depois de chamar $.historyLoad();
 * 3. com as ações Voltar e Próximo do navegador
 *
 */
function pageload(hash) {
	// REMOVE AS CLASSES QUE ESTIVEREM ATIVA
	$('.menu li').removeClass('current');
	window.scroll(0,0);
	var baseTitulo = 'dothCom Consultoria Digital';
	
	switch(hash)
	{
		case 'empresa':
			$('.load1').fadeIn();
			$('.menuEmpresa').addClass('current');
			$("#tooltips").load(SITE_URL+'/institucional/ver/'+hash,false,function(){ $('.load1').fadeOut(); });
			document.title = 'Empresa • '+baseTitulo;
		break;
		case 'solucoes':
			$('.load2').fadeIn();
			$('.menuSolucoes').addClass('current');
			$("#tooltips").load(SITE_URL+'/institucional/ver/'+hash,false,function(){ $('.load2').fadeOut(); });
			document.title = 'Soluções • '+baseTitulo;
		break;
		case 'http://blog.dothcom.net/':
			$('.load6').fadeIn();
			$('.menuBlog').addClass('current');
			parent.location = 'http://blog.dothcom.net/';
		break;
		case 'orcamento':
			$('.load3').fadeIn();
			$('.menuOrcamento').addClass('current');
			$("#tooltips").load(SITE_URL+'/'+hash,false,function(){ $('.load3').fadeOut(); });
			document.title = 'Faça seu Orçamento • '+baseTitulo;
		break;
		case 'trabalhe':
			$('.load4').fadeIn();
			$('.menuTrabalhe').addClass('current');
			$("#tooltips").load(SITE_URL+'/'+hash,false,function(){ $('.load4').fadeOut(); });
			document.title = 'Trabalhe Conosco • '+baseTitulo;
		break;
		case 'contato':
			$('.load5').fadeIn();
			$('.menuContato').addClass('current');
			$("#tooltips").load(SITE_URL+'/'+hash,false,function(){ $('.load5').fadeOut(); });
			document.title = 'Contato • '+baseTitulo;
		break;
		default:
			$("#tooltips").empty();
			document.title = baseTitulo;
	}
	return false;
}

$(document).ready(function(){
	// Inicializa o plugin jquery.history
	// O callback é chamado desde que exista o hash
	$.historyInit(pageload);
	
	// links que disparam o plugin history
	$(".menu li a, .fechar, .banner a[href^='#']").click(function(){
		// REMOVE TODAS AS CLASSES E ADICIONA AO ITEM CLICADO
		$('.menu li').removeClass('current');
		$(this).parent().addClass('current');
		
		// 
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');

		// chama nova página
		// a função pageload é chamada aqui
		$.historyLoad(hash);
		return false;
		
	});
});
