<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     rwd_default
 * @copyright   Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>

<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
    <?php echo $this->getChildHtml('review_form') ?>
    <?php if (count($_items)):?>
        <div class="box-reviews2">

            <h3><?php echo $this->__('Customer Reviews') ?></h3>
            <?php echo $this->getChildHtml('toolbar') ?>
<div class="box visible" >
<?php $count_reviews=0;?>
             
        <ul>
        <?php foreach ($_items as $_review):
              if($count_reviews==2) { ?>
                    <div id="showHideReview" style="display:none;"> 
                <?php }?>

            <li>
                <?php $_votes = $_review->getRatingVotes(); ?>

                <?php if (count($_votes)): ?>
                <table class="ratings-table">
                    <col width="1" />
                    <col />
                    <tbody>
                        <?php foreach ($_votes as $_vote): ?>
                        <tr>
                            <th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
                            <td>
                                <div class="rating-box">
                                    <div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
                                </div>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
                <?php endif; ?>

 <div class="review">
              <h6>                                 
                <?php echo $this->htmlEscape($_review->getTitle()) ?>
              </h6>

                <small>
                    <?php echo $this->__('Review by %s', $this->escapeHtml($_review->getNickname())) ?>
                    /
                   <?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?>
                </small>

               <div class="review-txt"><?php echo nl2br($this->htmlEscape($_review->getDetail())) ?></div>

 </div> <!--review-->
            </li>
      <?php $count_reviews++;?>
        <?php endforeach; 
           if($count_reviews>2) {
                 ?>
                </div>  <!--#showHideReview-->
                <?php } ?>
        </ul>

</div><!--box visible-->

        <div class="actions">
          <?php if($count_reviews>2) { ?>
            <a type="button" id="show_review_all"  class="button view-all"  onclick="showDiv()" ><span><?php echo $this->__('View all');?></span></a>
          <?php } ?>
          <a type="button" id="hide_review"  class="button view-all"  style="display:none" onclick="HideDiv()" ><span><?php echo $this->__('Hide');?></span></a>
        </div> <!--actions-->

  </div> <!--box-reviews2-->
        <?php // echo $this->getChildHtml('toolbar') ?>
    <?php elseif($this->getParentBlock()): ?>
        <?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?>
    <?php endif;?>

</div> <!--box-collateral box-reviews-->
<div class="clear"></div>

<script type="text/javascript" language="javascript">
    function showDiv()
    {
            document.getElementById('showHideReview').style.display = ""; 
            document.getElementById('hide_review').style.display = "";
            document.getElementById('show_review_all').style.display = "none";             
    }
    function HideDiv()
    {    
            document.getElementById('showHideReview').style.display = "none"; 
            document.getElementById('show_review_all').style.display = "";
            document.getElementById('hide_review').style.display = "none";               
    }
</script>
