$(document).ready(function(){
        jQuery.each(
		$("#sitio #cabecalho #menu a").get(),
		function(){
			$(this).click(function(){
				carregaPagina($(this).attr("href"));
				return false;
			});
		}
	);

        //Alterna a imagem de fundo do site
		loopTrocaFundo();
		setInterval(loopTrocaFundo,300000); //5 minutos
});

function imgDown(idImg){
	$("#" + idImg).attr({src: "imagens/marcadorDown.gif"});
}

function imgUp(idImg){
	$("#" + idImg).attr({src: "imagens/marcadorUp.gif"});
}

function carregaPagina(urlPath){
    encolherPagina();
	carregaPaginaParaId(urlPath, "#conteudo");
}

function carregaPaginaParaId(urlPath, idName){
	//Ajax Load
	$.ajax({
		url: urlPath,
		dateType: "html",
		type: "GET",
		cache: false,
		beforeSend: function(){
			//$(idName).html("<p align='center'><img src='imagens/load.gif' /></p>");
			$(idName).load("load.htm");
		},
		error: function(){
			$("#conteudo").load("erro.htm");
		},
		success: function(html){
			$(idName).html(html);
		}
	});
}

function encolherPagina(){
	var tempo = 500;
	
	$("#sitio #cabecalho #menu").animate({
		height: "95px"
	}, tempo);
	
	$("#sitio #cabecalho #logo").animate({
		height: "100px"
	}, tempo);
	
	$("#sitio #cabecalho").animate({
		height: "100px"		
	}, tempo);
}

function trocaImagem(objLink, idImgDest){
	origem = $(objLink).attr("href");
	
	$("#" + idImgDest).attr("src", origem);
}

//Preload de imagens
jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}

//Alterna a imagem do fundo a cada 1 minuto com uma função de random.
function loopTrocaFundo(){
    var numLow = 1;  //Número da primeira imagem
    var numHigh = 3; //Total de imagens de fundo da tela inicial em imagens/fundo/*.jpg
        
    var adjustedHigh = (parseFloat(numHigh) - parseFloat(numLow)) + 1;
        
    var numRand = Math.floor(Math.random()*adjustedHigh) + parseFloat(numLow);

    $("#sitio #conteudo").css("background-image", "url(imagens/fundo/" + numRand + ".jpg)");

    //alert(numRand);	
	//setTimeout(loopTrocaFundo, 300000); //5 minutos
}

