<?php // no direct access
defined ('_JEXEC') or die('Restricted access');
// add javascript for price and cart, need even for quantity buttons, so we need it almost anywhere
vmJsApi::jPrice();

$col = 1;
$pwidth = ' width' . floor (100 / $products_per_row);
if ($products_per_row > 1) {
	$float = "floatleft";
} else {
	$float = "center";
}

?>
<div class="vmgroup<?php echo $params->get ('moduleclass_sfx') ?> section-inner books-view">

	<?php if ($headerText) { ?>
	<div class="vmheader"><?php echo $headerText ?></div>
	<?php
}
	if ($display_style == "div") {
		?>
		<div id="bk-list" class="vmproduct<?php echo $params->get ('moduleclass_sfx'); ?> productdetails row bk-list">
			<?php foreach ($products as $product) { ?>
			<div class="product <?php echo $pwidth ?> <?php echo $float ?>">
				<div class="spacer">
					<div class="bk-book bk-bookdefault">
		        <div class="bk-front">
		          <div class="bk-cover">
		          		<?php 
		          			$url = JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' .$product->virtuemart_category_id);
		          		?>
		              <?php 
			              if (!empty($product->images[0])) {
					            $image = $product->images[0]->displayMediaThumb ('class="featuredProductImage" border="0"', FALSE);
					          } else {
					            $image = '';
					          }
					          echo JHTML::_ ('link', JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id), $image, array('title' => $product->product_name));
				          ?>
		          </div>
		        </div>
		        <div class="bk-back"></div>
		        <div class="bk-left">
		          <h2>
		            <span><?php echo $product->product_name ?></span>
		          </h2>
		        </div>
		      </div>
		      <div class="bk-info">
		        <h3>
		          <span><?php echo $product->product_name ?></span>
		        </h3>
            
		        <?php // Product Short Description
            if (!empty($product->product_s_desc)) {
            ?>
            <div class="pk-desc">
            <?php  echo shopFunctionsF::limitStringByWord ($product->product_s_desc, 70, ' ...') ?>
            </div>
            <?php } ?>
            
		        <?php 
			        if ($show_price) {
		            //    echo $currency->priceDisplay($product->prices['salesPrice']);
		            if (!empty($product->prices['salesPrice'])) {
		              echo $currency->createPriceDiv ('salesPrice', '', $product->prices, FALSE, FALSE, 1.0, TRUE);
		            }
		            //    if ($product->prices['salesPriceWithDiscount']>0) echo $currency->priceDisplay($product->prices['salesPriceWithDiscount']);
		            if (!empty($product->prices['salesPriceWithDiscount'])) {
		              echo $currency->createPriceDiv ('salesPriceWithDiscount', '', $product->prices, FALSE, FALSE, 1.0, TRUE);
		            }
		          }
		          if ($show_addtocart) {
		            echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product));
		          }
          	?>
          </div>
				</div>
			</div>
			<?php
			if ($col == $products_per_row && $products_per_row && $col < $totalProd) {
				echo "	</div><div class='bk-list row' style='clear:both;'>";
				$col = 1;
			} else {
				$col++;
			}
		} ?>
		</div>
		<br style='clear:both;'/>

		<?php
	} else {
		$last = count ($products) - 1;
		?>

		<ul class="vmproduct<?php echo $params->get ('moduleclass_sfx'); ?> productdetails">
			<?php foreach ($products as $product) : ?>
			<li class="<?php echo $pwidth ?> <?php echo $float ?>">
				<?php
				if (!empty($product->images[0])) {
					$image = $product->images[0]->displayMediaThumb ('class="featuredProductImage" border="0"', FALSE);
				} else {
					$image = '';
				}
				echo JHTML::_ ('link', JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id), $image, array('title' => $product->product_name));
				echo '<div class="clear"></div>';
				$url = JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' .
					$product->virtuemart_category_id); ?>
				<a href="<?php echo $url ?>"><?php echo $product->product_name ?></a>        <?php    echo '<div class="clear"></div>';
				// $product->prices is not set when show_prices in config is unchecked
				if ($show_price and  isset($product->prices)) {
					echo '<div class="product-price">'.$currency->createPriceDiv ('salesPrice', '', $product->prices, FALSE, FALSE, 1.0, TRUE);
					if ($product->prices['salesPriceWithDiscount'] > 0) {
						echo $currency->createPriceDiv ('salesPriceWithDiscount', '', $product->prices, FALSE, FALSE, 1.0, TRUE);
					}
					echo '</div>';
				}
				if ($show_addtocart) {
					echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product));
				}
				?>
			</li>
			<?php
			if ($col == $products_per_row && $products_per_row && $last) {
				echo '
		</ul><div class="clear"></div>
		<ul  class="vmproduct' . $params->get ('moduleclass_sfx') . ' productdetails">';
				$col = 1;
			} else {
				$col++;
			}
			$last--;
		endforeach; ?>
		</ul>
		<div class="clear"></div>

		<?php
	}
	if ($footerText) : ?>
		<div class="vmfooter<?php echo $params->get ('moduleclass_sfx') ?>">
			<?php echo $footerText ?>
		</div>
		<?php endif; ?>
</div>