var serverPassword	= {
	
	init: function() {
		this.container	= $('serverPassword');
		this.request	= new Request.JSON({
			'url': '/cod-contest/password.php',
			'onSuccess': this.update.bind(this)
		});
		
		this.getStatus();
		this.timer	= this.getStatus.periodical(5000, this);
	},
	
	getStatus: function() {
		this.request.cancel();
		this.request.post();
	},
	
	update: function(obj) {
		this.container.empty();
		this.container.adopt( new Element('h2', {'text': obj.title, 'align': 'center'}) );
		
		if(obj.complete) {
			this.container.adopt( new Element('h3', {'text': obj.message, 'align': 'center'}) );
			$clear(this.timer);
		} else {
			this.container.adopt( new Element('p', {'text': obj.message, 'align': 'center'}) );
		}
	}
	
};

window.addEvent('domready', serverPassword.init.bind(serverPassword));