var tb_pathToImage = "http://jquery.com/demo/thickbox/images/loadingAnimation.gif";
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$(o).2S(9(){1u(\'a.18, 3n.18, 3i.18\');1w=1p 1t();1w.L=2H});9 1u(b){$(b).s(9(){6 t=X.Q||X.1v||M;6 a=X.u||X.23;6 g=X.1N||P;19(t,a,g);X.2E();H P})}9 19(d,f,g){3m{3(2t o.v.J.2i==="2g"){$("v","11").r({A:"28%",z:"28%"});$("11").r("22","2Z");3(o.1Y("1F")===M){$("v").q("<U 5=\'1F\'></U><4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}n{3(o.1Y("B")===M){$("v").q("<4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}3(1K()){$("#B").1J("2B")}n{$("#B").1J("2z")}3(d===M){d=""}$("v").q("<4 5=\'K\'><1I L=\'"+1w.L+"\' /></4>");$(\'#K\').2y();6 h;3(f.O("?")!==-1){h=f.3l(0,f.O("?"))}n{h=f}6 i=/\\.2s$|\\.2q$|\\.2m$|\\.2l$|\\.2k$/;6 j=h.1C().2h(i);3(j==\'.2s\'||j==\'.2q\'||j==\'.2m\'||j==\'.2l\'||j==\'.2k\'){1D="";1G="";14="";1z="";1x="";R="";1n="";1r=P;3(g){E=$("a[@1N="+g+"]").36();25(D=0;((D<E.1c)&&(R===""));D++){6 k=E[D].u.1C().2h(i);3(!(E[D].u==f)){3(1r){1z=E[D].Q;1x=E[D].u;R="<1e 5=\'1X\'>&1d;&1d;<a u=\'#\'>2T &2R;</a></1e>"}n{1D=E[D].Q;1G=E[D].u;14="<1e 5=\'1U\'>&1d;&1d;<a u=\'#\'>&2O; 2N</a></1e>"}}n{1r=1b;1n="1t "+(D+1)+" 2L "+(E.1c)}}}S=1p 1t();S.1g=9(){S.1g=M;6 a=2x();6 x=a[0]-1M;6 y=a[1]-1M;6 b=S.z;6 c=S.A;3(b>x){c=c*(x/b);b=x;3(c>y){b=b*(y/c);c=y}}n 3(c>y){b=b*(y/c);c=y;3(b>x){c=c*(x/b);b=x}}13=b+30;1a=c+2G;$("#8").q("<a u=\'\' 5=\'1L\' Q=\'1o\'><1I 5=\'2F\' L=\'"+f+"\' z=\'"+b+"\' A=\'"+c+"\' 23=\'"+d+"\'/></a>"+"<4 5=\'2D\'>"+d+"<4 5=\'2C\'>"+1n+14+R+"</4></4><4 5=\'2A\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4>");$("#Z").s(G);3(!(14==="")){9 12(){3($(o).N("s",12)){$(o).N("s",12)}$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1D,1G,g);H P}$("#1U").s(12)}3(!(R==="")){9 1i(){$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1z,1x,g);H P}$("#1X").s(1i)}o.1h=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}n 3(I==3k){3(!(R=="")){o.1h="";1i()}}n 3(I==3j){3(!(14=="")){o.1h="";12()}}};16();$("#K").C();$("#1L").s(G);$("#8").r({Y:"T"})};S.L=f}n{6 l=f.2r(/^[^\\?]+\\??/,\'\');6 m=2p(l);13=(m[\'z\']*1)+30||3h;1a=(m[\'A\']*1)+3g||3f;W=13-30;V=1a-3e;3(f.O(\'2j\')!=-1){1E=f.1B(\'3d\');$("#15").C();3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4></4><U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\' > </U>")}n{$("#B").N();$("#8").q("<U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\'> </U>")}}n{3($("#8").r("Y")!="T"){3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\'>1l</a> 1k 1j 1s</4></4><4 5=\'F\' J=\'z:"+W+"p;A:"+V+"p\'></4>")}n{$("#B").N();$("#8").q("<4 5=\'F\' 3c=\'3b\' J=\'z:"+W+"p;A:"+V+"p;\'></4>")}}n{$("#F")[0].J.z=W+"p";$("#F")[0].J.A=V+"p";$("#F")[0].3a=0;$("#1H").11(d)}}$("#Z").s(G);3(f.O(\'37\')!=-1){$("#F").q($(\'#\'+m[\'26\']).1T());$("#8").24(9(){$(\'#\'+m[\'26\']).q($("#F").1T())});16();$("#K").C();$("#8").r({Y:"T"})}n 3(f.O(\'2j\')!=-1){16();3($.1q.35){$("#K").C();$("#8").r({Y:"T"})}}n{$("#F").34(f+="&1y="+(1p 33().32()),9(){16();$("#K").C();1u("#F a.18");$("#8").r({Y:"T"})})}}3(!m[\'1A\']){o.21=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}}}}31(e){}}9 1m(){$("#K").C();$("#8").r({Y:"T"})}9 G(){$("#2Y").N("s");$("#Z").N("s");$("#8").2X("2W",9(){$(\'#8,#B,#1F\').2V("24").N().C()});$("#K").C();3(2t o.v.J.2i=="2g"){$("v","11").r({A:"1Z",z:"1Z"});$("11").r("22","")}o.1h="";o.21="";H P}9 16(){$("#8").r({2U:\'-\'+20((13/2),10)+\'p\',z:13+\'p\'});3(!(1V.1q.2Q&&1V.1q.2P<7)){$("#8").r({38:\'-\'+20((1a/2),10)+\'p\'})}}9 2p(a){6 b={};3(!a){H b}6 c=a.1B(/[;&]/);25(6 i=0;i<c.1c;i++){6 d=c[i].1B(\'=\');3(!d||d.1c!=2){39}6 e=2a(d[0]);6 f=2a(d[1]);f=f.2r(/\\+/g,\' \');b[e]=f}H b}9 2x(){6 a=o.2M;6 w=1S.2o||1R.2o||(a&&a.1Q)||o.v.1Q;6 h=1S.1P||1R.1P||(a&&a.2n)||o.v.2n;1O=[w,h];H 1O}9 1K(){6 a=2K.2J.1C();3(a.O(\'2I\')!=-1&&a.O(\'3o\')!=-1){H 1b}}',62,211,'|||if|div|id|var||TB_window|function||||||||||||||else|document|px|append|css|click||href|body||||width|height|TB_overlay|remove|TB_Counter|TB_TempArray|TB_ajaxContent|tb_remove|return|keycode|style|TB_load|src|null|unbind|indexOf|false|title|TB_NextHTML|imgPreloader|block|iframe|ajaxContentH|ajaxContentW|this|display|TB_closeWindowButton||html|goPrev|TB_WIDTH|TB_PrevHTML|TB_iframeContent|tb_position||thickbox|tb_show|TB_HEIGHT|true|length|nbsp|span|Math|onload|onkeydown|goNext|Esc|or|close|tb_showIframe|TB_imageCount|Close|new|browser|TB_FoundURL|Key|Image|tb_init|name|imgLoader|TB_NextURL|random|TB_NextCaption|modal|split|toLowerCase|TB_PrevCaption|urlNoQuery|TB_HideSelect|TB_PrevURL|TB_ajaxWindowTitle|img|addClass|tb_detectMacXFF|TB_ImageOff|150|rel|arrayPageSize|innerHeight|clientWidth|self|window|children|TB_prev|jQuery|frameborder|TB_next|getElementById|auto|parseInt|onkeyup|overflow|alt|unload|for|inlineId||100||unescape|1000|round|hspace|TB_closeAjaxWindow|TB_title|undefined|match|maxHeight|TB_iframe|bmp|gif|png|clientHeight|innerWidth|tb_parseQuery|jpeg|replace|jpg|typeof|which|keyCode|event|tb_getPageSize|show|TB_overlayBG|TB_closeWindow|TB_overlayMacFFBGHack|TB_secondLine|TB_caption|blur|TB_Image|60|tb_pathToImage|mac|userAgent|navigator|of|documentElement|Prev|lt|version|msie|gt|ready|Next|marginLeft|trigger|fast|fadeOut|TB_imageOff|hidden||catch|getTime|Date|load|safari|get|TB_inline|marginTop|continue|scrollTop|TB_modal|class|TB_|45|440|40|630|input|188|190|substr|try|area|firefox'.split('|'),0,{}));

//eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('4 3={y:9(){4 a=5.z(\'a\');A(4 i=0;i<a.B;i++){4 b=a[i];2((b.C&&b.C.Y(\'#\')!=-1)&&((b.j==k.j)||(\'/\'+b.j==k.j))&&(b.D==k.D)){3.s(b,\'Z\',3.E)}}},E:9(e){2(6.h){8=6.h.11}l 2(e){8=e.8}l{7}2(8.F.G()!=\'a\'){8=8.12}2(8.F.G()!=\'a\'){7}m=8.H.13(1);4 a=5.z(\'a\');4 b=14;A(4 i=0;i<a.B;i++){4 c=a[i];2(c.I&&(c.I==m)){b=c;15}}2(!b){b=5.16(m)}2(!b){7 t}4 d=b.J;4 f=b.K;4 g=b;17(g.u&&(g.u!=5.n)){g=g.u;d+=g.J;f+=g.K}L(3.v);M=3.o();N=18((f-M)/3.O);3.v=19(\'3.P(\'+N+\',\'+f+\',"\'+m+\'")\',10);2(6.h){6.h.1a=t;6.h.1b=1c}2(e&&e.Q&&e.R){e.Q();e.R()}},P:9(a,b,c){p=3.o();S=(p<b);6.T(0,p+a);w=3.o();U=(w<b);2((S!=U)||(p==w)){6.T(0,b);L(3.v);k.H=c}},o:9(){2(5.n&&5.n.q){7 5.n.q}2(5.x&&5.x.q){7 5.x.q}2(6.V){7 6.V}7 0},s:9(a,b,c,d){2(a.W){a.W(b,c,d);7 t}l 2(a.X){4 r=a.X("1d"+b,c);7 r}l{1e("1f 1g 1h 1i 1j")}}};3.O=1k;3.s(6,"1l",3.y);',62,84,'||if|ss|var|document|window|return|target|function||||||||event||pathname|location|else|anchor|body|getCurrentYPos|wascypos|scrollTop||addEvent|true|offsetParent|INTERVAL|iscypos|documentElement|fixAllLinks|getElementsByTagName|for|length|href|search|smoothScroll|nodeName|toLowerCase|hash|name|offsetLeft|offsetTop|clearInterval|cypos|ss_stepsize|STEPS|scrollWindow|preventDefault|stopPropagation|isAbove|scrollTo|isAboveNow|pageYOffset|addEventListener|attachEvent|indexOf|click||srcElement|parentNode|substr|null|break|getElementById|while|parseInt|setInterval|cancelBubble|returnValue|false|on|alert|Handler|could|not|be|removed|25|load'.split('|'),0,{}));

(function($){$.fn.lazyload=function(options){var settings={threshold:0,failurelimit:0,event:"scroll",effect:"show",container:window};if(options){$.extend(settings,options);}
var elements=this;if("scroll"==settings.event){$(settings.container).bind("scroll",function(event){var counter=0;elements.each(function(){if($.abovethetop(this,settings)||$.leftofbegin(this,settings)){}else if(!$.belowthefold(this,settings)&&!$.rightoffold(this,settings)){$(this).trigger("appear");}else{if(counter++>settings.failurelimit){return false;}}});var temp=$.grep(elements,function(element){return!element.loaded;});elements=$(temp);});}
this.each(function(){var self=this;if(undefined==$(self).attr("original")){$(self).attr("original",$(self).attr("src"));}
if("scroll"!=settings.event||undefined==$(self).attr("src")||settings.placeholder==$(self).attr("src")||($.abovethetop(self,settings)||$.leftofbegin(self,settings)||$.belowthefold(self,settings)||$.rightoffold(self,settings))){if(settings.placeholder){$(self).attr("src",settings.placeholder);}else{$(self).removeAttr("src");}
self.loaded=false;}else{self.loaded=true;}
$(self).one("appear",function(){if(!this.loaded){$("<img />").bind("load",function(){$(self).hide().attr("src",$(self).attr("original"))
[settings.effect](settings.effectspeed);self.loaded=true;}).attr("src",$(self).attr("original"));};});if("scroll"!=settings.event){$(self).bind(settings.event,function(event){if(!self.loaded){$(self).trigger("appear");}});}});$(settings.container).trigger(settings.event);return this;};$.belowthefold=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).height()+$(window).scrollTop();}else{var fold=$(settings.container).offset().top+$(settings.container).height();}
return fold<=$(element).offset().top-settings.threshold;};$.rightoffold=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).width()+$(window).scrollLeft();}else{var fold=$(settings.container).offset().left+$(settings.container).width();}
return fold<=$(element).offset().left-settings.threshold;};$.abovethetop=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).scrollTop();}else{var fold=$(settings.container).offset().top;}
return fold>=$(element).offset().top+settings.threshold+$(element).height();};$.leftofbegin=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).scrollLeft();}else{var fold=$(settings.container).offset().left;}
return fold>=$(element).offset().left+settings.threshold+$(element).width();};$.extend($.expr[':'],{"below-the-fold":"$.belowthefold(a, {threshold : 0, container: window})","above-the-fold":"!$.belowthefold(a, {threshold : 0, container: window})","right-of-fold":"$.rightoffold(a, {threshold : 0, container: window})","left-of-fold":"!$.rightoffold(a, {threshold : 0, container: window})"});})(jQuery);

$(function() {          
    $(".left img").lazyload({
       placeholder : baseuri+"/img/grey.gif",
//       effect      : "fadeIn",
//       threshold   : 500
    });
});

(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);

function thickboxShow(e,a){
	var t = e.title || e.name || null;
	var g = e.rel || false;
	tb_show(t,a,g);
	e.blur();
}

function openOAuth(){
	tb_show("twitter経由でサイトにログイン",baseuri+"/oauth?height=250&width=400",false);
}

function action_reply(idx){
	if(userid){
		tb_show("",baseuri+"/dialog_reply/"+index+"?height=250&width=400&modal=true&idx="+idx,false);
	}else{
		openOAuth();
	}
}

function post_reply(id){
	var o = $(".post_box form").serializeArray();
	if(!o[0].value || o[0].value == "コメントを入力してください。"){
		alert("コメントを入力してください。");
		return;
	}
	
	post_call_api('/api/reply/'+id,{
		comment : o[0].value,
		add : (o[1] && o[1].value == "on" ? 1 : 0),
		in_reply_to : o[2].value,
	});

}

function action_retweet(idx){
	if(userid){
		tb_show("",baseuri+"/dialog_retweet/"+index+"?height=250&width=400&modal=true&idx="+idx,false);
	}else{
		openOAuth();
	}
}

function post_retweet(official,id){
	var o = $(".post_box form").serializeArray();
	
	if(!official){
		if(!o[0].value || o[0].value == "コメントを入力してください。"){
			alert("コメントを入力してください。");
			return;
		}
	}
	
	post_call_api('/api/retweet/'+id,{
		official : (official ? 1 : 0),
		comment : o[0].value,
		add : (o[1] && o[1].value == "on" ? 1 : 0),
		in_reply_to : o[2].value,
	});

}

function action_moreTweets(){
	$.get(baseuri+'/api/moreTweets/'+index,function (text){
		$("#list_more_line").replaceWith(text);
	});	
}



function post_favorite(f){
	var twit = f ? 1 : 0;
	var o = $(".post_box form").serializeArray();
	var comment = twit ? o[0].value : "";
	var list_id = o[1].value;
	
	$.get(baseuri+'/api/addListFavorite/'+list_id,{twit:twit,comment:comment},function (text){
		if(text == "error")
			alert("お気に入りへの登録に失敗しました。");
		else{
			alert("お気に入りへ登録しました。");
			tb_remove();
		}
	});
}

function action_listFavorite(id){
	if(userid){
		tb_show("",baseuri+"/dialog_favorite/"+id+"?height=250&width=400&modal=true",false);
/*		
		var twit = confirm("お気に入りをTwitterにも投稿しますか？") ? 1 : 0;
		$.get(baseuri+'/api/favorite/'+id,{twit:twit},function (text){
			if(text == "admin"){
			}else if(text == "error")
				alert("お気に入りへの登録に失敗しました。");
			else
				alert("お気に入りへ登録しました。");
		});*/
	}else{
		openOAuth();
	}
}

function action_moreFavorite(){
  	$(".favorite_box").load(baseuri+'/api/moreFavorite/'+index);
}

function action_favorite(idx){
	if(userid){
		$.post(baseuri+'/api/addFavorite/'+index,{
			idx : idx
		},function (text){
			alert("このつぶやきをふぁぼりました。");
		});
	}else{
		openOAuth();
	}
}

function action_comment(){
	if(userid){
		tb_show("",baseuri+"/dialog_comment/"+index+"?height=250&width=400&modal=true",false);
	}else{
		openOAuth();
	}
}

function post_comment(id){
	var o = $(".post_box form").serializeArray();

	if(o[0].value == "コメントを入力してください。"){
		alert("コメントを入力してください。");
		return;
	}
	
	post_call_api('/api/comment/'+id,{
		comment : o[0].value,
		twit : (o[1] && o[1].value == "on" ? 1 : 0)
	});	
	
}

function action_moreHistory(){
  	$(".history_box").load(baseuri+'/api/moreHistory/'+index);
}

function post_impl(prefix){
	
	var ids = $(prefix+" .action_item").map(function(){
		return $(this).attr("id");
	});
	
	var users = $(prefix+" .action_item h5 a.user").map(function(){
		return $(this).text();
	});
	var dates = $(prefix+" .action_item h5 span.date").map(function(){
		return $(this).text();
	});
	var tweets = $(prefix+" .action_item h4").map(function(){
		return $(this).html();
	});
	var images = $(prefix+" .action_item .list_img_wrap img").map(function(){
		return $(this).attr("src");
	});
	
	var res = [];
	for(var i = 0;i < ids.length;i++){
		var tmp = {};
		tmp.id = ids[i];
		tmp.user = users[i];
		tmp.date = dates[i];
		tmp.tweet = tweets[i];
		tmp.image = images[i];
		res.push(tmp);
	}
	
	return $.toJSON(res);

}

function post_impl2(prefix){
	var keys = $(prefix+" .action_item .list_box").map(function(){
		return $(this).attr("id");
	});
	
	var res = [];
	$(keys).each(function(){
		res.push(this);
	});
	
	return $.toJSON(res);
}

function post_impl3(prefix){
	var keys = $(prefix+" .deco_item .list_box").map(function(){
		return $(this).attr("id");
	});
	var tweets = $(prefix+" .deco_item .tweet").map(function(){
		return $(this).html();
	});
	
	var res = [];
	$(keys).each(function(idx,val){
		var tmp = {};
		tmp.key = val;
		tmp.tweet = tweets[idx];
		res.push(tmp);
	});
	return $.toJSON(res);
}

function post_backup(id){
	if(confirm("選択した状態に戻してよろしいですか？")){
		var o = $(".post_box form").serializeArray();
		$.post(baseuri+'/api/backup/'+id,{backup_id:o[0].value},function(text){
			if(text == "error")
				alert("保存されているリストの反映に失敗しました。");
			else{
				alert("保存されているリストを反映しました。");
				location.href = baseuri+'/li/'+id;
			}
		});
	}
}

function post_delete(id){
	if(confirm("このリストを削除してよろしいですか？")){
		$.get(baseuri+'/api/delete/'+id,function (text){
			if(text == "error")
				alert("リストの削除に失敗しました。");
			else{
				alert("リストを削除しました。");
				location.href = baseuri+'/id/'+text;
			}
	　	});
	}	
}

function post_cancel(id){
	if(confirm("編集内容を破棄してよろしいですか？")){
		location.href = baseuri+'/li/'+id;
	}
}

function post_edit(id){
	
	if($("#choices .action_item").length < 2){
		alert("最低２つ以上のつぶやきを設定してください。");
		return;
	}
	
	var o = $(".post_box form").serializeArray();
	if(o[0].value == "編集コメントを入力してください。"){
		o[0].value = "";
	}
	
	post_call_api('/api/edit/'+id,{
		data : post_impl2("#choices"),
		comment : o[0].value,
		twit : (o[1] && o[1].value == "on" ? 1 : 0),
		flag : 2
	});	
	
}

function post_deco(id){
	
	var o = $(".post_box form").serializeArray();
	if(o[0].value == "編集コメントを入力してください。"){
		o[0].value = "";
	}

	post_call_api('/api/edit/'+id,{
		data : post_impl3("#decos"),
		comment : o[0].value,
		twit : (o[1] && o[1].value == "on" ? 1 : 0),
		flag : 3
	});
}
	
function post_create(){
	
	if($("#choices .action_item").length < 2){
		alert("最低２つ以上のつぶやきを設定してください。");
		return;
	}
	
	var o = $(".post_box form").serializeArray();
	if(o[0].value == "タイトルを入力してください。"){
		alert("タイトルを入力してください。");
		return;
	}
	
	if(o[1].value == "簡単な解説文を入力してください。"){
		o[1].value = "";
	}

	if(o[2].value == "タグを入力してください。"){
		o[2].value = "";
	}
		
	post_call_api('/api/add',{
		title : o[0].value,
		desc : o[1].value,
		tag : o[2].value,
		pref : o[3].value,
		twit : (o[4] && o[4].value == "on" ? 1 : 0),
		data : post_impl2("#choices")
	});
	
}

function post_rename(id){
	var o = $(".post_box form").serializeArray();
	if(o[0].value == "タイトルを入力してください。"){
		alert("タイトルを入力してください。");
		return;
	}

	if(o[1].value == "簡単な解説文を入力してください。"){
		o[1].value = "";
	}
	
	post_call_api('/api/rename/'+id,{
		title : o[0].value,
		desc : o[1].value,
		pref : o[2].value
	});	

}

function post_call_api(url,data){
	$.ajax({
		type: 'POST',
		url: baseuri+url,
		timeout: 60000,
		data: data,
		beforeSend: function(){
			if(elm = $(".post_box input[type=submit]")[0])
				elm.disabled = true;
		},
		error:function (){
			alert("失敗しました。時間を置いてから再度お試しください。");
			if(elm = $(".post_box input[type=submit]")[0])
				elm.disabled = false;
		},
		success:function (text){
			if(text != parseInt(text)){
				this.error();
			}else{
				location.href = baseuri+'/li/'+text;
			}
		}
	});
}

function post_reset(){
	tb_remove();
}

function edit(id){
	if(userid){
		location.href = baseuri+'/li/'+id;
	}else{
		openOAuth();
	}	
}

function apiCall(func,data,replace){
	var s = (new Date()).getTime();
	if(!data.n)data.n = $("#num_select").val();
	$.get(baseuri+'/api/'+func+'?s='+s,data,function (text){
		if(replace){
			$("#"+replace).after(text).remove();
		}else{
			$("#results").append(text);
		}
		var p = $("#results").scrollTop() + $("#"+s).offset().top - $("#results").height() / 2 - $("#results").offset().top;
		$("#results").scrollTop(p);
		limit();
	});
}

function apiStatusCall(data){
	$.get(baseuri+'/api/getStatus',data,function (text){
		$("#choices").append(text);
		limit();
	});
}

function users(){
}

function results_reset(){
	if(confirm("取得したTLをクリアしてよろしいですか？")){
		$("#results").html("");		
	}
}

function choices_reset(){
	if(confirm("作成したTLをクリアしてよろしいですか？")){
		$("#choices").html("");
	}
}

function list(){
	var text = $("#list_input").val();
	var text = text.match(/\/([0-9a-zA-Z_-]+\/[0-9a-zA-Z_-]+)$/)[1];
	apiCall("getListTimeline",{q:text});
}

function limit(){
	$.get(baseuri+'/api/getApiStatus',function (text){
		$("#apistatus").html(text);
	});
}

function home(){
	apiCall("getFriendsTimeline",{});	
}

function favorite(){
	apiCall("getUserFavorite",{});
}

function mention(){
	apiCall("getUserMention",{});
}

function user(){
	var text = $("#word_input").val();
	apiCall("getUsersTimeline",{users:text});
//	apiCall("getUserTimeline",{name:text});	
}

function del(id){
	$("#"+id).remove();
}

function selected_copy(){
	var ids = $("#results .selected_item").map(function(){
		return $(this).removeClass("selected_item").attr("id");
	});
	var elm = $("#choices");
	$(ids).each(function(){
		elm.append($("#results li[id="+this+"]").get());
	});	
}

function copy(){
	var ids = $("#results .action_item").map(function(){
		return $(this).attr("id");
	});
	var elm = $("#choices");	
	$(ids).each(function(){
		elm.append($("#results li[id="+this+"]").get());
	});
}

function sort(f){
	var ids = $("#choices .action_item").map(function(){
		return $(this).attr("id");
	});
	ids.sort(function(a,b){return f ? a-b : b-a;});
	var elm = $("#choices");	
	$(ids).each(function(){
		if(tmp = $("#choices li[id="+this+"]"))elm.append(tmp.get());
	});
}

function duplicate(){
	var ids = [];
	$("#choices .action_item").map(function(){
		var id = $(this).attr("id");
		if(ids.indexOf(id) < 0){
			ids.push(id);
		}else{
			$(this).remove();
		}
	});
}

function search(){
	var text = $("#word_input").val();
	apiCall("getSearchQuery",{q:text});
	
/*
	$.ajax({
		url : "http://search.twitter.com/search.json",
		dataType : "jsonp",
		data : {
			q : text
		},
		success : function(json){
			
			$(json.results).each(function(){

				this.text = this.text.replace(/(https?:\/\/[^ ]+)|(https?:\/\/[.]+)$/g,"<a>$1</a>");
				this.text = this.text.replace(/@([a-zA-Z0-9_]+)/g,"<a onclick='set_input(\"@$1\")'>@$1</a>");
				this.text = this.text.replace(/#([a-zA-Z0-9_]+)/g,"<a onclick='set_input(\"#$1\")'>#$1</a>");
				
				var date = new Date().format('Y-m-d H:i:s',this.created_at);
				
				$("#results").prepend("<li class='list_box'><img src='"+this.profile_image_url+"'/><div><h4>"+this.text+"</h4><h5><span>"+date+"</span>&nbsp;<a id='"+this.id+"' onclick='set_input(\"@"+this.from_user+"\")'>"+this.from_user+"</a></h5></div></li>");
			});
		}
	});
*/
	
}

function status(){
	
	var text = $("#status_input").val();
	apiStatusCall({url:text});
	$("#status_input").val("");
	
/*	var status = $("#status_input").val();
	var id = status.match(/status\/([0-9]+)/)[1];
	$.ajax({
		url : "http://twitter.com/statuses/show/"+id+".json",
		dataType : "jsonp",
		success : function(json){
			$(json).each(function(){
				
				this.text = this.text.replace(/(https?:\/\/[^ ]+)|(https?:\/\/[.]+)$/g,"<a>$1</a>");
				this.text = this.text.replace(/@([a-zA-Z0-9_]+)/g,"<a onclick='set_input(\"@$1\")'>@$1</a>");
				this.text = this.text.replace(/#([a-zA-Z0-9_]+)/g,"<a onclick='set_input(\"#$1\")'>#$1</a>");
				
				var date = new Date().format('Y-m-d H:i:s',this.created_at);				
				$("#choices").append("<li class='list_box'><img src='"+this.user.profile_image_url+"'/><div><h4>"+this.text+"</h4><h5><span>"+date+"</span>&nbsp;<a id='"+this.id+"' onclick='set_input(\"@"+this.user.screen_name+"\")'>"+this.user.screen_name+"</a></h5></div></li>");

			});
		}
	});*/
}

function set_input(str){
	$("#word_input").val(str);
	return false;
}

var slideshow_item;
var page = 0;
function slideshow_init(){

	slideshow_item = $("#slideshow ul li").map(function(){
		return $(this);
	});
	
	slideshow_item.each(function(){
		this.css("display","none");
	});
	
	fixStyle();
	
	$(document).bind('keydown','j',function(){
		if(page == slideshow_item.length - 1)return;
		slideshow_item.each(function(){
			this.css("display","none");
		});
		slideshow_item[++page].css("display","block");
	});
	
	$(document).bind('keydown','k',function(){
		if(page == 0)return;
		slideshow_item.each(function(){
			this.css("display","none");
		});
		slideshow_item[--page].css("display","block");
	});
	
}

function fixStyle(){
	var width = $(window).width() * 0.8;
	var height = $(window).height();
	slideshow_item.each(function(){
		this.css("width",width);
		this.css("position","absolute");
		var top = (height - this.height()) / 2;
		this.css("top",top+"px");

	});
}

$.klass=function(a){var b=function(){this.init&&this.init.apply(this,arguments)};b.prototype=a;return b};

function _eventHandler( fn, thisImpl){
	return function(e){
		fn.apply(thisImpl,[e]);
	}
}

$.fn.extend({
	exbind: function( type, fn, thisImpl, data) {
		return this.each(function(){
			$(this).bind(type, data, function(){
				fn.apply(thisImpl,arguments);
			});
		});
	},
	exlive: function( type, fn, thisImpl) {
		return this.each(function(){
			$(this).live(type, function(){
				fn.apply(thisImpl,arguments);
			});
		});
	}
});

var extend = function(subc, superc) {
    var F = function() {};
    F.prototype=superc.prototype;
    
    subc.prototype.constructor=subc;
	subc.superclass=superc.prototype;
	for(var m in F.prototype){
		if(!subc.prototype[m])
			subc.prototype[m] = F.prototype[m];
	}
}

var Tool = $.klass({
	color : "c01",
	size : "f20",
	box : null,
	init : function(){
		this.box = $("#tools_box");
		$("input[name='font_size']").exbind("click",this.sizeClick,this);
		$("input[name='font_color']").exbind("click",this.colorClick,this);
		$("input[name='font_size']:first")[0].checked = true;
		$("input[name='font_color']:first")[0].checked = true;
		
		$(window).exbind("scroll",this.scroll,this);
	},
	scroll : function(e){
		
		var p = ($(window).height() - this.box.height()) / 2 + $(window).scrollTop();
		var diff = p - this.box.position().top;
		this.box.css("marginTop",(diff > 0 ? diff : 0));
//		this.box.animate({marginTop:top},500);
	},
	sizeClick : function(e){
		this.size = $(e.target).val();
	},
	colorClick : function(e){
		this.color = $(e.target).val();
	},
	getNode : function(){
		var node = document.createElement("span");
		node.className = this.size+" "+this.color;
		return node;
	},
	decoall : function(id){
		this.decoclear(id);
		this.elementApply(id);
	},
	decoclear : function(id){
		var elm = $("#"+id+" .tweet");
		var html = elm.html();
		var html = html.replace(/<SPAN[^>]*>|<\/SPAN[^>]*>/ig,'');
		elm.html(html);
	},
	elementApply : function(id){
		var elm = $("#"+id+" .tweet");
		var html = elm.html();
		var node = this.getNode();
		node.innerHTML = html;
		elm.html(node);
	},
	rangeApply : function(range){
		var node = this.getNode();
		if(jQuery.browser.msie){
			var container = document.createElement("div");
			container.appendChild(node);
			node.innerHTML = range.htmlText;
			try {
				range.pasteHTML(container.innerHTML);
				} catch (e) {}
		}else{
			range.surroundContents(node);			
		}
	}
});


var Deco = $.klass({
	elm : null,
	flag : false,
	init: function(elm){
		this.elm = elm;
		this.elm.exbind("mousedown",this.mousedown,this);
		this.elm.exbind("mouseup",this.mouseup,this);		
	},
	mousedown: function(e){
		this.flag = true;
	},
	mouseup: function(e){
		if(!this.flag)return;
		var selection = (window.getSelection) ? window.getSelection() : ((document.getSelection) ? document.getSelection() : (document.selection ? document.selection : null));
		var range =  jQuery.browser.msie ? selection.createRange() : selection.getRangeAt(0);

		if(window.getSelection){
			
			if(!range.collapsed && range.toString().length > 0 && 0 <= range.commonAncestorContainer.parentNode.className.toLowerCase().indexOf('editable')){
				tool.rangeApply(range);
			}
			
/*			console.log(range.commonAncestorContainer);
			console.log(range.cloneContents());
			if(range.startContainer.parentNode.tagName.toLowerCase() == 'a' || range.endContainer.parentNode.tagName.toLowerCase() == 'a'){
				return;
			}
			if(range.startContainer.parentNode.tagName.toLowerCase() == 'span' || range.endContainer.parentNode.tagName.toLowerCase() == 'span'){
				return;
			}
			
			console.log(range.commonAncestorContainer.parentNode.className);
			console.log(range.cloneContents());
*/
		}
	}
});

var Sort = $.klass({
	elm : null,
	t : null,
	flag : 0,
	init: function(){
		var impl = this;
		$(".sortable").sortable({
		    connectWith: ".list1, .list2",
		    cancel: '.ui-state-disabled'
		}).disableSelection()
		  .exbind("sortupdate",this.update,this)
		  .exbind("sortreceive",this.receive,this)
		  .exbind("sortclick",this.click,this)
		  .bind('sort',function(event, ui){impl.sort(event, ui);});
		this.elm = $("#choices");
	},
	receive : function(event, ui){
		ui.item.removeClass("selected_item");
	},
	click : function(event, ui){
		if(event.target.id == "results"){
			if($("#click_select").val() == 1){
				$("#choices").append($("#results li[id="+ui.item[0].id+"]").get());
			}else{
				ui.item.toggleClass("selected_item");
			}
		}
		
	},
	update : function(event, ui){
		this.clear();
	},
	sort : function(event, ui){
		var offset = this.elm.offset();
		var x = event.pageX - offset.left;
		var y = event.pageY - offset.top;
		if(0 < x && x < this.elm.width() && 0 < y && y < this.elm.height()){
			if(y < 100){
				if(this.flag != 1)this.up();
			}else if(this.elm.height() - 100 < y){
				if(this.flag != -1)this.down();
			}else{
				this.clear();
			}
		}else{		
			this.clear();
		}
	},
	clear : function(){
		this.flag = 0;
		clearInterval(this.t);
	},
	up : function(){
		var impl = this;
		this.flag = 1;
		clearInterval(this.t);
		this.t = setInterval(function(){
			impl.elm.scrollTop(impl.elm.scrollTop() - 10);
		},30);
	},
	down : function(){
		var impl = this;
		this.flag = -1;
		clearInterval(this.t);
		this.t = setInterval(function(){
			impl.elm.scrollTop(impl.elm.scrollTop() + 10);
		},30);
	}
});

var Menu = $.klass({
	type : null,
	elm : null,
	menu : null,
	html : null,
	init: function(type){
		this.type = type;
		
		this.elm = $("#"+this.type+"_action_button");
		this.elm.exbind('mousedown',this.mousedown,this);
		
		var inner = $("#"+this.type+"_action_button input");
		inner.exbind('mousedown',this.mousedown,this);
		inner.exbind("click",this.click,this);

		$("body").append("<div id='"+this.type+"_action_menu' style='display:none;position:absolute;'></div>");
		this.menu = $("#"+this.type+"_action_menu");
		this.menu.exbind('mousedown',this.mousedown,this);		

		$("body").exbind('mousedown',this.close,this);
		$(window).exbind('resize',this.close,this);
		
		
	},
	mousedown: function(e){
		e.stopPropagation();
//		e.preventDefault();
//		e.returnValue = false;
//		return false;
	},
	load: function(){
		var impl = this;
		var match = this.type.match(/^(.)(.+)$/);
		
		var method = "get"+match[1].toUpperCase()+match[2]+"Menu";
		
		$.get(baseuri+'/api/'+method+'/'+index,function (text){
			impl.html = text;
			impl.menu.html(impl.html);
		});
	},
	click: function(){
		if(!this.html){
			this.load();
		}
		if(this.menu.css("display") == "none")
			this.open();
		else
			this.close();
	},
	open: function(){
		this.menu.css("display", "block");
		this.menu.css("top", this.elm.offset().top + this.elm.height() + 5);
		this.menu.css("left", this.elm.offset().left);
	},
	close: function(){
		this.menu.css("display", "none");
	}
});


var tool = null;
$(document).ready(function(){
	
	new DescInput();
	
	if(action == "li"){
		new Menu("tweet");
		new Menu("amazon");
//		new CommentDeleter();
//		new TweetDeleter();
	}
	
	if(action == "create" || action == "edit"){
		new Sort();

		var h = $(window).height() - 100;
		$("#results").height(h);
		$("#choices").height(h);
		$("#choices").mousemove(function(e){
		});

		$("#word_input").val('ユーザ/キーワード（スペースで複数可）');
		$("#status_input").val('ユーザのつぶやきURLを張り付け');
		
		$(window).resize(function(){
			var h = $(window).height() - 100;
			$("#results").height(h);
			$("#choices").height(h);	
		});
		
		home();		
	}
	
	if(action == "deco"){
		tool = new Tool();
		$(".editable").each(function(){
			new Deco($(this));
		});
	}
	
	if(jQuery.browser.msie && "create,edit,deco".indexOf(action) > -1){		
		tb_show("ご利用のブラウザではリストの作成は行えません。",baseuri+'/reject?height=250&width=400&modal=true',false);
	}
	
/*	$("a[href^=#]").click(function(){
		console.log(this.hash);
		var hash = this.hash;
		if(!hash || hash == "#")return false;
		$($.browser.safari ? 'body' : 'html').animate({scrollTop: $(hash).offset().top}, 1500, "swing");
		return false;
	});*/
//	$("h2.title").wrap("<div class='title_box'></div>").css("position","absolute");
	
});

var CommentDeleter = $.klass({
	init: function(){
		if(userid){
			if(confirm("あなたのコメントを選択して削除することができます。続けますか？")){
				$(".comment_right").each(this.setting);
			}
		}else{
			openOAuth();
		}
	},
	setting: function(i,elm){
		var m = $(elm).attr("id").match(/comment_id_([0-9]+)_([0-9]+)/);
		if(m[1] != userid)return;
		
		$(elm).prepend("<label class='uiButton uiButtonDelete'><input id='comment_delete_button_"+i+"' type='button' value='削除'/></label>");
		$("#comment_delete_button_"+i).click(function(){
			if(confirm("このコメントを削除してよろしいですか？")){		
				$.get(baseuri+'/api/delComment/'+index,{comment_id:m[2]},function (text){
					alert("削除しました。");
					location.href = baseuri+'/li/'+text;
				});
			}
		});
	}
});

var TweetDeleter = $.klass({
	init: function(){
		if(userid){
			if(confirm("まとめの中のあなたのつぶやきを選択して削除することができます。続けますか？")){
				$(".list_body").each(this.setting);
			}
		}else{
			openOAuth();
		}
	},
	setting: function(i,elm){
		var m = $(elm).attr("id").match(/tweet_id_([0-9]+)_([0-9]+)/);
		if(!m || m[1] != userid)return;
		
		$(elm).prepend("<label class='uiButton uiButtonDelete'><input id='tweet_delete_button_"+i+"' type='button' value='削除'/></label>");
		$("#tweet_delete_button_"+i).click(function(){
			if(confirm("権利者が削除を行ったことが明記されます。元に戻すことはできません。削除してもよろしいですか？")){
				$.get(baseuri+'/api/delTweet/'+index,{index:i,tweet_id:m[2]},function (text){
					alert("削除しました。");
					location.href = baseuri+'/li/'+text;
				});
			}
		});
	}
});

var AmazonDeleter = $.klass({
	init: function(){
		$(".amazon_infomation").each(this.setting);
	},
	setting: function(i,elm){
		var m = $(elm).attr("id");
		$(elm).prepend("<label class='uiButton uiButtonDelete'><input id='amazon_delete_button_"+i+"' type='button' value='削除'/></label>");
		$("#amazon_delete_button_"+i).click(function(){
			if(confirm("この商品を削除してよろしいですか？")){
				$.get(baseuri+'/amazon/del/'+index,{ti:m},function (text){
					alert("削除しました。");
					$(elm).prev().remove();
					$(elm).remove();
				});
			}
		});
	}
});

var favDeleter = $.klass({
	init: function(){
		$(".info_box").each(this.setting);
	},
	setting: function(i,elm){
		var m = $(elm).attr("id").match(/list_id_([0-9]+)/);
		$(elm).prepend("<label class='uiButton uiButtonDelete'><input id='fav_delete_button_"+i+"' type='button' value='削除'/></label>");
		$("#fav_delete_button_"+i).click(function(){
			if(confirm("このまとめをお気に入りから削除してよろしいですか？")){
				$.get(baseuri+'/api/delFavorite/'+m[1],function (text){
					alert("削除しました。");
					$(elm).remove();
				});
			}
		});
	}
});

var DescInput = $.klass({
	
	init: function(){
		var impl = this;
		$(".desc_input").live("focus",function(){
			impl.focus.apply(impl,arguments);
		});
		$(".desc_input").live("blur",function(){
			impl.blur.apply(impl,arguments);
		});
	},
	focus: function(e){
		var elm = $(e.target);
		if(elm.val() == elm.attr("title")){elm.val("");}
		elm.css("color","#000");
	},
	blur: function(e){
		var elm = $(e.target);
		if(!elm.val().length){
			elm.val(elm.attr("title"));
			elm.css("color","#999");
		}
	}
});

var Amazon = $.klass({
	form: null,
	init: function(){
	},
	scroll: function(){
		$(window).scrollTop($(".amazon_box").offset().top);
	},
	check: function(asin){
		var elm = $("#amazon_item_"+asin);
		if($("#amazon_item_"+asin).children().attr("checked")){
			elm.children().attr("checked",false);
			elm.next().next().css("color","black");
//			$("#amazon_item_"+asin).attr("checked",false).next().next().css("color","black");
		}else{
			elm.children().attr("checked",true);
			elm.next().next().css("color","red");
		}
//			$("#amazon_item_"+asin).attr("checked",true).next().next().css("color","red");
	},
	checkLogin: function(){
		if(!userid){
			openOAuth();
			return false;
		}
		return true;
	},
	searchEdit: function(){
		if(this.checkLogin())
			$("#amazon_content_box").load(baseuri+'/amazon/search_edit/'+index+'?rand='+(new Date).getTime());
	},
	deleteEdit: function(){
		if(this.checkLogin()){
			$("#amazon_content_box").load(baseuri+'/amazon/stop_edit/'+index+'?rand='+(new Date).getTime(),function(){
				new AmazonDeleter();
				
			});		
		}
//			$("#amazon_content_box").load(baseuri+'/amazon/delete_edit/'+index+'?rand='+(new Date).getTime());
	},
	stopEdit: function(){
		$("#amazon_content_box").load(baseuri+'/amazon/stop_edit/'+index+'?rand='+(new Date).getTime());		
	},
	search: function(form){
		this.form = form;
		var param = $(this.form).serialize();
		param += "&page=1";
		$.post(this.form.action+'?rand='+(new Date).getTime(),param,function (text){
			if(!text.indexOf("error")){
				alert("失敗しました。");
			}else{
				$("#amazon_result_box").html(text);
			}
		});
	},
	page: function(page){
		var param = $(this.form).serialize();
		param += "&page="+page;
		$.post(this.form.action+'?rand='+(new Date).getTime(),param,function (text){
			$("#amazon_result_box").html(text);
		});
		
	},
	add: function(form){
		var param = $(form).serialize();
		$.post(form.action+'?rand='+(new Date).getTime(),param,function (text){
			if(!text.indexOf("error")){
				if(text.indexOf("_02") > 0)
					alert("登録したいアイテムを選択してください。");
				else if(text.indexOf("_03") > 0)
					alert("正しいアフィリエイトIDを入力してください。");
			}else{
				am.stopEdit();
			}
		});
	},
	del: function(form){
		
		if(confirm("選択したアイテムを削除してよろしいですか？")){
			var param = $(form).serialize();
			$.post(form.action+'?rand='+(new Date).getTime(),param,function (text){
				if(!text.indexOf("error"))
					alert("削除に失敗しました。");
				else
					$('#amazon_item_'+text).remove();
			});
		}
	}
});
var am = new Amazon();

var tagManager = function(){};
tagManager.prototype = {
  initialize: function(){
  	this._tags = new Array();
  	this._id = null;
  },
  startTagEdit: function(id){
  	this._id = id;
  	$("#tag_box_"+id).load(baseuri+'/tag/edit/'+this._id+'?rand='+(new Date).getTime());
  },
  addTagsAndRefresh:function(form,id){
 	var param = $(form).serialize();
 	if(param.length <= 3)return false;
	$.post(form.action+'?rand='+(new Date).getTime(),param,function (){
			tm.refreshTags(id);
		}
	);
	return false;
  },
  refreshTags:function(id){
	$('#tag_box_'+id).load(baseuri+'/tag/refresh/'+id+'?rand='+(new Date).getTime());
  },
  insertTagChange:function(form,id,tagid){
	var param = $(form).serialize();
	$.post(form.action,param,function (){
			$('#tag_box_'+id+' #tag_'+tagid).remove();
		}
	);
	return false;
  }
}

var tm = new tagManager();
tm.initialize();
