/* Js for , Version=1771494023 */
 v.theme = {"template":"mobile","theme":"default","device":"mobile"};;v.currencySymbol = "\uffe5";;
+(function($){
    'use strict';

    var minDelta = 20;

    $.fn.numberInput = function(){
        return $(this).each(function(){
            var $input = $(this);
            $input.on('click', '.btn-minus, .btn-plus', function(){
                var $val = $input.find('.btn-number, [type="number"]');
                var val = parseInt($val.val());
                val = Math.max(1, $(this).hasClass('btn-minus') ? (val - 1) : (val + 1));
                $val.val(val).trigger('change');
            });
        });
    };

    $(function(){$('.input-number').numberInput();});
}(Zepto));

$(function()
{
    var caculateTotal = function()
    {
        statAll();
    };

    $('.btn-number').on('change', function()
    {
        caculateTotal();
    });

    $('#checkAll').on('click', function()
    {
        $('.check-product').each(function()
        {
            $(this).prop("checked", $('#checkAll').prop("checked"));
        });
        statAll();
    });

    $('.check-product').on('click', function()
    {
        var status = true;
        $('.check-product').each(function()
        {
            if(!$(this).prop("checked"))
            {
                $('#checkAll').prop("checked", false);
                status = false;
            }
        })
        if(status)
        {
            $('#checkAll').prop("checked", true);
        }
        statAll();
    });

    $('.opt.admin').on('click', function()
    {
        $(this).siblings().show();
        $(this).hide();
        $('.total').find('span').hide();
        $('.btn-order-submit').hide();
        $('.btn-order-delete').show();
    });

    $('.opt.complete').on('click', function()
    {
        $(this).siblings().show();
        $(this).hide();
        $('.total').find('span').show();
        $('.btn-order-submit').show();
        $('.btn-order-delete').hide();
    });

    $('.btn-order-delete').on('click', function()
    {
        var products = '';
        $('.check-product:checked').each(function()
        {
            products += $(this).val() + ',';
        });
        $.getJSON(createLink('cart', 'batchdelete', 'products=' + products), function(data) 
        {
            window.location.reload();
        });
    });
});

statAll();
function statAll()
{
    var amount = 0;
    var total = 0;
    $('.check-product').each(function()
    {
        var price = $(this).parent().parent().find('.btn-number').data('price');
        var number = $(this).parent().parent().find('.btn-number').val();
        $(this).parent().parent().find('.product-amount').text(parseFloat(price*number).toFixed(2)); 
        if($(this).prop("checked"))
        {
            amount += 1;
            total += parseFloat($(this).parent().parent().find('.product-amount').html()); 
        }
    });
    total = total.toFixed(2);
    $('#amount').prev().html(amount);
    $('#amount').html($('#amount').html().substr(0,1) + total);

}
