<?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
 */
?>
<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>
<?php 
	$gridClasses = '';
	if(Mage::getStoreConfig('avalanche_config/avalanche_product_listings/avalanche_quick_view') == 1)
		$gridClasses .= 'quick-view-enabled ';
	if(Mage::getStoreConfig('avalanche_config/avalanche_product_listings/avalanche_grid_hover') == 1)
		$gridClasses .= 'grid-hover-enabled ';
?>

<?php if(!$_productCollection->count()): ?>
<div class="category-products">
	<p><?php echo $this->__('There are no products matching the selection.') ?></p>
</div>
<?php else: ?>
<div class="category-products <?php echo $gridClasses ?>">
	<div class="toolbar clearfix">
		<?php echo $this->getLayout()->createBlock('catalog/layer_state')->setTemplate('page/html/breadcrumbs_with_filters.phtml')->toHtml(); ?>
    	<?php echo $this->getToolbarHtml() ?>
	</div>

	 <?php // Grid mode ?>
    <?php if($this->getMode() == 'grid'): ?>

	<div class="catalog-page">
    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount() ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="product-grid clearfix">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
				<div class="grid-image <?php if(!$_product->isSaleable()) { ?>faded<?php } ?>">
		            <?php // Product Image ?>
		            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(140); ?>" width="140" height="140" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
					<div class="grid-quick-view">
						<a href="#" data-url="<?php echo Mage::getUrl('catalog/ajax_product/view', array('_query' => array('id' => $_product->getId()), '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure())) ?>"><?php echo $this->__('Quick View') ?></a>
					</div>
				</div>
				<div class="grid-rating">
	                <?php if($_product->getRatingSummary()): ?>
	                <?php echo $this->getReviewsSummaryHtml($_product) ?>
	                <?php endif; ?>
				</div>
				<div class="grid-title">
					<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
					<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a>
					<?php if(!$_product->isSaleable()): ?>
					    <div class="grid-availability"><?php echo $this->__('Out Of Stock') ?></div>
					<?php endif; ?>
				</div>
				<div class="grid-price">
					<?php echo $this->getPriceHtml($_product, true) ?>
				</div>
				<div class="grid-actions">
                    <?php if(Mage::getStoreConfigFlag('avalanche_config/avalanche_product_listings/avalanche_grid_show_button')): ?>
					<a href="<?php echo $_product->getProductUrl() ?>" class="action-button"><?php echo Mage::getStoreConfig('avalanche_config/avalanche_product_listings/avalanche_grid_show_button_text'); ?></a>
                    <?php endif; ?>
				</div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>
    </div>

    <?php // List Mode ?>
    <?php else: ?>

    <div class="catalog-page">
    	<ul class="product-list clearfix">
    	<?php foreach ($_productCollection as $_product): ?>
            <li>
				<div class="list-image <?php if(!$_product->isSaleable()) { ?>faded<?php } ?>">
		            <?php // Product Image ?>
		            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(118); ?>" width="118" height="118" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
					<div class="list-quick-view">
						<a href="#" data-url="<?php echo Mage::getUrl('catalog/ajax_product/view', array('_query' => array('id' => $_product->getId()), '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure())) ?>/"><?php echo $this->__('Quick View') ?></a>
					</div>
				</div>
				<?php if($_product->getRatingSummary()): ?>
	                <div class="list-rating clearfix">
	                	<?php echo $this->getReviewsSummaryHtml($_product) ?>
	                </div>
	            <?php endif; ?>
				<div class="list-title">
					<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
					<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a>
					<?php if(!$_product->isSaleable()): ?>
					    <div class="grid-availability"><?php echo $this->__('Out Of Stock') ?></div>
					<?php endif; ?>
				</div>			
				<?php if ($_product->getShortDescription()):?>
				<div class="list-desc">
					<p><?php echo strip_tags($_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description')) ?></p>
				</div>
		        <?php endif;?>
				<div class="list-price">
					<?php echo $this->getPriceHtml($_product, true) ?>
				</div>
            </li>
        <?php endforeach ?>
        </ul>  
    </div>

    <?php endif; ?>

	<div class="toolbar clearfix">
		<?php echo $this->getLayout()->createBlock('catalog/layer_state')->setTemplate('page/html/breadcrumbs_with_filters.phtml')->toHtml(); ?>
    	<?php echo $this->getToolbarHtml() ?>
	</div>
    
	<?php if(Mage::getStoreConfigFlag('avalanche_config/avalanche_product_listings/avalanche_ajax_catalog')): ?>
		<div id="last-page" data-number="<?php echo $this->getToolbarBlock()->getLastPageNum();?>"></div>
		<div id="show-more-loader" data-translate="<?php echo $this->__('Show More Products') ?>" data-src="<?php echo $this->getSkinUrl('images/ajax-load.gif') ?>"></div>
	<?php endif; ?>
</div>
<?php endif; ?>
