$(document).ready(function(){

//*** menu lingua

	$("#menu-lang a").click(function(event) {
		event.preventDefault();
		
		$("#menu-logo").removeClass('pginicial');
		
		var $idioma = "#menu-"+$(this).attr("value");

		$("#menu-lang").css({"display": "none"});
		$($idioma).fadeIn("slow");
		$('body').data('idioma', $(this).attr("value"));
		
		// chama o div de noticia depois da escolha do idioma
		postArtigo(4,$('body').data('idioma'));
	});

//*** menu principal no idioma escolhido ## $('body').data ('idioma') ##
	
	$("#menu-main div a").click(function(event) {
		event.preventDefault();
		
		$("#menu").removeClass('pg-interna');
		// limpa container e esconde botoes
		$("#container").html(' ');
		$("#the-background").fadeIn(500);
		$("#btn-ant").addClass('esconde');
		$("#btn-prox").addClass('esconde');
		
		var $sec_categoria = $(this).attr('value');
		var $sec_idioma = $('body').data('idioma');
		
		if ($sec_categoria ==3 || $sec_categoria==4 || $sec_categoria==6){
			postArtigo($sec_categoria,$sec_idioma);
		} else if ($sec_categoria ==1 || $sec_categoria==2){
			postProjeto($sec_categoria,'ano',$sec_idioma);	
		};
		if ($sec_categoria ==5){
			postContato($sec_categoria,$sec_idioma);
		};

		// muda cor do menu
		if ($sec_categoria ==2){
			$('#menu').css("background-image","url(img/compgraf_bg.png)");
		} else {
			$('#menu').css("background-image","url(img/arquitetura_bg.png)");
		};	

	});	

	
//*** menu itens projetos 

	$("#listagem DIV a").live('mouseover mouseout', function(event) {
	  if (event.type == 'mouseover') {
		$(this).addClass("hover");
	  } else {
		$(this).removeClass("hover");
	  }
	});		
		
	$("#listagem DIV a").live('click', function(event) {
		event.preventDefault();
		var listaItem = "";
		var currItem = $(this).attr('value');
		var indexItem = 0;
		var posItem = 0;
		
		$("#listagem DIV a.selecionado").each( function (){
			listaItem += $(this).attr('value')+",";
			if($(this).attr('value') == currItem) {posItem=indexItem};
			indexItem++;
		});
		
		listaItem = listaItem.substring(0,listaItem.length-1);
		
		//testa link (highlight) e envia [array dos selecionados / indice do trabalho clicado]
		if ($(this).hasClass('selecionado')) { geraItem (listaItem,posItem);};

	});
	
	
	$("#menu-logo").toggle(
		function () {
			if($(this).hasClass('pginicial')){
				minMenu();
				return false;
			} else {
				window.location.href = '';
			}
		},
		function () {
			if($(this).hasClass('pginicial')){
				maxMenu();
				return false;
			} else {
				window.location.href = '';
			}
		}
	);
	

	$("#menu.pg-interna").live('mouseleave', function(){
		minMenu();
		return false;
	});	

	$("#menu.pg-interna").live('mouseenter', function(){
		maxMenu();
		return false;
	});	
	
//*** MENU MAXIMIZA E MINIMIZA

	var minMenu = function() {
		$("#menu").animate({'width': '150', 'height':'75'},200);
	}

	var maxMenu = function() { 
		$("#menu").css({'width':'', 'height':''});
	}
	
});
