var JSONMail = {
	opcoes: {
		metodo: 'post',
		url: 'index.php',
		quandidade: 0
	},

	dados: '{"tipo": "cliente"}',

	enviar: function(){
		if(arguments.length == 1) {
			var opcoes = arguments[0];
			this.opcoes.metodo = opcoes.metodo || this.opcoes.metodo;
			this.opcoes.url = opcoes.url || this.opcoes.url;
		}
		jQuery.ajax({
			url: JSONMail.opcoes.url,
			type: JSONMail.opcoes.metodo,
			data: "JSONMail="+JSONMail.dados,
			success: function(resposta) {
				try {
					if(resposta.length > 0) {
						var JM = jQuery.parseJSON(resposta).JSONMail;
						if(JM.quantidade > 0 && JM.recarregar) {
							JSONMail.opcoes.identificador = setTimeout("JSONMail.enviar()", parseInt(1000 * JM.atraso));
						}
					}
				} catch(e) {}
			}
		});
	}
}

// Verificando a existência de emails no servidor
JSONMail.enviar();
