Player = {
	timeoutInMillisecs: 5000,
	startUpdatingCaption: function() {
		this.captionUpdateHref = $('caption-update-link').href;
		this.captionId = 0;
		//setInterval(this.sendCaptionRequest.bind(this), 1000);
	},
	sendCaptionRequest: function() {
		if (this.request && !this.request._complete) return;
		this.request = new Ajax.Request(this.captionUpdateHref+'/captionId/'+this.captionId, {
			onSuccess: this.updateCaption.bind(this),
			on304: this.clearTimeout.bind(this)
		});
		this.timeout = setTimeout(this.abort.bind(this), this.timeoutInMillisecs);
	},
	
	abort: function() {
		this.clearTimeout.bind(this)
		this.request = null;		
	},
	
	updateCaption: function(response) {
		response = response.responseJSON;	
		player.sendToAs(response.captions[0], response.captions[1]);
		
		this.captionId = response.captionId;
		
		this.clearTimeout();
	},
	clearTimeout: function() {
		if (this.timeout) clearTimeout(this.timeout);
	}
}

function clear_text() {
	$('text').value = '';
}

function set_name() {
	$('name').value = $('user_name').innerHTML;
}

function timer(dur,id) {
  //setTimeout("setEmpty(id)",dur);
	alert("hello");
}

function setEmpty(id){
	new Ajax.Request('/caption/set?type=title&t1=&playerId='+id , {asynchronous:true, evalScripts:false, method:"get"});	
}



