function loadTwitterTimeline() {
	$.ajax({
		url: 'http://twitter.kion.name',
		type: 'GET',
		success: function(res) {
			$(res.responseText).find('div.tweet').each(function(idx, tweet){
				var timestampHtml = '';
				if ($(tweet).text().substring(1, 2) != '@') {
					var $meta = $(tweet).find('p.meta');
					var timestamp = $meta.text().replace(/via.*/gi, '');
					$meta.remove();
					timestampHtml = '<div class="timestamp">' + timestamp + '</div>';
				}
				var picHtml = '';
				$(tweet).find('a.pic').each(function(idx, pic){
					var href = $(pic).attr('href');
					var $img = $(pic).find('img');
					var src = $img.attr('src').replace(/\.th\.jpg/gi, ':iphone');
					picHtml += '<div style="text-align:center;margin-top:10px;"><a target="_blank" href="' + href + '"><img src="' + src + '"></div>';
				});
				$(tweet).find('a.pic').each(function(idx, pic){
					$(pic).remove();
				});
				$(tweet).html(timestampHtml + $(tweet).html() + picHtml)
				$(tweet).appendTo($("#content"));
			});
			embedVideos();
		}
	});
}

function embedVideos() {
	$("a.link").longUrl({
		callback: function(href, long_url){
			if (long_url) {
				if (href.indexOf('http://t.co/') == 0 && (long_url.indexOf('http://j.mp/') == 0 || long_url.indexOf('http://bit.ly/') == 0)) {
					$(this).attr('href', long_url);
					this.longUrl({
						callback: function(href, long_url){
							if (long_url) {
								this.text(long_url);
								embedVideo(this, long_url);
							}
						}
					});
				} else {
					this.text(long_url);
					embedVideo(this, long_url);
				}
			}
		}
	});
}

function embedVideo(a, long_url) {
	if (long_url.indexOf('http://www.youtube.com/watch?v=') == 0) {
		var videoId = long_url.replace('http://www.youtube.com/watch?v=', '');
		var container = a.parent();
		var containerWidth = container.width();
		var videoWidth;
		var videoHeight;
		if (containerWidth > 1280) {
			videoWidth = 1280;
			videoHeight = 720;
		} else if (containerWidth > 853) {
			videoWidth = 853;
			videoHeight = 510;
		} else if (containerWidth > 640) {
			videoWidth = 640;
			videoHeight = 390;
		} else {
			videoWidth = 560;
			videoHeight = 345;
		}
		$('<div style="text-align:center;margin-top:10px;"><iframe width="' + videoWidth + '" height="' + videoHeight + '" src="http://www.youtube.com/embed/' + videoId + '" frameborder="0" allowfullscreen></iframe></div>').appendTo(container);
	}
}

