var Papershow = {
    pid : undefined,
    init : function(pid,authorized) {
	Papershow.pid = pid;
	authorized ? $('#buttons').show() : $('#buttons').hide();
	authorized ? $('#buttons-login').hide() : $('#buttons-login').show();
    },
    auth_tw : function() {
	Papershow.auth('twitter');
    },
    auth_fb : function() {
	Papershow.auth('facebook');
    },
    auth : function(type) {
	window.open('/auth/'+type,'auth','width=640,height=480');
    },
    comment : function() {
	$('#t-comment').attr('disabled','disabled');
	$('#a-add').hide();
	$.ajax({type:'POST',
		url:'/comment',
		data : $.param({comment:$('#t-comment').val(),pid:Papershow.pid}),
		success: function(ret) {
		    ret = JSON.parse(ret);
		    if(ret.comment) {
			// insert
			$('#ul-commentlist').append('<li><div class="name"><a name="'+ret.commentid+'" href="'+ret.url+'" target="_blank">'+(ret.id||'<i>link</i>')+'</a><br />'+ret.name+'</div><div class="img"><a href="'+ret.url+'" target="_blank"><img src="'+ret.picture+'" width="48" height="48" /></a></div><div class="comment"><div class="comment-inner">'+ret.comment+'</div></div></li>');
		    }
		    $('#t-comment').removeAttr('disabled').val('');
		    $('#a-add').show();
		}});
    },
    cancelcomment : function() {
    },
    auth_postback : function(ret) {
	$('#buttons').show();
	$('#buttons-login').hide();
	$('#a-add').attr('href','javascript:Papershow.comment();');
	$('#ul-commentlist').after('<div id="comment"><div class="name">'
			 + '<a href="'+ret.url+'" target="_blank">'+(ret.id||'<i>link</i>')+'</a><br />'+ret.name+'</div>'
			 + '<div class="img"><a href="'+ret.url+'" target="_blank"><img src="'+ret.picture+'" width="48" height="48"/></a></div>'
			 + '<div class="comment"><div class="comment-inner"><textarea id="t-comment"></textarea></div></div></div>');
    }

};
//$(Papershow.init);
