$(function(){

	$.fn.tweetify = function() {

		this.each(function() {

		    $(this).html(

		        $(this).html()
		            .replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a target="_blank" href="$1">$1</a>')
		            .replace(/(^|\s)#(\w+)/g,'$1<a target="_blank" href="http://search.twitter.com/search?q=%23$2">#$2</a>')
		            .replace(/(^|\s)@(\w+)/g,'$1<a target="_blank" href="http://twitter.com/$2">@$2</a>')

		    );

		});

		return $(this);

	}
	
	function twitter(tweetSize){
		
		var url = "http://api.twitter.com/1/statuses/user_timeline.json?user_id=46784174&include_rts=true&count="+tweetSize+"&callback=?"
	
		$.getJSON(url, function(data){
		
			var htmlString = '';
			
		    $.each(data, function(i, item) {
		    
		    	var tweetDate = item.created_at.substring(0,19);
		    
		    	htmlString += '<div class="tweet"><div class="tweet_info">'+tweetDate+'</div><div class="tweet_content">'+item.text+'</div>';
		    	htmlString += '</div>';
	
		    });
		    
		    $("#tweetwall_inside").html(htmlString);
		    				
			$(".tweet_content").tweetify();
	
		});
	
	}

	var tweetWall = "more";
	
	$("a.tweetsize").click(function(){
	
		if (tweetWall == "less"){
			
			$("#block").animate({"height":270}, 1000);
			$("a.tweetsize p").html("more tweets");
			tweetWall = "more";
		
		} else {
		
			$("#block").animate({"height":0}, 1000);
			$("a.tweetsize p").html("less tweets");
			tweetWall = "less";					
		
		}
	
	});
	
	$(function(){
	
		twitter(4);
	
	});	

});
