var loadAnimate = function(span) {
	span.css('backgroundPosition','-16px 0');
	span.animate({backgroundPosition: '220px 0'}, 3000,function(){
		if(span.height() > 0) {
			loadAnimate(span);
		}
	});
}

var limparCampo = function() { $("#fileInput").html($("#fileInput").html()); }

var upload = function() {
	if($("#upload").val().length > 0){
		var lis = $("#arquivos li").length + 1;
		if(lis == 1) { $("#arquivos").show(); }
		$("#arquivos").append('<li id="arq'+lis+'">Enviando arquivo...<span></span><iframe id="ifrmFile'+lis+'" name="ifrmFile'+lis+'" width="1" height="1"></iframe></li>');
		loadAnimate($("#arquivos #arq"+lis+" span"));
		$("#form_cadastre_seu_imovel").attr("action","fileup.php?id="+lis);
		$("#form_cadastre_seu_imovel").attr("target","ifrmFile"+lis);
		$("#form_cadastre_seu_imovel").submit();
		limparCampo();
	}
}

var enviado = function() {
	$("#arquivos li").each(function(){ $(this).remove(); });
	document.getElementById("form_cadastre_seu_imovel").reset();
	GB_showCenter("VOCÊ Consultoria Imobiliária!", "/includes/err.php?tipo=alert&err=Dados enviados com sucesso", 114, 362);
	parent.$(".gifload").hide();
}

var falha = function(msg) {
	GB_showCenter("VOCÊ Consultoria Imobiliária!", "/includes/err.php?tipo=alert&err="+msg, 114, 362);
	$(".gifload").hide();
}

$(function(){
	$("#bt_quero_cadastrar").click(function() {
		limparCampo();
		if(validaCadastro(document.getElementById("form_cadastre_seu_imovel"))) {
			$("#form_cadastre_seu_imovel").attr("action","envio.php");
			$("#form_cadastre_seu_imovel").attr("target","ifrmFile");
			$(".gifload").show();
			$("#form_cadastre_seu_imovel").submit();
		}
	});
	$("#fileSubmit").live('click',function(){ upload(); });
	$("#upload").live('change',function(){ upload(); });
	//$ ("#upload"). live('change', function () (alert ($ (this). Text ());));
	$("#arquivos .close").live('click',function(){
		$(this).parents("li").remove();
	});
});

