<?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 $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>

<div id="product-info-inner" class="black-box">
    <?php if(Mage::getStoreConfig('avalanche_social/general/button_location') == 'above-reviews-full' || Mage::getStoreConfig('avalanche_social/general/button_location') == 'beside-reviews'): ?>
        <?php echo $this->getChildHtml('social-buttons') ?>
    <?php endif; ?>
	
	<div id="product-rating" class="clearfix">
		<?php echo $this->getReviewsSummaryHtml($_product) ?>
	</div>
	
	<h1 class="name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>

	<div id="product-description" class="description">
		<?php if ($_product->getShortDescription()):?>
			<p><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></p>
        <?php endif;?>
	</div>

	<div id="product-price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
        <?php if($_product->getTypeId() != "grouped") { ?>
		  <?php echo $this->getPriceHtml($_product) ?>
        <?php } ?>
        <?php if(!$_product->isSaleable()): ?>
            <div id="availability" class="out_of_stock" itemprop="availability"><?php echo $this->__('Out Of Stock') ?></div>
        <?php else: ?>
            <div class="in_stock" style="display: none" itemprop="availability"><?php echo $this->__('In Stock') ?></div>
        <?php endif; ?>
		<span class="hidden" itemprop="price"><?php echo Mage::helper('core')->currency($_product->getPrice()); ?></span>
		<span class="hidden" itemprop="priceCurrency"><?php echo Mage::app()->getStore()->getCurrentCurrencyCode(); ?></span>		
	</div>

    <?php if(Mage::getStoreConfig('avalanche_social/general/button_location') == 'below-price'): ?>
        <?php echo $this->getChildHtml('social-buttons') ?>
    <?php endif; ?>

    <?php echo $this->getChildHtml('other') ?>
	
	<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?> onsubmit="return false">
        <?php echo $this->getBlockHtml('formkey') ?>
		<div class="no-display">
            <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
            <input type="hidden" name="related_product" id="related-products-field" value="" />
        </div>

        <?php echo $this->getChildHtml('alert_urls') ?>
        <?php echo $this->getChildHtml('product_type_data') ?>
        <?php echo $this->getTierPriceHtml() ?>
        <?php echo $this->getChildHtml('extrahint') ?>

		<?php if($_product->isSaleable()): ?>
			<?php if($this->hasOptions()): ?>
				<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
				<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
	        <?php endif;?>
			<?php echo $this->getChildHtml('addtocart') ?>
		<?php endif; ?>
	</form>

    <?php if(Mage::getStoreConfig('avalanche_social/general/button_location') == 'below-cart'): ?>
        <?php echo $this->getChildHtml('social-buttons') ?>
    <?php endif; ?>
</div>

<script type="text/javascript">
//<![CDATA[
    var productAddToCartForm = new VarienForm('product_addtocart_form');
    productAddToCartForm.submit = function(button, url) {
        if (this.validator.validate()) {
            var form = this.form;
            var oldUrl = form.action;

            if (url) {
               form.action = url;
            }
            var e = null;
            try {
                this.form.submit();
            } catch (e) {
            }
            this.form.action = oldUrl;
            if (e) {
                throw e;
            }

            if (button && button != 'undefined') {
                button.disabled = true;
            }

			return false;
        }
    }.bind(productAddToCartForm);

    productAddToCartForm.submitLight = function(button, url){
        if(this.validator) {
            var nv = Validation.methods;
            delete Validation.methods['required-entry'];
            delete Validation.methods['validate-one-required'];
            delete Validation.methods['validate-one-required-by-name'];
            if (this.validator.validate()) {
                if (url) {
                    this.form.action = url;
                }
                this.form.submit();
            }
            Object.extend(Validation.methods, nv);
        }
    }.bind(productAddToCartForm);
//]]>
</script>