window.addEvent('domready', function(){
	acks.attempt( 20 );
});

function iniList(){
	$('closeList').addEvent('click', function(){ window.close(); });
	$$('.buttonsCell').forEach(function(cell){
		var id = cell.getElement('.callID').value;
		cell.getElements('INPUT[type=button]').forEach(function(btn){
			if( btn.disabled ) return;
			btn.addEvent('click', function(e){ xajax_takeCall( id ); });
		});
	});
	acks.attempt();
};

var acks = {
	to: null,
	attempt: function( to ){
		this.backupCall();
		setTimeout(this.call, to||1000);
	},
	backupCall: function(){
		var that = this;
		clearTimeout( this.to );
		this.to = setTimeout(function(){ that.attempt(); }, 5000);
	},
	call: function(){	/* noSS=true forces refresh */
		xajax_updateList();
	},
	ring: function(){
		$('incomingCallAudio').play();
	}
}