jQuery(document).ready(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);
	}			
			
	var url = "http://twitter.com/status/user_timeline/onestopwebshop.json?count=4&callback=?";

	$.getJSON(url, function(data){
	
		var htmlString = '';
		
	    $.each(data, function(i, item) {
	    
	    	// Re-format Date/Time
			//get Tweet date
			var tweetDate = item.created_at.substring(0,19);

			
			
			htmlString += '<ul>';
	    	htmlString += '<li><div class="tweet_info"><span>'+tweetDate+'</span></div><div class="tweet_content">'+item.text+'</div>';
	    	htmlString += '<div class="retweet_btn"><a target="_blank" href="http://twitter.com/#!/onestopwebshop">Lees meer &raquo;</a></div>';
	    	htmlString += '</li>';
	    	htmlString += '</ul>';

	    });
	    
	    $("#tweet_container").html(htmlString);    				
		$(".tweet_content").tweetify();

	});
	
});
