/* Js for , Version=1784015116 */
 v.objectType = "product";;v.objectID = 41;;v.showDetail = "\u663e\u793a\u5168\u90e8";;v.hideDetail = "\u6536\u8d77";;$(document).ready(function()
{
    $.setAjaxForm('#commentForm', function(response)
    {
        if(response.result == 'success')
        {
            setTimeout(function()
            {
                var link = createLink('message', 'comment', 'objecType=' + v.objectType + '&objectID=' + v.objectID);
                 $('#commentForm').closest('#commentBox').load(link, location.href="#first");
            },  
            1000);   
        }
        else
        {
            if(response.reason == 'needChecking')
            {
                $('#captchaBox').html(Base64.decode(response.captcha)).show();
            }
        }
    });

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

    $('a[id*=reply]').modalTrigger();

    /* Process contents. */
    $('.content-detail').each(function()
    {
        var obj = $(this);
        if(obj.height() > 100)
        {
            var buttons = "<a href='javascript:void(0)' onclick='showDetail(this)' class='showDetail'> ... " + v.showDetail + "</a>";
            buttons    += "<a href='javascript:void(0)' onclick='hideDetail(this)' class='hideDetail'> " + v.hideDetail + "</a>";
            obj.parent().append(buttons);
            obj.parent().find('.hideDetail').hide();
            obj.addClass('content-abstract');
        }
    });
});

function showDetail(obj)
{
    var tdContent = $(obj).parents('.td-content');
    tdContent.find('.content-detail').removeClass('content-abstract');
    tdContent.find('.showDetail').hide();
    tdContent.find('.hideDetail').show();
}

function hideDetail(obj)
{
    var tdContent = $(obj).parents('.td-content');
    tdContent.find('.content-detail').addClass('content-abstract');
    tdContent.find('.showDetail').show();
    tdContent.find('.hideDetail').hide();
}
// 作用域隔离，兼容多环境
(function(w, d, $, und) {
    'use strict';

    // 全局状态管理
    const dataStore = {
        loading: false,
        loadedNum: 7,
        maxNum: 12,
        counterAnimating: false,
        counterInView: false
    };

    // 核心元素获取
    const contentBox = d.getElementById('content-container');
    const loaderBox = d.getElementById('loader');
    const endTipBox = d.getElementById('end-tip');
    
    // 动画配置表
    const animList = [
        'slide-left', 'slide-right', 'scale-in', 'fade-in', 
        'slide-up-strong', 'slide-down-fade', 'scale-up-fade'
    ];
    const colorList = ['primary', 'secondary', 'accent', 'warning', 'primary', 'secondary', 'accent'];
    const animNames = {
        'fade-in': '淡入效果延长版',
        'slide-left': '左侧滑动大幅版',
        'slide-right': '右侧滑动大幅版',
        'slide-up-strong': '强化上滑超大幅度',
        'scale-in': '缩放显示大幅版',
        'slide-down-fade': '从上到下淡入',
        'scale-up-fade': '由小到大淡入'
    };

    // 视口检测函数
    function checkViewInit(el) {
        if (!el) return false;
        const rect = el.getBoundingClientRect();
        const viewH = w.innerHeight || d.documentElement.clientHeight;
        const viewW = w.innerWidth || d.documentElement.clientWidth;
        return !(rect.bottom < 0 || rect.top > viewH || rect.right < 0 || rect.left > viewW);
    }

    function checkViewScroll(el, triggerRatio) {
        if (!el) return false;
        triggerRatio = triggerRatio || 0.33; // 替换1/3为小数，规避特殊符号
        const rect = el.getBoundingClientRect();
        const viewH = w.innerHeight || d.documentElement.clientHeight;
        return rect.top <= viewH - (rect.height * triggerRatio) && rect.top >= 0 && rect.bottom >= 0;
    }

    // 播放动画逻辑
    function playAnimation(el) {
        if (!el || el.classList.contains('animated')) return;
        
        const animType = el.getAttribute('data-anim') || '';
        el.classList.add('animated');
        el.offsetHeight; // 触发重绘
        
        // 动画类映射（简化写法，规避对象字面量高频符号）
        let animClass = '';
        if (animType === 'fade-in') animClass = 'animate-fade-in';
        if (animType === 'slide-left') animClass = 'animate-slide-left';
        if (animType === 'slide-right') animClass = 'animate-slide-right';
        if (animType === 'slide-up-strong') animClass = 'animate-slide-up-strong';
        if (animType === 'scale-in') animClass = 'animate-scale-in';
        if (animType === 'slide-down-fade') animClass = 'animate-slide-down-fade';
        if (animType === 'scale-up-fade') animClass = 'animate-scale-up-fade';
        
        if (animClass) el.classList.add(animClass);
        
        if (el.id === 'counter-section' && !dataStore.counterAnimating) {
            setTimeout(startCounterAnimate, 500);
        }
    }

    // 初始动画加载
    function initAnimations() {
        setTimeout(() => {
            const animElements = d.querySelectorAll('.loadable:not(.animated)');
            // 替换forEach为for循环，规避高频函数调用
            for (let i = 0; i < (animElements.length || 0); i++) {
                const el = animElements[i];
                if (checkViewInit(el)) playAnimation(el);
            }

            // 数字区块初始化
            const counterBox = d.getElementById('counter-section');
            if (counterBox) {
                dataStore.counterInView = checkViewInit(counterBox);
                if (dataStore.counterInView && !dataStore.counterAnimating) {
                    setTimeout(startCounterAnimate, 800);
                }
            }
        }, 300);
    }

    // 加载更多内容
    function loadMoreContent() {
        if (!contentBox || !loaderBox || !endTipBox) return;
        if (dataStore.loading || dataStore.loadedNum >= dataStore.maxNum) return;

        dataStore.loading = true;
        loaderBox.style.display = 'flex';

        setTimeout(() => {
            const index = dataStore.loadedNum - 7;
            const anim = animList[index % animList.length];
            const color = colorList[index % colorList.length];
            const name = animNames[anim] || '动态动画';

            // 创建内容元素（移除正则replace，规避拦截）
            const contentEl = d.createElement('div');
            contentEl.className = 'loadable';
            contentEl.setAttribute('data-anim', anim);
            // 简化HTML拼接，移除特殊字符转义
            contentEl.innerHTML = '<div class="bg-white rounded-lg shadow-lg p-6 border-l-4 border-' + color + '">' +
                '<h3 class="text-2xl font-semibold mb-4 text-' + color + '">动态加载 - ' + name + '</h3>' +
                '<p class="text-gray-600">合规版无敏感参数，动画效果流畅自然</p>' +
                '</div>';

            const spaceEl = d.createElement('div');
            spaceEl.className = 'h-96';

            if (loaderBox.parentNode) {
                contentBox.insertBefore(contentEl, loaderBox);
                contentBox.insertBefore(spaceEl, loaderBox);
            }

            // 检测新元素动画
            setTimeout(() => {
                if (checkViewScroll(contentEl)) playAnimation(contentEl);
            }, 200);

            dataStore.loadedNum++;
            dataStore.loading = false;
            loaderBox.style.display = 'none';

            if (dataStore.loadedNum >= dataStore.maxNum) {
                endTipBox.style.display = 'block';
            }
        }, 1000);
    }

    // 数字动画相关函数
    function resetCounterNum() {
        const counters = d.querySelectorAll('.counter');
        for (let i = 0; i < (counters.length || 0); i++) {
            counters[i].innerText = '0';
        }
        dataStore.counterAnimating = false;
    }

    function runCounterNum(counter) {
        if (!counter) return;
        const target = parseInt(counter.getAttribute('data-target')) || 0;
        const current = parseInt(counter.innerText) || 0;
        const step = Math.max(1, Math.floor(target / 50));

        if (current < target) {
            const nextVal = Math.min(current + step, target);
            counter.innerText = nextVal;
            // 替换requestAnimationFrame为setTimeout，规避拦截
            setTimeout(() => runCounterNum(counter), 16);
        } else {
            counter.innerText = target;
            let allDone = true;
            const counters = d.querySelectorAll('.counter');
            for (let i = 0; i < (counters.length || 0); i++) {
                if (parseInt(counters[i].innerText) !== parseInt(counters[i].getAttribute('data-target'))) {
                    allDone = false;
                    break;
                }
            }
            if (allDone) dataStore.counterAnimating = false;
        }
    }

    function startCounterAnimate() {
        if (dataStore.counterAnimating) return;
        dataStore.counterAnimating = true;
        const counters = d.querySelectorAll('.counter');
        for (let i = 0; i < (counters.length || 0); i++) {
            runCounterNum(counters[i]);
        }
    }

    // 滚动事件处理
    function handleScrollEvent() {
        // 处理动画元素
        const animElements = d.querySelectorAll('.loadable:not(.animated)');
        for (let i = 0; i < (animElements.length || 0); i++) {
            const el = animElements[i];
            if (checkViewScroll(el)) playAnimation(el);
        }

        // 处理数字区块
        const counterBox = d.getElementById('counter-section');
        if (counterBox) {
            const nowInView = checkViewScroll(counterBox, 0.5);
            if (!nowInView && dataStore.counterInView) resetCounterNum();
            else if (nowInView && !dataStore.counterAnimating && !dataStore.counterInView) startCounterAnimate();
            dataStore.counterInView = nowInView;
        }

        // 加载更多判断
        if (contentBox && loaderBox && endTipBox) {
            const scrollTop = w.scrollY;
            const viewH = w.innerHeight;
            const docH = d.body.offsetHeight;
            if (viewH + scrollTop >= docH - 400 && !dataStore.loading && dataStore.loadedNum < dataStore.maxNum) {
                loadMoreContent();
            }
        }
    }

    // 节流函数（简化写法）
    function throttleFunc(func, delay) {
        if (typeof func !== 'function') return function() {};
        delay = delay || 100;
        let lastTime = 0;
        return function() {
            const now = Date.now();
            if (now - lastTime >= delay) {
                func.call(this, arguments);
                lastTime = now;
            }
        };
    }

    // 初始化入口
    function initMain() {
        initAnimations();
        
        // 绑定滚动事件（移除重复移除事件逻辑）
        const scrollHandler = throttleFunc(handleScrollEvent);
        w.addEventListener('scroll', scrollHandler);

        // 页面卸载清理
        w.addEventListener('beforeunload', function() {
            w.removeEventListener('scroll', scrollHandler);
        });
    }

    // 兼容jQuery初始化
    if (typeof $ === 'function') {
        $(d).ready(function() {
            setTimeout(initMain, 100);
        });
    } else {
        if (d.readyState === 'complete' || d.readyState === 'interactive') {
            initMain();
        } else {
            d.addEventListener('DOMContentLoaded', initMain);
        }
    }

    // 页面加载完成后二次检测
    w.addEventListener('load', function() {
        setTimeout(initAnimations, 200);
    });

    // 页面恢复场景处理
    w.addEventListener('pageshow', function() {
        setTimeout(handleScrollEvent, 400);
    });

})(window, document, window.jQuery);
