var AtendimentoButton = {
	initState: false,
	enabled: false,
	setState: function () {
		var ab = document.getElementById('atendimento-button');
		try { ab.className = "atendimento"+(this.enabled?"ES":"PT":"EN") "at-"+(this.enabled?"on":"off"); }
		catch(e) { }
	},
	interval: null,
	init: function() {
		try {
			var ab = document.getElementById('atendimento-button');
			var cn = ab.className;
			cn = cn.split(" ");
			cn = cn[1].split("-");
			//initState = (cn[1] == "on"?true:false);
			this.interval = setInterval("AtendimentoButton.check();",5000);
		} catch(e) {
			setTimeout("AtendimentoButton.init();",100);
		}
	},
	check: function() {
		try {
			new Ajax.Request('_atendimento.php',{
				method:'post',
				parameters:{"action":"quick-check"},
				onFailure: function(){ AtendimentoButton.off(); },
				onSuccess: function(transport){
					if (!transport.responseText.length) { AtendimentoButton.off(); return; }
					var c = parseInt(transport.responseText);
					if (c > 0) {
						AtendimentoButton.on();
					} else {
						AtendimentoButton.off();
					}					
					return;
				}
			});
		} catch(e) {
		}
	},
	on: function() {
		this.enabled = true;
		this.setState();
	},
	off: function() {
		this.enabled = false;
		this.setState();
	}
}
AtendimentoButton.init();