/**
 * @author absolute
 */
var ArticlesPagerSel = '#articles_pager';
ArticlesReloadPager =  function(i, n) {
	$(ArticlesPagerSel).pager({ pagenumber: i, pagecount: n, nonavbutton: true, buttonClickCallback: function(pagenum) { ArticlesGetPage(pagenum); } });
},
		
ArticlesGetPage = function(pagenum) {
	showArticlesOverlay();
	$.ajax({
		url: article_json_url,
		dataType: 'json',
		data: { "page":pagenum, "sidx": 'created_at', "sord": 'desc', 'uid': 'all'},
		type: 'get',
		async: true,
		cache: true,
		complete: function(request, status) {
			hideArticlesOverlay();
		},
		success: function(data) {
			if (data['items']) {
				$("#articles").html('');

				$.each(data['items'], function(key, item) {
					var html = '<div class="articlelist_item"><span class="articles_listitem_list">●</span>'+
					'<span><a href="'+view_article_url_sample.replace('9999', item['id'])+'">'+item['title']+'</a></span>'+
					'<span class="posted"> - ' +item['created_at']+'</span>&nbsp;&nbsp;&nbsp;'+
					'<a class="posted" href="'+view_user_url_sample.replace('targetuser',item['author'])+'">[ '+item['author']+' ]</a></div><div class="separator"></div>';
					var listItem = $("#articles").append(html);
				});
				$('#articles').find('.articles_listitem:last').removeClass('articles_listitem').addClass('articles_listitem_last');
				ArticlesReloadPager(pagenum, data['page_count']);
			}
		},
	});
}
showArticlesOverlay = function() {
	$("#articles").fadeOut('fast');
	$("#articles_loading").fadeIn('fast');
}
hideArticlesOverlay = function() {
	$("#articles_loading").fadeOut('fast');
	$("#articles").fadeIn('fast');
}
ArticlesGetPage(1);


