Shopping cart, items count

Hi there !
I have two problems to solve with my cart. I have a multisite installation and i modified the shopping cart widget so that it does not show the actual elements contained in that cart but only the number of items.
My first problem is : it seems the method i am using to get the items count is not working well. Here is the code.

$global_cart = $mp->get_cart_contents(true);

if (!$mp->global_cart) $selected_cart[$blog_id] = $global_cart[$blog_id];
else $selected_cart = $global_cart;

$items_count= 0;
foreach($selected_cart as $blog)
{
foreach($blog as $product)
{
if (count($product) > 0) $items_count++;
}
}

The second problem is :
when i add an item to the cart, the number of item is not updated. I understand i have to send some information to the AJAX interface and be able to update the "item count" field when the AJAX response comes up but i have not clue how to do that.

Thanks for your help.
Cyprien