/* 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);

}
;$().ready(function() { $('#execIcon').click(function(){ $('#execInfoBar').toggle();});}); ;
$(function()
{
    var countLink  = '/index.php/cart-count.mhtml';
    var browseLink = '/index.php/cart-browse.mhtml';
    
    $.refreshCart = function(twinkle)
    {
        $.getJSON(countLink, function(data)
        {
            if($.isPlainObject(data) && data.result === 'success')
            {
                var $count = $('.cart-count').text(data.count).toggleClass('hide', data.count < 1);
                if(data.count > 0 && twinkle)
                {
                    $count.addClass('twinkle');
                    setTimeout(function(){$count.removeClass('twinkle')}, 200);
                    if(window.v && window.v.addToCartSuccess) $.messager.success(window.v.addToCartSuccess + "<div><a class='btn success dismiss' href=" + browseLink + ">" + window.v.gotoCart + " <i class='icon-arrow-right'></i></a><div class='msger-cart-count'><i class='icon icon-shopping-cart icon-s3'></i><strong class='cart-count badge'>" + data.count + "</strong></div></div>", {time: 10000, cssClass: 'msger-cart'});
                }
            }
        });
    };
    
    $.refreshCart();
});
