(function($){
	$.fn.twLine = function(options){ 
		var c = $.extend({
			user: null,
			number: 10
		},options || {});
		$(this).each(function(){
			var self = $(this);
 
			if(!c.user){
				return false;
			}
	 
			self.append(
				'<div class="loading"><img src="img/loading.gif" width="32" height="32" alt="" />loading...</div>',
				'<ul/>'
			);
				
			$.getJSON('http://twitter.com/statuses/user_timeline/' + c.user +'.json?callback=?',function(data){  
				$('.loading', self).remove();
					
				if( data.length < 1 ) {
					$('ul', self).append('<li>投稿がありません。</li>');
					return false;
				}
								
				$.each(data , function(i , items) {
					if( i > (c.number - 1) ) {
						return false;
					}
					if(items.in_reply_to_status_id > 0){
						return true;
					}
					var timestr = items.created_at;
					var timevl = new Date();
					if(/MSIE/.test(navigator.userAgent)){
						var timestr2 = timestr.slice(0,timestr.length-10) + 'UTC' + timestr.slice(timestr.length-10,timestr.length);
						timevl.setTime(Date.parse(timestr2));
						timestr = '（' + (timevl.getYear()) +'年'+ (timevl.getMonth()+1) +'月'+ timevl.getDate() +'日'+ timevl.getHours() +':'+ timevl.getMinutes() +':'+ timevl.getSeconds()+'）';
					}
					else{
						timevl.setTime(Date.parse(timestr));
						timestr = '（' + (timevl.getYear()+1900) +'年'+ (timevl.getMonth()+1) +'月'+ timevl.getDate() +'日'+ timevl.getHours() +':'+ timevl.getMinutes() +':'+ timevl.getSeconds()+'）';
					}
					$('ul', self).append(
						$('<li/>',{
							text:items.text+timestr
						})
					);
				});
			});
		});
	}
})(jQuery);

function twit_load(){
	$('#news').twLine({
		user: 'futribe',
		number: 5
	});
	return false;
}


function addLoadEvent(func)
{	
	if(typeof window.addEventListener == 'function'){
		window.addEventListener('load', func, false);
		return true;
	}
	else if(typeof window.attachEvent == 'object'){
		window.attachEvent('onload', func);
		return true;
	}
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}

addLoadEvent(twit_load);	// run gmap_load onLoad

