function $(ini){
	return document.getElementById(ini);
}

var tOut = null;
var flag = 0;

window.onload = function(){
	showTopo();
	tOut = setTimeout(function(){hideTopo();}, 3000);
}

//Criar Objeto do ajax
function createRequest(){
	var request = null;
	try{
		request = new XMLHttpRequest();
	}catch(trymicrosoft){
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(othermicrosoft){
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(failed){
				request = null;
			}
		}
	}
	if(request == null){
		alert('Erro ao criar objeto de requisição!\nPor favor, reinicie o sistema. Se o erro persistir, entre em contato com o suporte.');
	}else{
		return request;
	}
}
	
function cadastra(nome,email){
	if(!nome || nome == "Nome"){
		alert('Nome não informado');
	}else if(!email || email == "Email"){
		alert('Email não informado');
	}else{
		var msg = createRequest();
		var url = "sendMail3.asp?nome=" + nome + "&email=" + email + "&date=" + new Date().getTime();
		msg.open("GET",url,true);
		msg.onreadystatechange = function(){
			if(msg.readyState == 4){
				if(msg.status == 200){
					alert(msg.responseText);
				}else{
					alert("Ocorreu um erro interno");
				}
			}
		}
		msg.send(null);
	}
}

function hideTopo(){
	if(flag == 1) fadeOut('menu');
	var t = setInterval(function(){ 
		var tamanho = parseInt($("barraTopo").style.top);
		tamanho = (!tamanho)? 0:tamanho;
		if(tamanho > -70){
			$("barraTopo").style.top = '0px';
		}else{
			flag = 0;
			clearInterval(t);
		}
	},1);
}

function showTopo(){
	var t = setInterval(function(){ 
		var tamanho = parseInt($("barraTopo").style.top);
		tamanho = (!tamanho && tamanho != 0)? -70:tamanho;
		if(tamanho < 0){
			$("barraTopo").style.top = '0px';
		}else{
			if(flag == 0) fadeIn('menu');
			flag = 1;
			clearInterval(t);
		}
	},1);
}

function fadeOut(ini){
/*
	var fadeIt = setInterval(function()
	{
		var opacityArrive = parseFloat($(ini).style.opacity);
		var newOpacity = opacityArrive - (0.1);
			
		if(opacityArrive > 0){
			$(ini).style.opacity = (newOpacity);
			$(ini).style.filter = 'alpha(opacity=' + (newOpacity * 100) + ')';
		}else{
			$(ini).style.opacity = 0;
			$(ini).style.filter = 'alpha(opacity=0)';
			clearInterval(fadeIt);
		}
	}
	,1);
*/
}

function fadeIn(ini){
/*
	$(ini).style.opacity = 0;
	$(ini).style.filter = 'alpha(opacity=0)';
	
	var fadeIt = setInterval(function()
	{
		var opacityArrive = parseFloat($(ini).style.opacity);
		var newOpacity = opacityArrive + (0.1);
			
		if(opacityArrive < 1){
			$(ini).style.opacity = (newOpacity);
			$(ini).style.filter = 'alpha(opacity=' + (newOpacity * 100) + ')';
		}else{
			$(ini).style.opacity = 1;
			$(ini).style.filter = 'alpha(opacity=100)';
			clearInterval(fadeIt);
		}
	}
	,1);
*/
}

