
<?php if (is_null(Mage::registry('blogId'))): ?>
    <?php echo Mage::helper('designer/messages')->error('Invalid blog id.') ?>
<?php else: ?>
    <?php $_buffer = Mage::getModel('designer/buffer') ?>

    <?php if ($_buffer->capture('header')): ?>
        <?php echo $this->__('Catalog Advanced Search') ?>
    <?php endif ?>

    <?php if ($_buffer->capture('content')): ?>
        <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
        <?php if ($this->getResultCount()): ?>

            <?php if (($_resultBuffer = Mage::getModel('designer/buffer')) && $_resultBuffer->capture('success')): ?>
                <p><?php echo $this->helper('catalogsearch')->__('%d item(s) were found using the following search criteria', $this->getResultCount()) ?></p>
                <div class="advanced-search-summary">
                    <?php $searchCriterias = $this->getSearchCriterias() ?>
                    <?php foreach (array('left', 'right') as $side): ?>
                        <?php if (array_key_exists($side, $searchCriterias) && $searchCriterias[$side]): ?>
                            <ul>
                                <?php foreach($searchCriterias[$side] as $criteria): ?>
                                    <li><strong><?php echo $this->htmlEscape($this->helper('catalog')->__($criteria['name'])); ?>:</strong> <?php echo $this->htmlEscape($criteria['value']); ?></li>
                                <?php endforeach ?>
                            </ul>
                        <?php endif ?>
                    <?php endforeach ?>
                    <?php if ($this->getResultCount()): ?>
                        <?php echo $this->helper('catalogsearch')->__("Don't see what you're looking for?"); ?>
                        <a href="<?php echo $this->getFormUrl() ?>"><?php echo $this->helper('catalogsearch')->__('Modify your search') ?></a>
                    <?php endif ?>
                </div>
                <?php echo Mage::helper('designer/messages')->success($_resultBuffer->complete()) ?>
            <?php endif ?>

        <?php else: ?>
            <?php if (($_noItemsBuffer = Mage::getModel('designer/buffer')) && $_noItemsBuffer->capture('error')): ?>
                <?php echo $this->helper('catalogsearch')->__('No items were found using the following search criteria.');?>
                <a href="<?php echo $this->getFormUrl() ?>"><?php echo $this->helper('catalogsearch')->__('Modify your search') ?></a>
                <?php echo Mage::helper('designer/messages')->warning($_noItemsBuffer->complete()) ?>
            <?php endif ?>
        <?php endif ?>

        <?php if($this->getResultCount()): ?>
            <?php echo $this->getProductListHtml() ?>
        <?php endif ?>
        <?php $this->getSearchCriterias(); ?>
    <?php endif ?>

    <?php
        $_blogTpl = Mage::helper('designer')->createTemplate('blog', Mage::registry('blogId'));
        $_blogTpl->setArticles($_buffer->complete());
        echo $_blogTpl->toHtml();
    ?>

<?php endif ?>