DOM elements not behaving as expected.
===

I seem completely unable to solve this problem.  When I run this loop:

    for ( var i=0; i < 10; i++ ) {
    					var $items = $(balls()); 
    					console.log($items);
    					$container.imagesLoaded(function(){
    						$container.append( $items ).masonry( 'appended', $items, true );
    					});
    				}

The first item, and the last item are fine, they look like: 

    <div class="box masonry-brick" id="resultBox" style="top: 0px; position: absolute; left: 0px; "><div><p>NAME</p><img src="pathtoimage.jpg"><boxbottom id="boxBottom">NUM%</boxbottom></div></div>

But the other 8 aren't fine, they look like: 

    <div class="box" id="resultBox""><div><p>NAME</p><img src="pathtoimage.jpg"><boxbottom id="boxBottom">NUM%</boxbottom></div></div>

So there's no 'masonry-brick' class being applied, which means they aren't getting processed by masonry.  

Also relevant is: 

    function balls(){
    	var boxes = [];
    	$iterator -= 1;
        var box = document.createElement('div'),
            spacerdiv = document.createElement('div'),
            para = document.createElement('p'),
            img = document.createElement('img'),
            boxBottom = document.createElement('boxBottom'),
            name = document.createTextNode( $test[$iterator][1][2]['name'] ),
            percentage = document.createTextNode(Math.floor($test[$iterator][0]*100)+'%');
        
        box.className = 'box';
        box.id = 'resultBox';
        img.src= 'scripts/php/timthumb.php?src='+$test[$iterator][2]+'&q=100&w=300';
        boxBottom.id='boxBottom';
    
        box.appendChild( spacerdiv );
        spacerdiv.appendChild( para);
        para.appendChild(name);
        spacerdiv.appendChild( img );
        spacerdiv.appendChild(boxBottom);
        boxBottom.appendChild(percentage);
        // add box DOM node to array of new elements
     	return box;
    }

I think there's something odd going on with the DOM model here, perhaps because the elements are being created dynamically?  
I've been at this all day, and I'm getting burned out...