function ahc_getAdminBarCounter() {
    jQuery.ajax({
        type: 'GET',
        url: ahc_ajax.ajax_url,
        data: {
            'action': 'ahcpro_countOnlineusers_adminbar',
        },
        success: function(data) {
            data = jQuery.parseJSON(data);
                var newCount = parseInt(data);

                // Original widget counter
                var oldCounter = parseInt(jQuery('#onlinecounter').text() || 0);
                jQuery('#onlinecounter').text(newCount);

                // Admin bar counter
                var adminCounter = parseInt(jQuery('#onlinecounter_adminbar').text() || 0);
                jQuery('#onlinecounter_adminbar').text(newCount);

                // Remove old classes
                jQuery('#up-down').removeClass('increase_counter decrease_counter');

                // Add new class depending on trend
                if (newCount > oldCounter) {
                    jQuery('#up-down').addClass('increase_counter');
                } else if (newCount < oldCounter) {
                    jQuery('#up-down').addClass('decrease_counter');
                }
        },
        error: function(data) {
            console.log('Admin bar counter error:', data);
        }
    });
}

jQuery(document).ready(function() {
    // Call immediately on page load
    ahc_getAdminBarCounter();
    
    // Update every 60 seconds 
    setInterval(ahc_getAdminBarCounter, 60000);
});