<?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(); ?>
<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div class="page-messages">
	<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
</div>

<?php /* Product Images */ ?>
<?php echo $this->getChildHtml('media') ?>

<div id="product-details">
    <div id="product-header-container">
        <div id="product-header" data-float="<?php echo Mage::getStoreConfig('avalanche_mobile/catalog/floaty_header') ?>">
            <div id="product-title">
                <h1 class="name fn"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
                <div id="product-rating"><?php echo $this->getReviewsSummaryHtml($_product, 'product') ?></div>
            </div>
            <div id="product-price">
                <?php if($_product->getTypeId() != "grouped") { ?>
                  <?php echo $this->getPriceHtml($_product) ?>
                <?php } ?>
                <?php if(!$_product->isSaleable()): ?>
                    <div id="availability" class="availability out_of_stock"><?php echo $this->__('Out Of Stock') ?></div>
                <?php else: ?>
                    <div class="availability in_stock" style="display: none"><?php echo $this->__('In Stock') ?></div>
                <?php endif; ?>
            </div>
            <?php $showSku = Mage::getStoreConfigFlag('avalanche_mobile/catalog/show_sku'); ?>
            <?php if($showSku): ?>
                <div id="product-sku">SKU: #<?php echo $_product->getSku() ?></div>
            <?php endif; ?>
        </div>
    </div>

    <?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">
        <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 echo $this->getChildHtml('addto') ?>

    <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>

    <?php /* Product Description */ ?>
    <?php echo $this->getChildHtml('description') ?>

    <?php /* Product Reviews */ ?>
    <?php echo $this->getChildHtml('product_reviews') ?>

    <?php echo $this->getChildHtml('info_tabs') ?>
    <?php echo $this->getChildHtml('product_additional_data') ?>
</div>