Accordion with AJAXed content

Accordion with AJAXed content

Hey guys!

I am using an accordion to list an array fetched from a MySQL-table joined to another table. Currently I am fetching Brand.id and Brand.title and also a grouped count of how many cigars from the table Cigar are linked to each Brand. I call this last field simply "cigars"

In my view (I am using CakePHP) I have this code:

<div id="accordion">
    <?php foreach($brands as $brand): ?>
        <h3><a href="#"><?php echo $brand['Brand']['title'].' ('.$brand[0]['cigars'].')'; ?></a></h3>
            <div>
                <?php echo $html->link('Show', array('controller' => 'cigars', 'action' => 'index', 'id' => $brand['Brand']['id'])); ?> cigars.<br>
                Number of cigars: <?php echo $brand[0]['cigars']; ?>
            </div>
    <?php endforeach; ?>
</div>

This is just something to start working on, I eventually want to have nothing in the div and fill it with AJAXhtml from a function in my controller. I havn't gotten so far on the AJAX though since I ran into a wall, and thus we come to my question. This is my script so far:

$(function() {
    $("#accordion").accordion({
        collapsible: true,
        active: false,
        animated: false,
        change: function(event, ui) {
            $(ui.newContent).html('Ajax');
        }
    });
});

I guess the .html should be switched to .load later, but I just put the html there to have something to play around with. Now what would be the best way here to make sure I get the correct Brand.id along with my AJAXrequest? How, in the script, do I fetch the id that I have in the html of the accordion?

All help is greatly appreciated!