<?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
	$_product = $this->getProduct();
	$_items = $this->getReviewsCollection()->getItems();
	$_aggregateRating = 0;

	if(count($_items)) {
		foreach($_items as $_review) {
			$_votes = $_review->getRatingVotes();
			$_avgVote = 0;
			if(count($_votes)) {
				foreach($_review->getRatingVotes() as $_vote) {
					$_avgVote += $_vote->getPercent();
				}
				$_avgVote = round($_avgVote / count($_votes));
				$_curRating = round($_avgVote / 20);
				$_aggregateRating += $_curRating;
				$_ratingArr[] = $_curRating;
			}
		}
		$_aggregateRating = round($_aggregateRating / count($_items));	
?>
<span class="hidden" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
	<span itemprop="ratingValue"><?php echo $_aggregateRating ?></span>
	<span itemprop="bestRating"><?php echo max($_ratingArr) ?></span>
	<span itemprop="worstRating"><?php echo min($_ratingArr) ?></span>
	<span itemprop="ratingCount"><?php echo count($_items) ?></span>
	<span itemprop="reviewCount"><?php echo count($_items) ?></span>
</span>
<?php
	}
?>