<?php

$_dimHelper = Mage::helper('configurableswatches/swatchdimensions');
$_swatchInnerWidth = $_dimHelper->getInnerWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER);
$_swatchInnerHeight = $_dimHelper->getInnerHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER);
$_swatchOuterWidth = $_dimHelper->getOuterWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER);
$_swatchOuterHeight = $_dimHelper->getOuterHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER);
$_nofollow = Mage::helper('catalin_seo')->getNofollow();
?>

<ol class="configurable-swatch-list">
    <?php foreach ($this->getItems() as $_item): ?>
        <?php
        $_hasItems = ($_item->getCount() > 0);
        $_label = $_item->getLabel();
        $_swatchUrl = Mage::helper('configurableswatches/productimg')->getGlobalSwatchUrl($_item, $_label, $_swatchInnerWidth, $_swatchInnerHeight);
        $_hasImage = (!empty($_swatchUrl));
        $_linkClass = 'swatch-link' . (($_hasImage) ? ' has-image' : '');
        $_linkCss = 'height:' . $_swatchOuterHeight . 'px; ' . ((!$_hasImage) ? 'min-' : '') . 'width:' . $_swatchOuterWidth . 'px;';
        $_lineHeight = $_swatchOuterHeight + 2;
        ?>
        <li<?php if ($_hasImage){ echo ' style="line-height: ' . $_lineHeight . 'px;"'; } ?>>
            <?php if ($_hasItems): ?>
                <a href="<?php echo $this->urlEscape(($_item->isSelected()) ? $_item->getRemoveUrl() : $_item->getUrl()) ?>" class="<?php echo $_linkClass ?>" <?php echo $_nofollow; ?>>
            <?php else: ?>
                <span class="<?php echo $_linkClass ?>">
            <?php endif; ?>
                <span class="swatch-label"<?php if ($_hasImage){ echo ' style="' . $_linkCss . '"'; } ?>>
                    <?php if ($_hasImage): ?>
                        <img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_label; ?>" title="<?php echo $_label ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" />
                    <?php else: ?>
                        <?php echo $_label; ?>
                    <?php endif; ?>
                </span>
                <?php if ($this->shouldDisplayProductCount()): ?>
                    <span class="count">(<?php echo $_item->getCount() ?>)</span>
                <?php endif; ?>
            <?php if ($_hasItems): ?>
                </a>
            <?php else: ?>
                </span>
            <?php endif; ?>
        </li>
    <?php endforeach ?>
</ol>
