/* Author: 

*/

var quotes = [
	'<p><strong>"So computers are tools of the devil?" thought Newt. He had no problem believing it. Computers had to be the tools of somebody, and all he knew for certain was that it definitely wasn\'t him.</strong></p><p>Neil Gaiman and Terry Pratchett, <em>Good Omens</em></p>',
	'<p><strong>It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience.</strong></p><p>Albert Einstein</p>',
	"<p><strong>Now, you listen here: 'e's not the Messiah, 'e's a very naughty boy! Now, go away!</strong></p>",
	"<p><strong>It's every man's right to have babies if he wants them.</strong></p><p>Stan, <em>Monty Python's Life of Brian</em></p>",
	'<p><strong>Many forms of Government have been tried, and will be tried in this world of sin and woe. No one pretends that democracy is perfect or all-wise. Indeed, it has been said that democracy is the worst form of government except all those other forms that have been tried from time to time.</strong></p><p>Winston Churchill</p>',
	'<p><strong>All animals are equal, but some animals are more equal than others.</strong></p><p>George Orwell, <em>Animal Farm</em></p>',
	'<p><strong>Any society that would give up a little liberty to gain a little security will deserve neither and lose both.</strong></p><p>Benjamin Franklin</p>',
	'<p><strong>Bureaucracy expands to meet the needs of the expanding bureaucracy.</strong></p><p>Oscar Wilde</p>',
	'<p><strong>The Net interprets censorship as damage and routes around it.</strong></p><p>John Gilmore</p>',
	'<p><strong>In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.</strong></p><p>Douglas Adams, <em>The Restaurant at the End of the Universe</em></p>',
	'<p><strong>Beep... beep... beep... beep...</strong></p>'
];

var shuffle = function (o) { //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};

var random = function(o) {
	return o[parseInt(Math.random() * o.length)];
};

$(function() {
	var colors = [
			'#E8CDDB',
			'#FFE1E2',
			'#E1CDE8',
			'#F0E1FF'
		],
		blocks = shuffle($.makeArray($('.block:parent'))),
		empty = $('.block:empty'),
		intrvl;
	$.each(blocks, function (i, b) {
		var $b = $(b);
		$b.data('html', $b.html());
		$b.html('');
	});
	var cb = function () {
		var block;
		if (blocks.length == 0) {
			clearInterval(intrvl);
			return;
		}
		block = $(blocks.pop()).addClass('flip');
		setTimeout(function () {
			block.html(block.data('html'));
		}, 500);
	};
	intrvl = setInterval(cb, 500);
	empty.click(function () {
		var $b = $(this);
		if ($b.is(':empty')) {
			$b.addClass('flip');
			setTimeout(function () {
				$b.html(random(quotes)).css('background-color', random(colors));
			}, 500);
		} else {
			$b.removeClass('flip');
			setTimeout(function () {
				$b.text('');
			}, 500);
		}
	});
});

