/* Js for , Version=1775248520 */
 v.theme = {"template":"mobile","theme":"default","device":"mobile"};;v.quoteTitle = "<div class='quote-title'>\u539f\u5e16\u7531 %s \u4e8e %s \u53d1\u8868<\/div>";;v.discussion = 0;;
    $(function()
    {
        var $commentForm = $('#commentForm'),
            $commentBox = $('#commentBox'),
            $replyForm = $('#replyForm'),
            $commentContent = localStorage.getItem('commentContent');

        if($commentContent)
        {
            $commentForm.find('#commentContent').val($commentContent);
        }

        $.refreshCommentList = function ()
        {
            $('.pager-pull-up').removePullUpPager();
            console.log(window.location.href);
            $('#commentsListAsync').load(window.location.href + ' #commentsListWrapper', function ()
            {
                $('.pager-pull-up').initPullUpPager();
                moreRepliesHide();
                moreReliesBind();
                pupLoadBind();
                threadReplyBtnBind();
            });
        };

        var threadReplyBtnBind = function ()
        {
            $('.thread-reply-btn').on('click', function ()
            {
                $('#reply').val($(this).data('reply-id'));
            });
        };
        threadReplyBtnBind();

        var pupLoadBind = function ()
        {
            $('.pager-pull-up').on('pupLoad', function ()
            {
                moreRepliesHide();
                moreReliesBind();
                threadReplyBtnBind();
            });
        };
        pupLoadBind();

        $commentBox.find('.pager').on('click', 'a', function()
        {
            $commentBox.load($(this).attr('href'));
            return false;
        });

        $commentForm.ajaxform({
            onSubmit: function ()
            {
                localStorage.setItem('commentContent', $commentForm.find('#commentContent').val());
            },
            onSuccess: function(response)
            {
                if(response.result == 'success')
                {
                    localStorage.setItem('commentContent', '');
                    $commentForm.find('#commentContent').val('');
                    setTimeout($.refreshCommentList, 200);
                    $('.comment-list').show();
                }
            }
        });

        $replyForm.ajaxform({
            onSubmit: function ()
            {
                localStorage.setItem('replyContent', $replyForm.find('#content').val());
            },
            onResultSuccess: function()
            {
                localStorage.setItem('replyContent', '');
                $replyForm.find('#content').val('');
                $('#replyDialog').modal('hide');
                setTimeout($.refreshCommentList, 200);
            },
            onSuccess: function(response)
            {
                if(response.reason == 'needChecking')
                {
                    $replyForm.find('.captcha-box').html(Base64.decode(response.captcha)).removeClass('hide');
                }
            }
        });

        var moreRepliesHide = function ()
        {
            $('.comment').each(function ()
            {
                var i = 0;
                $(this).children('.replies').find('.reply-heading').each(function ()
                {
                    i++;
                    if(i > 3) $(this).hide();
                });
                var j = 0;
                $(this).children('.replies').find('.reply-body').each(function ()
                {
                    j++;
                    if(j > 3) $(this).hide();
                });
                if(j > 3)
                {
                    $(this).find('.more-replies-amount').html(j - 3);
                } else {
                    $(this).find('.more-replies').hide();
                }
            });
        };
        moreRepliesHide();

        var moreReliesBind = function ()
        {
            $('.more-replies').on('click', function ()
            {
                $(this).hide();
                $(this).parent().parent().children('.replies').find('.reply-heading,.reply-body').show();
            });
        };
        moreReliesBind();
    });
;$(function()
{
    $('.thread > .card-footer').each(function()
    {
        var $footer = $(this);
        var $children = $footer.children();
        var length = $children.length;
        if(length < 1 
           || (length === 1 && $children.filter('.actions').length === 1 && $children.filter('.actions').children().length < 1))
        {
            $footer.hide();
        }
    });

    $(document).on('click', '.quote', function()
    {
        if($(this).parents('.alert-replies').length)
        {
            var $quote = $(this).parents('.thread-content');
            var date   = $quote.find('.reply-date').html();
            var user   = $quote.find('.reply-author').html().replace('\：', '');
            var quoteTitle = v.quoteTitle.replace('\%\s', user).replace('\%\s', date);

            var quoteContent = '[quote]';
            quoteContent += quoteTitle;
            quoteContent += $quote.find('.reply-content').html();
            quoteContent += '[/quote]';
        }
        else
        {
            var $quote     = $(this).parents('.panel.reply');
            var date       = $quote.find('.panel-heading span.muted')[0].childNodes[1].textContent;
            var user       = $quote.find('.table .speaker .thread-author')[0].childNodes[1].textContent;
            var quoteTitle = v.quoteTitle.replace('\%\s', user).replace('%s', date);
            
            var quoteContent = '[quote]';
            quoteContent += quoteTitle;
            quoteContent += $quote.find('.table .thread-wrapper .thread-content').html();
            quoteContent += '<br/>[/quote]';
        }

        $('#content').focus().val(quoteContent);
    });

    $(document).on('click', 'input[name=stick]', function()
    {
        if($('#stick1').prop('checked'))
        {
            $(this).parents('.form-group').next(".form-group").hide().next('.form-group').hide();
        }
        else
        {
            $(this).parents('.form-group').next(".form-group").show().next('.form-group').show();
        }
    });

    $('.operations .trigger').on('click', function ()
    {
        var options = $('.operations .options');
        if (options.hasClass('hidden'))
        {
            $(this).addClass('active');
            options.removeClass('hidden');
        }
        else
        {
            $(this).removeClass('active');
            options.addClass('hidden');
        }
    })
});

;
$(function()
{
    var countLink  = '/cart-count.mhtml';
    var browseLink = '/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();
});
;
  
