var Countdown = {
	seconds: 0,
	interval: null,

	init: function() {
		this.seconds = next;

		if (this.seconds == 0)
		{
			return false;
		}

		this.timer();
		this.interval = setInterval(this.timer, 1000);
	},

	timer: function() {
		Countdown.seconds--;

		if (Countdown.seconds == -1)
		{
			clearInterval(Countdown.interval);
			if (confirm('Um novo jogo foi adicionado! Deseja ir jogá-lo?'))
			{
				document.location = '/ultimo-jogo/';
			}
		}
		else
		{
			Countdown.display();
		}
	},

	display: function() {
		var ms = Countdown.seconds;

		var h = Math.floor(ms / 3600);
		ms -= h * 3600;

		var m = Math.floor(ms / 60);
		ms -= m * 60;

		var s = ms;

		var text = this.zero(h) + 'h ' + this.zero(m) + 'm ' + this.zero(s) + 's';

		$('#countdown').html('<b>' + text + '</b>');
	},

	zero: function(num) {
		return (num < 10 ? '0' + num.toString() : num.toString());
	}
};

$(document).ready(function(){
	Countdown.init();

	$('#busca input').bind('focus', function(){if ($(this).val() == 'Buscar...'){$(this).val('');}}).bind('blur', function(){if ($(this).val() == ''){$(this).val('Buscar...');}});
});