$(function() {
	//IE対策
	function replaceTwTimeStr(time){
		var tArray = time.split(" ");
		var timeStr = tArray[0] + " " + tArray[1] + " " + tArray[2] + " " + tArray[5] + " " + tArray[3] + " " + tArray[4];
		return timeStr;
	}
	var dateObj = new Date;
	$.getJSON('http://twitter.com/statuses/user_timeline/UTpkai.json', function (json) {
		var j = 0;
		for(var i in json){
			var text = json[i].text;
			if (text.indexOf('#notice')!=-1) {
				text = text.replace('#notice','');
				text = text.replace(/(s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:@&=+$,%#]+)/gi,'<a href="$1">$1</a>');
				text = text.replace(/#(\w+)/gi,'<a href="http://twitter.com/search?q=%23$1">#$1</a>');
				text = text.replace(/@(\w+)/gi,'<a href="http://twitter.com/$1">@$1</a>');
				title = text.slice(1,text.indexOf("]"));
				text = text.slice(title.length+2);
				$("#twitter dl").append("<dt>" + title + "</dt><dd>" + text + "(" + dateObj.format('Y/m/d H:i', replaceTwTimeStr(json[i].created_at)) + ")</dd>");
				if (++j>=3) break;
			}
		}
		$("#twitter").prepend('Twitter <a href="https://twitter.com/UTpkai">@UTpkai</a> よりお知らせを抜粋。最新のお知らせを'+j+'件表示しています。<br>');
	});
});
