
jQuery(document).ready(function() {

	var getFriendsFunction = function(effect) {
		var d = new Date;
	
		jQuery.get(
			'/a/friends.api/' + d.getTime(),
			{ 'of': curBlogsterProfile.username,
			  'sort':'online',
			  'limit':5 },
			function(json) {
				var html = '';
				var a;
				var preload;
						
				jQuery(json.list).each(function(){
					html += '<div style="display:none;" class="user-icon">' +
					        '<a href="' + this.profileURL + '"><img src="' + this.avatarURL + '" alt="user-icon" /></a><br />' + 
					        '<a href="' + this.profileURL + '">' + this.username + '</a></div>';

				});
				
				jQuery('#profile-right-friends').prepend(html);
	
				if(effect) {
					var iter = 1;
	
					jQuery('#profile-right-friends-loading').fadeOut();
					jQuery('#profile-right-friends div.user-icon').each(function() {
						var element = this;
						setTimeout(function() { jQuery(element).slideDown(); },(iter*50));
						++iter;
					});
				} else {
					jQuery('#profile-right-friends-loading').fadeOut();
					jQuery('#profile-right-friends div.user-icon:visible').remove();
					jQuery('#profile-right-friends div.user-icon').show();
				}		
			
			},'json'		
		);
	}

	setTimeout(function() {
		getFriendsFunction(false);
	},300);
	
//	setInterval(function() {
//		getFriendsFunction(false);
//	},30000);
});
