
var xpBlog = {

	sort: 'newest',
	curPage: 1,
	initHTML: '',
	
	init: function() {
	
		xpBlog.render(1);
	
		return;
	},

	render: function(page){

		if(page) xpBlog.curPage = page;
		
		bCommon.windowScrollToTop();
		jQuery('#explore-content-table-loading').show();
		jQuery('#explore-content-table tbody').html('');
		

		jQuery.get(
			'/a/blog-posts-global.api/' + getTime(),
			{ 'type':xpBlog.sort,'page':xpBlog.curPage,'num':50,'special':'true' },
			function(json) {
			
				var iter = json.offset + 1;
				var html = new String;

				jQuery(json.posts).each(function(){
					html += 
						'<tr>'+
						'<td valign="top" class="rank">' + iter + '</td>'+
						'<td valign="top" style="width:100px;"><div class="user-icon"><a href="' + this.url + '"><img src="' + this.avatarURL + '" alt="" /></a></div></td>' +
						'<td valign="top">' +
						'<h2><a href="' + this.url + '">'+ this.title + '</a></h2>' +
						'<div class="info">' + this.date + ' by <a href="' + this.profileURL + '">' + this.username + '</a> ';

					if(xpBlog.sort == 'commented') {
						html += '&bull; ' + this.comments + ' comment' + ((this.comments == 1)?(''):('s'));
					} else if(xpBlog.sort == 'rating') {
						html += '&nbsp; &nbsp; <span style="float:right">'; 
						for(var a = 0; a < this.stargfx; a++) {
							html += '<img src="/share/gfx/star-tiny.png" alt="" style="vertical-align:baseline;" />';
						}
						html += ' (' + this.ratecount + ' rating' + ((this.ratecount == 1)?(''):('s')) + ')</span>';
					}

					html +=
						'</div>' +
						'<div class="summary">' + this.summary + '</div>' +
						'</td>'+
						'</tr>';
						
					++iter;
					return;
				});
				
				var pagetool = new bPageTool(json.page,json.pageCount,xpBlog.render);

				jQuery('#explore-content-table-loading').hide();
				jQuery('#explore-content-table tbody').html(html);
				jQuery('#explore-pagetool').html(pagetool.get());

			},'json'
		);

		return;
	}

}

