gusto = window.gusto || {};
gusto.fb_comments = {
	tries: 0,
	max_tries: 8,
	try_delay: 500,
	
	init: function() {
	    // reset the # of tries, becasue this may be a refresh rather than a new page render
	    gusto.fb_comments.tries = 0;
		$('#comment_count span.count').hide();
		$('body.js').ready(function() {
			setTimeout('gusto.fb_comments.check_cmnt_cnt()', gusto.fb_comments.try_delay);
		});
	},
	
	check_cmnt_cnt: function() {
		var cnt = $('#comment_count span.fb_comments_count').html();
		if (cnt == null) {
			gusto.fb_comments.tries++;
			if (gusto.fb_comments.tries <= gusto.fb_comments.max_tries) {
				setTimeout('gusto.fb_comments.check_cmnt_cnt()', gusto.fb_comments.try_delay);
			}
		}
		else {
			cnt = parseInt(cnt);
			if (cnt > 0) {
                gusto.fb_comments.tries = 0;
				$('#comment_count span.count').show().css('display', 'inline');
			}
		}
	}
};

if (window.jQuery) {
    $('#comment_count').ready(function() {
    	gusto.fb_comments.init();
    });
}
