<?php
//@*--


require_once "Mage/Core/Block/Text/List.php";

class Theme_Designer_Block_Core_Text_List extends Mage_Core_Block_Text_List
{
    public function getSortedChildren()
    {
        $blockName = $this->getNameInLayout();
        $blockId = $this->getBlockId();
        $blockTemplate = $this->getBlockTemplate();
        $customList = Mage::registry('designer_blocks');

        if (!$customList || ($blockName != 'left' && $blockName != 'right'))
            return parent::getSortedChildren();


        $sortedChildren = array();

        foreach ($customList as $name => $info) {
            if ($info['position'] != $blockName || !($block = $this->getLayout()->getBlock($name))) continue;
            $block->setBlockId($blockId);
            $block->setBlockTemplate($blockTemplate);
            $sortedChildren[] = $name;
        }

        foreach ($this->_sortedChildren as $child) {
            if (array_key_exists($child, $customList)) continue;
            if ($block = $this->getLayout()->getBlock($child)) {
                $block->setBlockId($blockId);
                $block->setBlockTemplate($blockTemplate);
            }
            $sortedChildren[] = $child;
        }

        return $sortedChildren;
    }
}

//--*@