$(document).ready(function() { 	
	$('.thewire-post').mouseover(function(){
		$(this).children('.thewire_options').show();
	});
	$('.thewire-post').mouseout(function(){
		$(this).children('.thewire_options').hide();
	});

	var options = {
			target:        	"#thewire_post_new",
			//clearForm: 		true,
			beforeSubmit:  	showRequest,
			success:       	showResponse  
	};
	
	$('#vazco_thewire_form').ajaxForm(options);
	
	function showRequest(formData, jqForm, options) {
		$('#thewire_post_prev').html($('#thewire_post_new').html() + $('#thewire_post_prev').html());
		$('#thewire_post_new').html('');
	}
		
	function showResponse(responseText, statusText, xhr, $form)  {
		$('#thewire_large-textarea').val('');
		$('.thewire_characters_remaining_field').val('140');
		
		$('.thewire-post').mouseover(function(){
			$(this).children('.thewire_options').show();
		});
		$('.thewire-post').mouseout(function(){
			$(this).children('.thewire_options').hide();
		});
		
		$('.thewire_message').fadeOut(5000);
		$('.thewire_error').fadeOut(5000); 
	}
	
	$('.thewire_addbutton a').live('click',function() {
		
		$('#thewire_list').load(this.href,function() {
			$('.thewire-post').mouseover(function(){ 
				$(this).children('.thewire_options').show(); 
			}); 
			
			$('.thewire-post').mouseout(function(){ 
				$(this).children('.thewire_options').hide(); 
			});
		});
		var start = this.href.search(/&limit=[\d]+/);
		var end = this.href.indexOf('callback');
		var value = this.href.substring(start+7,end-1);
		this.href = this.href.replace(/&limit=[\d]+/,"&limit="+(parseInt(value)+10));
		
		return false;
	});
	
});