$(function() {
	function resetThings(){
		$(".process").css({"background": "red"});
	}

	var urlBox = $('#theLink').val(),
		submitB = $('#submit');
	$('#theLink').focus(function(){
		if( $(this).val() == urlBox ){
			$(this).val("http://");
		}
	});
	
$('#linkForm').submit(function(){
	resetThings();
	submitB.fadeOut();	
	$('.processingC').html('Shrinking your URL...');
	$('.process').animate({"height": "50px"}, 500);
	
	$.ajax({
		type: 'post',
		dataType: 'json', // more info
		url: 'files/process/add.php', // hello
		data: 'theLink=' + $('#theLink').val(),
		success: function(e){
			if(e.error == true){
				$('.processingC').html(e.message);
				submitB.fadeIn();
				$('.process').animate({"height": "50px"}, 3500).animate({"height": "0px"}, 1000);
			}else{
				$('.processingC').html(e.message);
				$('.process').css({"background": "green"}).animate({"height": "50px"}, 3500).animate({"height": "0px"}, 1000);
				$('#theLink').val(e.shortURL);
				$('.postTo').fadeIn().animate({"marginLeft": "255px"}, 200);
				// change the size of the textbox
				$("#theLink").animate({"width": "450px"})
				
				// set the buttons
				$('.postTo .tweetie a').attr({"href": "javascript:window.location='tweetie:'+'" + e.shortURL + "' "});
				$('.postTo .twitter a').attr({"href": "http://twitter.com/?status=" + e.shortURL + " "});
				$('.postTo .facebook a').attr({"href": "http://facebook.com/sharer.php?u=" + e.shortURL + " "});
			}
		}
	});
		
		$(this).ajaxError(function(){
			alert("THERE WAS AN AJAX ERROR, SORRY ABOUT THAT");
		});
		return false;
});
	
	
	
});
