(function($) {
	$(document).ready(function () {

		$.fn.twitterpts = function(options){

			var options = jQuery.extend({
				username: 'sixfeetunderatl',
				total:2,
				date: false
			},options);


			return this.each(function() {

				var _this = $(this);


				$.ajax({
					url:"http://twitter.com/status/user_timeline/" + options.username + ".json?count=" + options.total,
					dataType: 'jsonp',
					erorr:function() {
						_this.prepend("<div class='twitter'>Please wait...</div>");
					},
					success:function(response) {
						var twitterLast = "<ul id='twitterLast'>";
						$.each(response, function(i, tweets) {
							var text = tweets.text.replace( /(http:\/\/(?:[^\s]{4,}))/, '<a href="$1" target="_blank">$1</a>' ).replace( /^(?:@([^ ]+))/, '<a href="http://twitter.com/$1" target="_blank">@$1</a>' );
							
								
							

						
								var time =  tweets.created_at;

								time = time.split(' ');
								// 0 - День недели
								// 1 - Месяц
								// 2 - Число в месяце
								// 3 - Время
								// 4 - Часовой пояс
								// 5 - Год
								
								// Формируем строку даты
								time = time[0] + ", " + time[1] + " " +time[2] + ", " + time[5] + " - " + time[3];
								
								twitterLast +="<li"+((i==0)?" class='latest'":"")+">" + "<span class='date'>"+time+"</span>";
								twitterLast += "<span class='twit'>"+text+"</span>";
								
								
								
							
							twitterLast +="</lii>";



						});
						twitterLast +="</ul>"
						_this.html(twitterLast);
						

					}

				});


			});

		};

	});
})(jQuery);
