function mysql_time(time_value){
	var d = new Date(time_value);
	var retValue = d.getFullYear()+"-";
	if(d.getMonth() < 10)
	{
		var mon = d.getMonth() + 1;
		retValue += "0" + mon;
	}
	else
	{
		retValue += d.getMonth() + 1;
	}
	retValue += "-";
	if(d.getDate() < 10)
	{
		retValue += "0" + d.getDate();
	}
	else
	{
		retValue += d.getDate();
	}
	retValue += " ";
	if(d.getHours() < 10)
	{
		retValue += "0" + d.getHours();
	}
	else
	{
		retValue += d.getHours();
	}
	retValue += ":";
	if(d.getMinutes() < 10)
	{
		retValue += "0" + d.getMinutes();
	}
	else
	{
		retValue += d.getMinutes();
	}
	retValue += ":";
	if(d.getSeconds() < 10)
	{
		retValue += "0" + d.getSeconds();
	}
	else
	{
		retValue += d.getSeconds();
	}
	
	return retValue;
}

function relative_time(time_value){
	if(time_value.indexOf("UTC") < 0) time_value = time_value.replace("+","UTC+");
	var parsed_date = Date.parse(time_value);
	var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
	var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);

	if(delta < 60) {
		return '1分以内';
	} else if(delta < 120) {
		return '2分以内';
	} else if(delta < (45*60)) {
		return (parseInt(delta / 60)).toString() + '分前';
	} else if(delta < (90*60)) {
		return '1時間以内';
	} else if(delta < (24*60*60)) {
		return (parseInt(delta / 3600)).toString() + '時間前';
	} else if(delta < (48*60*60)) {
		return '1日前';
	} else {
		return (parseInt(delta / 86400)).toString() + '日前';
	}
}
function delta_time(time_value){
	var d = new Date();
	d.setFullYear(parseInt(time_value.substring(0,4)));
	d.setMonth(parseInt(time_value.substring(5,7))-1);
	d.setDate(parseInt(time_value.substring(8,10)));
	d.setHours(parseInt(time_value.substring(11,13)));
	d.setMinutes(parseInt(time_value.substring(14,16)));
	d.setSeconds(parseInt(time_value.substring(17,19)));

	var parsed_date = d.getTime();
	var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
	var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);

	return delta;
}

function SetWndSize(barW,barH) {
		bar_w = barW;
		bar_h = barH;

    var nIE = navigator.userAgent.indexOf("MSIE");
    var bIE6std = nIE >= 0 && navigator.userAgent.substr(nIE+5, 1) == "6" 
                && document.compatMode && document.compatMode=="CSS1Compat";

    var nWidth, nHeight;
    if (bIE6std) {/* IE6スタンダードモードの時 */
        nWidth = document.documentElement.clientWidth;
        nHeight = document.documentElement.clientHeight;
		    document.getElementById('eegFrame').style.height=(nHeight-(barH))+'px';
		    document.getElementById('bar2').style.height=(nHeight-(barH))+'px';
		    document.getElementById('eegFrame').style.width=(nWidth-(barW))+'px';
    } else if (nIE >= 0) {
        nWidth = document.body.clientWidth;
        nHeight = document.body.clientHeight;
		    document.getElementById('eegFrame').style.height=(nHeight-(barH)-40)+'px';
		    document.getElementById('bar2').style.height=(nHeight-(barH)-40)+'px';
		    document.getElementById('eegFrame').style.width=(nWidth-(barW))+'px';
    } else {
        nWidth = window.innerWidth;
        nHeight = window.innerHeight;
		    document.getElementById('bar2').style.height=(nHeight-(barH))+'px';
		    document.getElementById('eegFrame').style.height=(nHeight-barH)+'px';
		    document.getElementById('eegFrame').style.width=(nWidth-barW)+'px';
    }
}

var lastMenu = 0;
var menuMax = 7;
var menuList = new Array();
menuList[0] = '';
menuList[1] = 'twitterに投稿';
menuList[2] = 'コメントを見る';
menuList[3] = '';
menuList[4] = '';
menuList[5] = '';
var bar_w = 20;
var bar_h = 40;
var listsCreate = 0;

function ToggleSub(id)
{
	if( (id == 2) && (timer == '') && (id != lastMenu) )
	{
		timer = setTimeout(onReloadComment, 1000);
	}
	else if( (id == 2) && (timer != '') && (id == lastMenu) )
	{
		clearTimeout(timer);
		timer = '';
	}

	if( (id == 3) && (id != lastMenu) )
	{
		if( member == 1 )
		{
			if( listsCreate == 0 )
			{
				LoadLists();
			}
			LoadMyData();
		}
	}
	else if( (id == 6) && (id != lastMenu) )
	{
		if( member == 1 )
		{
			LoadMentions();
		}
	}

	if( id == lastMenu )
	{
		document.getElementById('bar').style.height = 40+'px';
		document.getElementById('bar2').style.width = 20+'px';
		document.getElementById('bar2').style.top = 41+'px';
		document.getElementById('optionWnd1').style.visibility = 'hidden';
		document.getElementById('optionWnd2').style.visibility = 'hidden';
		document.getElementById('optionWnd3').style.visibility = 'hidden';
		document.getElementById('optionWnd4').style.visibility = 'hidden';
		document.getElementById('optionWnd5').style.visibility = 'hidden';
		document.getElementById('optionWnd6').style.visibility = 'hidden';
		document.getElementById('optionWnd1').style.display = 'none';
		document.getElementById('optionWnd2').style.display = 'none';
		document.getElementById('optionWnd3').style.display = 'none';
		document.getElementById('optionWnd4').style.display = 'none';
		document.getElementById('optionWnd5').style.display = 'none';
		document.getElementById('optionWnd6').style.display = 'none';
		document.getElementById('eegFrame').style.top = 41+'px';
		document.getElementById('eegFrame').style.left = 21+'px';
		SetWndSize(20,40);
		lastMenu = 0;
	}
	else
	{
		for( i = 1; i < menuMax; i++ )
		{
			if( i == id )
			{
				document.getElementById('optionWnd'+i).style.visibility = 'visible';
				document.getElementById('optionWnd'+i).style.display = 'block';

				if( (2 == id) || (3 == id) || (4 == id) || (5 == id) || (6 == id) )
				{
					document.getElementById('bar').style.height = 40+'px';
					document.getElementById('bar2').style.width = 340+'px';
					document.getElementById('bar2').style.top = 41+'px';
					document.getElementById('eegFrame').style.top = 41+'px';
					document.getElementById('eegFrame').style.left = 341+'px';
					SetWndSize(340,40);
				}
				else
				{
					document.getElementById('bar').style.height = (40+document.getElementById('optionWnd'+i).clientHeight)+'px';
					document.getElementById('bar2').style.width = 20+'px';
					document.getElementById('bar2').style.top = (41+document.getElementById('optionWnd'+i).clientHeight)+'px';
					document.getElementById('eegFrame').style.top = (41+document.getElementById('optionWnd'+i).clientHeight)+'px';
					document.getElementById('eegFrame').style.left = 21+'px';
					SetWndSize(20,(40+document.getElementById('optionWnd'+i).clientHeight));
				}
			}
			else
			{
				document.getElementById('optionWnd'+i).style.visibility = 'hidden';
				document.getElementById('optionWnd'+i).style.display = 'none';
			}
		}
		lastMenu = id;
	}
	$.cookie("lastMenu", lastMenu, { path:'/',expires: 365 });
}

var twtxtChanged = 0;

function onRetweet()
{
	var tmpTxt = $("#twtxt2").val();
	if( tmpTxt == '' )
	{
		alert('つぶやきが空です');
		return;
	}
	tmpTxt += ' (eegコメント on http://eeg.jp/'+urlid+' '+title_short+')';
	$(".rblock2").prepend('<img id="ajax-loader" src="/img/ajax-loader.gif" />');

	var dataString  = "mode=tweet";
			dataString += "&urlindex="+urlindex;
			dataString += "&url_hash="+hash;
			dataString += "&user_twid="+user_twid;
			dataString += "&user_hash="+user_hash;
			dataString += "&reply_twstatusid="+reply_twstatusid;
			if( last_insert_date != '' )
			{
				dataString += "&last_insert_date="+last_insert_date;
			}
			dataString += "&comment="+tmpTxt;

	$.ajax({
		type: "POST",
		url: "/json.php",
		data: dataString,
		dataType: "json",
		success: function(result){
			if( result.result_num != 0 )
			{
				$.each(result.tweets, function(i,results){
					if( i == result.result_num-1 )
					{
						last_insert_date = mysql_time(results.insert_date);
					}
					var comment = decodeURIComponent(results.comment);
							comment2 = 'RT @'+results.twid+' http://eeg.jp/'+urlid+' '+comment.replace(/http:\/\/eeg.jp\/([0-9a-zA-Z]+)/g,'');
							comment = comment.replace(/http:\/\/eeg.jp\/([0-9a-zA-Z]+)/g,'<a href="http://eeg.jp/$1" target="_blank">http://eeg.jp/$1</a>');
							comment = comment.replace(/@([0-9a-z_A-Z]+)/g,'@<a href="http://pf.eeg.jp/$1" target="blank">$1</a>');

					$("#fromAJAX").prepend(
						'<div class="item '+results.twstatusid+'">'
						+'<a href="http://pf.eeg.jp/'+results.twid+'" target="_blank">'
						+'<img src="'+results.twimg+'" height="48" />'
						+'</a>'
						+(
							( member == 1 )?
							(
								'<a href="javascript:;">'
								+'<img src="/img/follow.png" style="position:absolute;left:4px;top:54px;" onclick="Follow(\''+results.twid+'\');" alt="'+results.twname+'をフォローする" />'
								+'</a>'
							):
							(
								'<a href="/login.html">'
								+'<img src="/img/follow.png" style="position:absolute;left:4px;top:54px;" alt="'+results.twname+'をフォローする" />'
								+'</a>'
							)
						)
						+'<span>'
						+'<a href="http://pf.eeg.jp/'+results.twid+'" target="_blank">'
						+results.twname
						+'</a> '
						+'"'+comment+'"'
						+'<br />'
						+mysql_time(results.insert_date)
						+'</span>'
						+(
							( member == 1 )?
							(
								'<a href="javascript:;">'
								+'<img src="/img/reply.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Reply(\''+results.twid+' \');" alt="返信" /></a>'
								+'<a href="javascript:;">'
								+'<img src="/img/rt.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Retweet(\''+encodeURIComponent(comment2)+'\',\''+results.twstatusid+'\',\'0\');" alt="つぶやく！" /></a>'
								+'<a href="javascript:;">'
								+'<img src="/img/favorite.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Favorite(\''+results.twstatusid+'\');" alt="お気に入りに追加" /></a>'
							):
							(
								'<a href="/login.html">'
								+'<img src="/img/reply.png" style="width:80px;height:16px;margin-top:2px;float:right;" alt="返信" /></a>'
								+'<a href="/login.html">'
								+'<img src="/img/rt.png" style="width:80px;height:16px;margin-top:2px;float:right;" alt="つぶやく" /></a>'
								+'<a href="/login.html">'
								+'<img src="/img/favorite.png" style="width:80px;height:16px;margin-top:2px;float:right;" alt="お気に入りに追加" /></a>'
							)
						)
						+'</div>'
					);
				});
				$("#twtxt2").val('')
				$("#twtxt2").trigger("change")
			}
			else
			{
				alert('投稿に失敗しました');
			}
		},
		complete: function(){
			$("#ajax-loader").remove();
		}
	});
}

function onReloadComment()
{
	clearTimeout(timer);
	timer = '';

	$("#fromAJAX").each(function(){
		$(".rblock2").prepend('<img id="ajax-loader" src="/img/ajax-loader.gif" />');
		$.ajax({
			complete: function(){
				$("#ajax-loader").remove();
			}
		});
		$.getJSON("/json.php", { mode: "get_comment", url_hash:hash,last_insert_date:last_insert_date },function(result){
			if( result.result_num != 0 )
			{
				$.each(result.tweets, function(i,results){
					if( i == result.result_num-1 )
					{
						last_insert_date = mysql_time(results.insert_date);
					}
					var comment = decodeURIComponent(results.comment);
							comment2 = 'RT @'+results.twid+' http://eeg.jp/'+urlid+' '+comment.replace(/http:\/\/eeg.jp\/([0-9a-zA-Z]+)/g,'');
							comment = comment.replace(/http:\/\/eeg.jp\/([0-9a-zA-Z]+)/g,'<a href="http://eeg.jp/$1" target="_blank">http://eeg.jp/$1</a>');
							comment = comment.replace(/@([0-9a-z_A-Z]+)/g,'@<a href="http://pf.eeg.jp/$1" target="blank">$1</a>');
					$("#fromAJAX").prepend(
						'<div class="item '+results.twstatusid+'">'
						+'<a href="http://pf.eeg.jp/'+results.twid+'" target="_blank">'
						+'<img src="'+results.twimg+'" height="48" />'
						+'</a>'
						+(
							( member == 1 )?
							(
								'<a href="javascript:;">'
								+'<img src="/img/follow.png" style="position:absolute;left:4px;top:54px;" onclick="Follow(\''+results.twid+'\');" alt="'+results.twname+'をフォローする" />'
								+'</a>'
							):
							(
								'<a href="/login.html">'
								+'<img src="/img/follow.png" style="position:absolute;left:4px;top:54px;" alt="'+results.twname+'をフォローする" />'
								+'</a>'
							)
						)
						+'<span>'
						+'<a href="http://pf.eeg.jp/'+results.twid+'" target="_blank">'
						+results.twname
						+'</a> '
						+'"'+comment+'"'
						+'<br />'
						+mysql_time(results.insert_date)
						+'</span>'
						+(
							( member == 1 )?
							(
								'<a href="javascript:;">'
								+'<img src="/img/reply.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Reply(\''+results.twid+' \');" alt="返信" /></a>'
								+'<a href="javascript:;">'
								+'<img src="/img/rt.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Retweet(\''+encodeURIComponent(comment2)+'\',\''+results.twstatusid+'\',\'0\');" alt="つぶやく！" /></a>'
								+'<a href="javascript:;">'
								+'<img src="/img/favorite.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Favorite(\''+results.twstatusid+'\');" alt="お気に入りに追加" /></a>'
							):
							(
								'<a href="/login.html">'
								+'<img src="/img/reply.png" style="width:80px;height:16px;margin-top:2px;float:right;" alt="返信" /></a>'
								+'<a href="/login.html">'
								+'<img src="/img/rt.png" style="width:80px;height:16px;margin-top:2px;float:right;" alt="つぶやく" /></a>'
								+'<a href="/login.html">'
								+'<img src="/img/favorite.png" style="width:80px;height:16px;margin-top:2px;float:right;" alt="お気に入りに追加" /></a>'
							)
						)
						+'</div>'
					);
				});
			}
			if( last_insert_date != '' )
			{
				var delta = delta_time(last_insert_date);
				if( delta < 60 )
				{
					timer = setTimeout(onReloadComment, 10000);
				}
				else
				{
					timer = setTimeout(onReloadComment, 20000);
				}
			}
		});
	});
}
function updateEEG()
{
	var reqUrl = 'http://search.twitter.com/search.json?q=http%3A%2F%2Feeg%2Ejp%2F'+urlid+'&rpp=100&callback=?';
	if( since_id != '' )
	{
		reqUrl = 'http://search.twitter.com/search.json?q=http%3A%2F%2Feeg%2Ejp%2F'+urlid+'&since_id='+since_id+'&rpp=100&callback=?';
	}
	$.getJSON(reqUrl, function(json) {
		var dataString = "finaldata="+code+"&urlindex="+urlindex+"&urlhash="+hash;
		var counter = 0;
		since_id = json.results.max_id;
		$.each(json.results, function(i,results){
			if( ( results.from_user != 'eegjp')  && (results.text.indexOf(urlid,0) != -1 ) && (results.source.indexOf('eeg',0) == -1)  )
			{
				dataString += "&twid[]="+results.from_user;
				dataString += "&twimg[]="+results.profile_image_url;
				dataString += "&comment[]="+results.text;
				dataString += "&insert_date[]="+results.created_at;
				dataString += "&twstatusid[]="+results.id;
				counter++;
			}
		});
		if( counter != 0 )
		{
			$.ajax({
						type: "POST",
						url: "json.php",
						data: dataString,
						success: function(msg){
						}
			});
		}
	});
}
function LoadLists()
{
	$("#lists").empty();
	$("#lists").prepend('<img id="ajax-loader" src="/img/ajax-loader.gif" />');
	$.ajax({
		complete: function(){
			$("#ajax-loader").remove();
		}
	});
	var reqUrl = 'json.php?mode=lists';
	$.getJSON(reqUrl, function(json) {

		var tmpStr = "<select id='twlists'></select>";
		var target = $(tmpStr);

		if( ($.cookie('lastList') == '') || (($.cookie('lastList') == '0')) )
		{
			tmpStr = "<option value='"+0+"' selected />";
		}
		else
		{
			tmpStr = "<option value='"+0+"' />";
		}
		var target2 = $(tmpStr);
		target2.append(document.createTextNode('タイムライン'));
		target.append(target2);

		$.each(json.lists, function(i,item){
			if( $.cookie('lastList') == item.slug )
			{
				tmpStr = "<option value='"+item.slug+"' selected />";
			}
			else
			{
				tmpStr = "<option value='"+item.slug+"' />";
			}
			var target2 = $(tmpStr);
			target2.append(document.createTextNode(item.slug));
			target.append(target2);
		});
		$("#lists").append(target);
		listsCreate = 1;
	  $("#lists>select").change(onListSelectChange);
	});
}
function onListSelectChange()
{
	$.cookie("lastList",$(this).val(), { path:'/',expires: 365 });
	LoadMyData();
}

function LoadMyData()
{
	if( ($.cookie('lastList') == '') || (($.cookie('lastList') == '0')) )
	{
		LoadTimeline();
	}
	else
	{
		LoadMyLists($.cookie('lastList'));
	}
}
function LoadMyLists(targetList)
{
	$("#timeline").prepend('<img id="ajax-loader" src="/img/ajax-loader.gif" />');
	var reqUrl = 'json.php?mode=list&target='+targetList;
	$.getJSON(reqUrl, function(json) {
		$("#timeline").empty();
		$.each(json, function(i,item){
			var comment = String(item.text);
					comment = comment.replace('　',' ');
					comment = comment.replace(/(http:\/\/[^ ]+)/g,'<a href="http://eeg.jp/$1">$1</a>');
					comment = comment.replace('http://eeg.jp/http://eeg.jp/','http://eeg.jp/');
					comment = comment.replace(/@([0-9a-z_A-Z]+)/g,'@<a href="http://pf.eeg.jp/$1" target="blank">$1</a>');

			var screen_name = String(item.user["screen_name"]);
			var tmpSrc = encodeURIComponent('RT @'+screen_name+' '+item.text.replace("'","’").replace(")","）").replace("(","（"));

			var itemSrc = '';
			itemSrc += '<div class="item">';
			itemSrc += '<a href="http://pf.eeg.jp/'+screen_name+'" target="_blank">';
			itemSrc += '<img src="'+item.user.profile_image_url+'" height="48" alt="'+item.user.description+'" />';
			itemSrc += '</a>';
			itemSrc += '<span>';
			itemSrc += '<a href="http://pf.eeg.jp/'+screen_name+'" target="_blank">';
			itemSrc += item.user.name;
			itemSrc += '</a> ';
			itemSrc += '"'+comment+'"';
			itemSrc += '<br />';
			itemSrc += relative_time(item.created_at);
			if( item.user.location != '' )
			{
				itemSrc += ' ['+item.user.location+']';
			}
			if( item.user.url != '' )
			{
				itemSrc += ' [ <a href="http://eeg.jp/'+item.user.url+'" target="_blank">HP</a> ]';
			}
			itemSrc += '</span>';
			itemSrc += '<a href="javascript:;">';
			itemSrc += '<img src="/img/reply.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Retweet(\'@'+screen_name+' \',\''+item.id+'\',\'1\');" alt="返信" />';
			itemSrc += '</a>';
			itemSrc += '<a href="javascript:;">';
			itemSrc += '<img src="/img/rt.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Retweet(\''+tmpSrc+'\',\''+item.id+'\',\'1\');" alt="つぶやく" />';
			itemSrc += '</a>';
			if( item.favorited == false )
			{
				itemSrc += '<a href="javascript:;">';
				itemSrc += '<img src="/img/favorite.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Favorite(\''+item.id+'\');" alt="お気に入りに追加" />';
				itemSrc += '</a>';
			}
			itemSrc += '</div>';
			$("#timeline").append(itemSrc);
		});
	});
}

function LoadTimeline()
{
	$("#timeline").prepend('<img id="ajax-loader" src="/img/ajax-loader.gif" />');
	var reqUrl = 'json.php?mode=statuses/home_timeline';
	$.getJSON(reqUrl, function(json) {
		$("#timeline").empty();
		$.each(json, function(i,item){
			var comment = String(item.text);
					comment = comment.replace('　',' ');
					comment = comment.replace(/(http:\/\/[^ ]+)/g,'<a href="http://eeg.jp/$1">$1</a>');
					comment = comment.replace('http://eeg.jp/http://eeg.jp/','http://eeg.jp/');
					comment = comment.replace(/@([0-9a-z_A-Z]+)/g,'@<a href="http://pf.eeg.jp/$1" target="blank">$1</a>');

			var screen_name = String(item.user["screen_name"]);
			var tmpSrc = encodeURIComponent('RT @'+screen_name+' '+item.text.replace("'","’").replace(")","）").replace("(","（"));

			var itemSrc = '';
			itemSrc += '<div class="item">';
			itemSrc += '<a href="http://pf.eeg.jp/'+screen_name+'" target="_blank">';
			itemSrc += '<img src="'+item.user.profile_image_url+'" height="48" alt="'+item.user.description+'" />';
			itemSrc += '</a>';
			itemSrc += '<span>';
			itemSrc += '<a href="http://pf.eeg.jp/'+screen_name+'" target="_blank">';
			itemSrc += item.user.name;
			itemSrc += '</a> ';
			itemSrc += '"'+comment+'"';
			itemSrc += '<br />';
			itemSrc += relative_time(item.created_at);
			if( item.user.location != '' )
			{
				itemSrc += ' ['+item.user.location+']';
			}
			if( item.user.url != '' )
			{
				itemSrc += ' [ <a href="http://eeg.jp/'+item.user.url+'" target="_blank">HP</a> ]';
			}
			itemSrc += '</span>';
			itemSrc += '<a href="javascript:;">';
			itemSrc += '<img src="/img/reply.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Retweet(\'@'+screen_name+' \',\''+item.id+'\',\'1\');" alt="返信" />';
			itemSrc += '</a>';
			itemSrc += '<a href="javascript:;">';
			itemSrc += '<img src="/img/rt.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Retweet(\''+tmpSrc+'\',\''+item.id+'\',\'1\');" alt="つぶやく" />';
			itemSrc += '</a>';
			if( item.favorited == false )
			{
				itemSrc += '<a href="javascript:;">';
				itemSrc += '<img src="/img/favorite.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Favorite(\''+item.id+'\');" alt="お気に入りに追加" />';
				itemSrc += '</a>';
			}
			itemSrc += '</div>';
			$("#timeline").append(itemSrc);
		});
	});
}
function LoadMentions()
{
	$("#mentions").prepend('<img id="ajax-loader" src="/img/ajax-loader.gif" />');

	var reqUrl = 'json.php?mode=statuses/mentions';
	$.getJSON(reqUrl, function(json) {
		$("#mentions").empty();
		$.each(json, function(i,item){
			var comment = String(item.text);
					comment = comment.replace('　',' ');
					comment = comment.replace(/(http:\/\/[^ ]+)/g,'<a href="http://eeg.jp/$1">$1</a>');
					comment = comment.replace('http://eeg.jp/http://eeg.jp/','http://eeg.jp/');
					comment = comment.replace(/@([0-9a-z_A-Z]+)/g,'@<a href="http://pf.eeg.jp/$1" target="blank">$1</a>');

			var screen_name = String(item.user["screen_name"]);
			var tmpSrc = encodeURIComponent('RT @'+screen_name+' '+item.text.replace("'","’").replace(")","）").replace("(","（"));

			var itemSrc = '';
			itemSrc += '<div class="item">';
			itemSrc += '<a href="http://pf.eeg.jp/'+screen_name+'" target="_blank">';
			itemSrc += '<img src="'+item.user.profile_image_url+'" height="48" alt="'+item.user.description+'" />';
			itemSrc += '</a>';
			itemSrc += '<span>';
			itemSrc += '<a href="http://pf.eeg.jp/'+screen_name+'" target="_blank">';
			itemSrc += item.user.name;
			itemSrc += '</a> ';
			itemSrc += '"'+comment+'"';
			itemSrc += '<br />';
			itemSrc += relative_time(item.created_at);
			if( item.user.location != '' )
			{
				itemSrc += ' ['+item.user.location+']';
			}
			if( item.user.url != '' )
			{
				itemSrc += ' [ <a href="http://eeg.jp/'+item.user.url+'" target="_blank">HP</a> ]';
			}
			itemSrc += '</span>';
			itemSrc += '<a href="javascript:;">';
			itemSrc += '<img src="/img/reply.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Retweet(\'@'+screen_name+' \',\''+item.id+'\',\'1\');" alt="返信" />';
			itemSrc += '</a>';
			itemSrc += '<a href="javascript:;">';
			itemSrc += '<img src="/img/rt.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Retweet(\''+tmpSrc+'\',\''+item.id+'\',\'1\');" alt="つぶやく" />';
			itemSrc += '</a>';
			if( item.favorited == false )
			{
				itemSrc += '<a href="javascript:;">';
				itemSrc += '<img src="/img/favorite.png" style="width:80px;height:16px;margin-top:2px;float:right;" onclick="Favorite(\''+item.id+'\');" alt="お気に入りに追加" />';
				itemSrc += '</a>';
			}
			itemSrc += '</div>';
			$("#mentions").append(itemSrc);
		});
	});
}
function Favorite( statusid )
{
	if( member == 1 )
	{
		var reqUrl = 'json.php?mode=favorites/create&twstatusid='+statusid;
			$.getJSON(reqUrl, function(json) {
			alert('お気に入りに追加しました');
		});
	}
}

function Follow( screen_name )
{
	if( member == 1 )
	{
		var reqUrl = 'json.php?mode=friendships/create&screen_name='+screen_name;
			$.getJSON(reqUrl, function(json) {
			alert(screen_name+'をフォローしました');
		});
	}
}

function Retweet( comment,twstatusid,norelation )
{
	document.getElementById('twtxt').innerHTML = decodeURIComponent(comment);
	document.getElementById('twstatusid').value = twstatusid;
	document.getElementById('norelation').value = norelation;
	document.getElementById('optionWnd2').scrollTop = 0;
	document.getElementById('optionWnd3').scrollTop = 0;
	ToggleSub(1);
}

function Reply( twid )
{
	document.getElementById('twtxt2').innerHTML = '@'+twid+' ';
	document.getElementById('optionWnd2').scrollTop = 0;
	document.getElementById('optionWnd3').scrollTop = 0;
}
