tealiumTracking = function () {
    //private menbers
    let currentSection = null;


    //private methods
    function init() {
        console.log('tealiumTracking is loaded.');

        setTimeout(()=>{
            updateCurrentSection();
        }, 500);

    }

    function updateCurrentSection() {
        $(window).scroll(function() {
            // 獲取當前捲動位置
            const scrollPosition = $(window).scrollTop();
            const windowH = $(window).outerHeight();
            const bodyH = $("body").outerHeight();

            // 逐個檢查每個 section 的位置
            $('section').each(function() {
                const section = $(this);
                // console.log(section)
                const sectionTop = section.offset().top;
                const sectionBottom = sectionTop + section.outerHeight();

                // 檢查是否在該 section 的範圍內
                if (scrollPosition >= sectionTop && scrollPosition < sectionBottom) {
                    let sectionId = section.attr('id');

                    if(!isMobile) {
                        if(scrollPosition >= (bodyH - windowH - 300)) {
                            sectionId = 'moreref';
                        }
                    }

                    if(!currentSection) {
                        currentSection = sectionId;
                        // console.log('目前在 ' + currentSection + ' 部分。');
                        jQuery("document").trigger( "virtualPageView" );
                        if(setGA){
                            setGA.pageView(sectionId);
                        }
                    }

                    if(currentSection !== sectionId) {
                        currentSection = sectionId;
                        // console.log('目前在 ' + currentSection + ' 部分。');
                        jQuery("document").trigger( "virtualPageView" );
                        if(setGA){
                            setGA.pageView(sectionId);
                        }
                    }

                    // 在這裡可以執行其他你想要的操作
                    // console.log('目前在 ' + sectionId + ' 部分。');
                    
                }
            });
        });
    }

    

    {
        $(document).ready(function () {
            init();
        });
    }

    //public
    return {

    };
};

var tealiumTracking = new tealiumTracking();




