/**
 * @author absolute
 */
var commentPagerSel = '#comments_pager';
commentReloadPager =  function(i, n) {
	$(commentPagerSel).pager({ pagenumber: i, pagecount: n, nonavbutton: true, buttonClickCallback: function(pagenum) { commentGetPage(pagenum); } });
},
		
commentGetPage = function(pagenum) {
	showCommentsOverlay();
	$.ajax({
		url: comment_json_url,
		dataType: 'json',
		data: { "page":pagenum, "sidx": 'created_at', "sord": 'desc', 'uid': 'all'},
		type: 'get',
		async: true,
		cache: true,
		complete: function(request, status) {
			hideCommentsOverlay();
		},
		success: function(data) {
			if (data['items']) {
				$("#comments_display #comments").html('');
				$.each(data['items'], function(key, item) {
					var listItem = $("#comments_display #comments").append('<div class="comment"></div>').find('.comment:last');
					var username = (item['username'] != 'anonymous') ? item['username'] : '';
					var visitor_name = (item['visitor_name']) ? item['visitor_name'] : '';
					listItem.append('<div class="avatar"></div>'+
						'<div class="commenter_name"><a href="'+view_user_url.replace('targetuser', item['username'])+'">'+username+'</a>'+
							'<span>'+visitor_name+'</span></div>'+
						'<div class="content">'+item['content']+'</div>'+
						'<div class="footer">'+item['created_at']+'</div>');
				});
				commentReloadPager(pagenum, data['page_count']);
			}
			$('#display_title').html('Comments (' + data['items_count']+')');
		},
	});
}
showCommentsOverlay = function() {
	$("#comments_display #comments").fadeOut('fast');
	$("#comments_list_loading").show();
}
hideCommentsOverlay = function() {
	$("#comments_list_loading").hide();
	$("#comments_display #comments").fadeIn('fast');
}
commentGetPage(1);


