<?php
/**
 * Avalanche for Magento 1.8+
 * Designed by Fast Division (http://fastdivision.com)
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the EULA
 * that is bundled with this package in the file license.txt.
 * It is also available through the world-wide-web at this URL:
 * http://fastdivision.com/legal/license.txt
 *
 * @author     Fast Division
 * @version    1.5.0
 * @copyright  Copyright 2013 Fast Division
 * @license    http://fastdivision.com/legal/license.txt
 */
?>
<div class="white-box">
	<h1>
		<?php echo $this->__('Compare Products') ?>
		<div class="call-to-action">
			<a href="#" onclick="window.print(); return false;" class="action-button"><span><?php echo $this->__('Print This Page') ?></span></a>
		</div>
	</h1>
	<div class="white-box-inner">
		<?php $_total=$this->getItems()->getSize() ?>
		<?php if($_total): ?>
		    <table class="data-table compare-table" id="product_comparison">
		    <?php $_i=0 ?>
		    <?php foreach($this->getItems() as $_item): ?>
		        <?php if($_i++%10==0): ?>
		            <col width="1" />
		        <?php endif; ?>
		            <col width="<?php echo floor(100/$_total); ?>%" />
		    <?php endforeach; ?>
		        <tbody>
		            <tr class="product-shop-row">
		            <?php $_i=0 ?>
		            <?php foreach($this->getItems() as $_item): ?>
		                <?php if($_i++%10==0): ?>
		                    <th>&nbsp;</th>
		                <?php endif; ?>
		                <td>
							<a href="#" class="compare-remove-list-item ir" onclick="removeItem('<?php echo $this->helper('catalog/product_compare')->getRemoveUrl($_item) ?>');" title="<?php echo $this->__('Remove This Item') ?>"><?php echo $this->__('Remove This Item') ?></a>
		                    <a class="product-image" href="#" onclick="setPLocation('<?php echo $this->getProductUrl($_item) ?>', true)" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->stripTags($_item->getName(), null, true) ?>" /></a><br>
		                    <a href="#" onclick="setPLocation('<?php echo $this->getProductUrl($_item) ?>', true)" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>" class="product-name"><?php echo $this->helper('catalog/output')->productAttribute($_item, $_item->getName(), 'name') ?></a>
		                    <?php echo $this->getReviewsSummaryHtml($_item, 'short') ?>
		                    <?php echo $this->getPriceHtml($_item, true, '-compare-list-top') ?>
		                    <?php if($_item->isSaleable()): ?>
		                        <br><p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
		                    <?php else: ?>
		                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
		                    <?php endif; ?>
		                </td>
		            <?php endforeach; ?>
		            </tr>
		        </tbody>
		        <tbody>
		        <?php foreach ($this->getAttributes() as $_attribute): ?>
		            <tr>
		                <?php $_i=0 ?>
		                <?php foreach($this->getItems() as $_item): ?>
		                <?php if($_i++%10==0): ?>
		                <th><span class="nobr"><?php echo $_attribute->getStoreLabel() ?></span></th>
		                <?php endif; ?>
		                <td>
		                    <?php switch ($_attribute->getAttributeCode()) {
		                        case "price": ?>
		                            <span class="price"><?php echo $this->getPriceHtml($_item, true, '-compare-list-' . $_attribute->getCode()) ?></span>
		                            <?php break;
		                        case "small_image": ?>
		                            <img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->escapeHtml($_item->getName()) ?>" title="<?php echo $this->escapeHtml($_item->getName()) ?>" />
		                            <?php break;
		                        case "date":
		                              echo substr($this->getProductAttributeValue($_item, $_attribute),0,10);
		                              break;
		                        default: ?>
		                            <?php echo $this->helper('catalog/output')->productAttribute($_item, $this->getProductAttributeValue($_item, $_attribute), $_attribute->getCode()) ?>
		                            <?php break;
		                    } ?>
		                </td>
		                <?php endforeach; ?>
		            </tr>
		        <?php endforeach; ?>
		        </tbody>
		        <tbody>
		                <tr class="add-to-row">
		                <?php $_i=0 ?>
		                <?php foreach($this->getItems() as $_item): ?>
		                <?php if($_i++%10==0): ?>
		                <th>&nbsp;</th>
		                <?php endif; ?>
		                <td>
		                    <?php echo $this->getPriceHtml($_item, true, '-compare-list-bottom') ?>
		                    <?php if($_item->isSaleable()): ?>
		                        <br><p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
		                    <?php else: ?>
		                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
		                    <?php endif; ?>
		                </td>
		                <?php endforeach; ?>
		            </tr>
		        </tbody>
		    </table>
		    <div class="buttons-set box-action">
		        <button type="button" title="<?php echo $this->__('Close Window') ?>" class="button" onclick="window.close();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
		        <span class="please-wait" id="compare-list-please-wait" style="display:none;">
		            <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Please wait...') ?>" title="<?php echo $this->__('Please wait...') ?>" class="v-middle" /> <?php echo $this->__('Please wait...') ?>
		        </span>
		    </div>
		    <script type="text/javascript">
		        decorateTable('product_comparison');

		        /**
		         * Send remove item request, after that reload windows
		         */
		        function removeItem(url)
		        {
		            new Ajax.Request(url, {
		                parameters: {isAjax: 1, method: 'POST'},
		                onLoading: function(){$('compare-list-please-wait').show();},
		                onSuccess: function(transport) {
		                    $('compare-list-please-wait').hide();
		                    window.location.reload();
		                    window.opener.location.reload();
		                }
		            });
		        }
		    </script>
		<?php else: ?>
		    <script type="text/javascript">window.close();</script>
		<?php endif; ?>
	</div>
</div>