
/* specific style based functions for populating data on only the index page of
 * the main site. */
//. 20091028 - bob

function localFetchHappening() {

	jQuery('#index-happening-now').html('<div class="loadingbar">Loading...</div>');

	jQuery.get(
		'/a/index/comments.api/' + getTime(),
		{ },
		function(json) {

			var html = new String;
			var odd = false;
			
			jQuery(json.data).each(function(){
				
				html +=
					'<li style="overflow:hidden;clear:both;"' + ((odd)?(' class="alt"'):('')) + '>'+
					'<img style="height:34px;width:34px;float:left;margin:3px 0px 4px 3px;" src="' + this.comment.avatarURL + '" />'+
					'<div class="post-link" style="float:right;width:205px;margin-bottom:4px;">'+
					'<a href="' + this.comment.profileURL + '" class="post">' + this.comment.username + '</a> '+
					'commented on '+
					'<a href="' + this.post.url + '" class="post">' + this.post.title + '</a><br />'+
					'</div>'+
					'</li>';
					
				odd = !odd;

				
				return;
			});
			
			jQuery('#index-happening-now').html('<ul class="post">' + html + '</ul>');

			return;
		},'json'
	);

	return;
}

function localFetchUsers() {

	jQuery.get(
		'/a/index/users.api/' + getTime(),
		{ },
		function(json) {

			var iter = 0;
			var html = new String;
			jQuery(json.online).each(function(){
				html +=
					'<div class="user-icon" style="width:73px;">'+
					'<a href="' + this.profileURL + '">'+
					'<img src="' + this.avatarURL + '" alt="" style="width:65px;height:65px;" />'+
					'</a><br />'+
					'<a href="' + this.profileURL + '">' + bCommon.breakLineWrap(this.username) + '</a>' +
					'</div>';
			});
			jQuery('#index-user-online').html(html);
			jQuery('#index-user-online-link').show();
			
			html = '';
			json.newest = json.newest.slice(0,8);
			jQuery(json.newest).each(function(){
				html +=
					'<div class="user-icon" style="width:73px;">'+
					'<a href="' + this.profileURL + '">'+
					'<img src="' + this.avatarURL + '" alt="" style="width:65px;height:65px;" />'+
					'</a><br />' +
					'<a href="' + this.profileURL + '">' + bCommon.breakLineWrap(this.username) + '</a>' +
					'</div>';
			});
			jQuery('#index-user-newest').html(html);

			html = '';
			jQuery(json.commenters).each(function(){
				html +=
					'<div class="user-icon" style="width:40px;">'+
					'<a href="' + this.profileURL + '">'+
					'<img src="' + this.avatarURL + '" alt="" style="width:32px;height:32px;" />'+
					'</a></div>';
			});
			jQuery('#index-user-commenters').html(html);

		},'json'
	);

	return;
}

function localFetchPosts() {

	jQuery.get(
		'/a/index/posts.api/' + getTime(),
		{ },
		function(json) {

			var html = new String;

			jQuery(json.newest).each(function(){
			
				html +=
					'<tr class="post-link">' +
					'<td><div class="user-icon" style="width:40px"><a href="' + this.url + '"><img src="' + this.avatarURL + '" alt="" style="width:32px;height:32px" /></a></div></td>'+
					'<td><a href="' + this.url + '">' + this.title + '</a><br />by ' + this.username + '</td>'+
					'</tr>';
			
				return;
			});
			jQuery('#index-post-newest').html(html);
			
			return;
		},'json'
	);

	return;
}

jQuery(document).ready(function(){
	//. doing things for this page load.
	
	localFetchHappening();
	setInterval(localFetchHappening,60000);
	
	localFetchUsers();
	localFetchPosts();
	
	return;
});

