
jQuery(document).ready(function() {

	var getVisitorsFunction = function(effect) {
		var d = new Date;
		
		jQuery.get(
			'/a/visitors.api/' + d.getTime(),
			{ 'of': curBlogsterProfile.username,
			  'num':5 },
			function(json) {
				var html = '';
				var a;
				var preload;
				
				if(json.visitors.length) {
					jQuery(json.visitors).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-visitors').prepend(html);

				if(effect) {
					var iter = 1;
					jQuery('#profile-right-visitors-loading').fadeOut();
					jQuery('#profile-right-visitors div.user-icon').each(function() {
						var element = this;
						setTimeout(function() { jQuery(element).slideDown(); },(iter*50));
						++iter;
					});
				} else {
					jQuery('#profile-right-visitors-loading').fadeOut();
					jQuery('#profile-right-visitors div.user-icon:visible').remove();
					jQuery('#profile-right-visitors div.user-icon').show();
				}
	
			},'json'		
		);
	}
	
	setTimeout(function() {
		getVisitorsFunction(false);
	},300);
	
//	setInterval(function() {
//		getVisitorsFunction(false);
//	},30000);
});
