/* Start Jquery */
$(document).ready(function(){
		
		/* Faz preload da imagem de load */
		$.preloadImages("images/elementos/ajax-loader.gif");		
		
		/* Histórico */
		//$.history.init(carregaConteudo);
		
		/* Carrega Conteudo */
		$("a.interno").click(function(){
			var $load = $(this).attr("load");
			carregaConteudo($load);
			//var $load = $(this).attr("load").replace(/^.*#/, '');
			//var $load = $(this).attr("load");
			//$.history.load($load);
			return false;
		});
		
		/* Efeitos Ajax */
		$("div#Loading").ajaxStart(function(){
			$(this).fadeIn('slow');
			$("div#pageContent").fadeOut(1);
		});
		$("div#Loading").ajaxStop(function(){
			$(this).fadeOut('slow');
			$("div#pageContent").fadeIn('normal');
		});
		
		/* Histórico */
		$("a.historyBack").click(function(){
			historicoBack();
			return false;
		});
		

	
});
/* Carrega Topo */
function carregaTopo($pagina){
	$("#pageHeader").load("includes/topo.asp",{'paginaAtual' : $pagina});
}
/* Carrega Home */
function carregaHome(){
	//alert('AEEEE TIETEEEE');
}
/* Carrega Conteudo */
function carregaConteudo($pagina,$noadd){

	// Página Padrão
	if($pagina==null){ $pagina = "01_home"; }
	
	if($pagina!=null){
		$("div#pageContent").load("contents/"+$pagina+".asp")
		if(!$noadd){
			historicoAdd($pagina);
		}
	}
}

function popup(url,titulo,largura,altura){
	var pop=window.open(url, '', "status=no,resizable=no,left=150,top=150,width="+largura+",height="+altura+"");
	pop.focus();
}

function historicoAdd($valor){
	
	var $n = $('#hist input[name=history]').length;
	
	if($n >= 5){
		$('#hist input[name=history]:first').remove();
	}
	$('#hist').append('<input type="hidden" name="history" id="history" value="'+$valor+'"');	
}

function getHistorico(){
	$('#hist input[name=history]').each(function(){
		alert($(this).val())
	});
}

function historicoBack(){
	var $n = $('#hist input[name=history]').length;

	if($n >= 2){
		$lastHist = $($('#hist input[name=history]')[($n - 2)]);
		$load = $lastHist.val();
		$('#hist input:last').remove();		
		carregaConteudo($load,true);
	}
}

// Teclas
$(document).keydown(function(e){
	var t_back = 8;
	
	if(e.which == t_back){
		historicoBack();
	}
});