$(document).ready(function(){
	
	//	Randomize Posts
		var posts = $('.user');
		$('#posts').html(posts.sort(function() {return 0.5 - Math.random()}));
	
		var i = 1;
		$('#posts .user').each(function(){
			if(i > 13) {
				$(this).addClass('flip');
				if(i >= 18){
					i = 1;
				} else {
					i++;
				}
			} else {
				i++;
			}
		})
	
		$('#posts .text').hide();
		$('#posts .user').hover(function(e){
			$(this).css({"z-index" : 10}).find('.text').fadeIn('fast');
		}, function(){
			$(this).css({"z-index" : 0}).find('.text').hide();
		})
		
	//	Admin AJAX
		$('#admin #twitterblacklist form').live('submit', function(){
			var form = $(this);
			$.post(form.attr('action'), form.serialize(), function(){
				$('#remove_set').load('/~iread/admin #remove_set', function(){
					form.find('#twitter_username').val('');
				});
				
			});
			return false;
		})
		
		$('#admin .post .delete').click(function(){
			var link = this;
			$.get(link.href, function(){
				$(link).parent().fadeOut('slow');
			})
			return false;
		})
	
	//	Twitter Button
		$('#say_it_on_twitter').click(function(e){
			if($('#postcontent').val() != 'I read the newspaper because...'){
				this.href = "http://twitter.com/home?status=" + escape($('#postcontent').val().substr(0, 100) + " - ") + "http://ireadlouisiana.com %23iread";
			}
		})
		
	//	Spam check
		$('#createform #submit').click(function(){
			if($('#antispam').val() != $('#antispam_answer').val()){
				alert('To make sure that you\'re not a robot, we need to accurately answer the math problem below. Your answer was incorrect. Please try again.');
				return false;
			}
		})
})
