function SendEvent() {
    if (typeof SendGaEvent !== "undefined") {
        SendGaEvent.apply(null, arguments);
    }
}
globalThis.SendEvent = SendEvent;

window.onbeforeunload = function () {
    document.documentElement.scrollTop = 0;
    document.body.scrollTop = 0;
}

// Key Visual VideoPlay
$(window).resize(function () {
    if (($(window).width() / $(window).height()) > 2.2) {
        $('#kv-video').addClass('big-video')
    } else {
        $('#kv-video').removeClass('big-video');
    }
});

let vid = document.getElementById("kv-video");
setInterval(() => {
    vid.onpause = function () {
        vid.play();
        vid.loop = true;
        vid.muted = true;
    };
}, 100);
/*//////////////////////////////////////////////// noise-effects ////////////////////////////////////////////////*/
var turbVal = {
    val: 0
},
    turb = document.querySelectorAll('#noise feTurbulence')[0],

    btTl = new TimelineLite({
        paused: true,
        onUpdate: function () {
            turb.setAttribute('baseFrequency', '0 ' + turbVal.val);
        }
    });

btTl.from(turbVal, 0.3, {
    val: 0.4
})
    .to(turbVal, 0.3, {
        val: 0.000001
    });
let noiseAuto = setInterval(() => {
    btTl.restart();
}, 6000);
/*//////////////////////////////////////////////// kf-slider ////////////////////////////////////////////////*/
function kfSliderPrev() {
    if ($('.kf-slider.active').index() == 0) {
        $('.kf-slider:last-child').addClass('active').siblings().removeClass('active');
    } else {
        $('.kf-slider.active').removeClass('active').prev().addClass('active');
    }
}

function kfSliderNext() {
    if ($('.kf-slider.active').index() == $('.kf-slider').length - 1) {
        $('.kf-slider:first-child').addClass('active').siblings().removeClass('active');
    } else {
        $('.kf-slider.active').removeClass('active').next().addClass('active');
    }
}
let kfSliderAuto = setInterval(() => {
    // kfSliderNext()
}, 5000);

function kfSliderUpdate() {
    if ($('.kf-slider.active').index() == 0) {
        $('.kf-slider.active').next().addClass('kf-next').siblings().removeClass('kf-next');
        $('.kf-slider:last-child').addClass('kf-prev').siblings().removeClass('kf-prev');
    } else if ($('.kf-slider.active').index() == $('.kf-slider').length - 1) {
        $('.kf-slider.active').prev().addClass('kf-prev').siblings().removeClass('kf-prev');
        $('.kf-slider:first-child').addClass('kf-next').siblings().removeClass('kf-next');
    } else {
        $('.kf-slider.active').next().addClass('kf-next').siblings().removeClass('kf-next');
        $('.kf-slider.active').prev().addClass('kf-prev').siblings().removeClass('kf-prev');
    }
}
setInterval(() => {
    kfSliderUpdate()
}, 0);
$('.kf-slider-next-btn').click(function () {
    clearInterval(kfSliderAuto);
    kfSliderNext();
    kfSliderUpdate();
    $('.kf-sliders').addClass('next-ani').removeClass('prev-ani');
})
$('.kf-slider-prev-btn').click(function () {
    clearInterval(kfSliderAuto);
    kfSliderPrev();
    kfSliderUpdate();
    $('.kf-sliders').addClass('prev-ani').removeClass('next-ani');
})
ScrollTrigger.create({
    trigger: $('#keyfeature'),
    // markers: true,
    start: "top center",
    end: "+=" + $('#keyfeature').outerHeight(),
    onEnter: () => {
        TriggerToFirstKF();
    },
    onEnterBack: () => {
        TriggerToFirstKF();
    }
});

function TriggerToFirstKF() {
    $('.kf-slider:first-child').addClass('active').siblings().removeClass('active');
    kfSliderUpdate();
}

/*//////////////////////////////////////////////// cool-btns ////////////////////////////////////////////////*/
let Coolbtns = document.querySelectorAll('.cool-btns>div');
let CoolbtnsAuto = setInterval(() => {
    if ($('.cool-btns>div.active').index() == Coolbtns.length - 1) {
        $('.cool-btns>div:first-child').addClass('active').siblings().removeClass('active');
    } else {
        $('.cool-btns>div.active').removeClass('active').next().addClass('active');
    }
    CoolEffect()
}, 10000);
$('.cool-btns>div').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
    clearInterval(CoolbtnsAuto);
    CoolEffect();
    $('.cool-video').removeClass('activeV');
    $('.cool-video-btn').removeClass('activeV');
});

function CoolEffect() {
    for (i = 1; i <= Coolbtns.length; i++) {
        $('.cool-imgs').removeClass('active' + i);
    };
    let curIndex = $('.cool-btns>div.active').index() + 1;
    $('.cool-imgs').addClass('active' + curIndex);
    btTl.restart();
}

ScrollTrigger.create({
    trigger: $('#cool'),
    // markers: true,
    start: "top center",
    end: "+=" + $('#cool').outerHeight(),
    onEnter: () => {
        TriggerToFirst();
    },
    onEnterBack: () => {
        TriggerToFirst();
    }
});

function TriggerToFirst() {
    for (i = 1; i <= Coolbtns.length; i++) {
        $('.cool-imgs').removeClass('active' + i);
    };
    $('.cool-imgs').addClass('active1');
    $('.cool-btns>div:first-child').addClass('active').siblings().removeClass('active');
};

$('.cool-video-btn').click(function () {
    clearInterval(CoolbtnsAuto);
    TriggerToFirst();
    $('.cool-video').addClass('activeV');
    if ($('.cool-video').hasClass('activeV')) {
        $('.cool-video-btn').addClass('activeV');
    } else {
        $('.cool-video-btn').removeClass('activeV');
    }
    let CoolV = document.getElementById('cool-video');
    CoolV.play();
});

/*//////////////////////////////////////////////// performance-btns ////////////////////////////////////////////////*/
let performancebtns = document.querySelectorAll('.performance-btns>div');

let performancebtnsAuto = setInterval(() => {
    if ($('.performance-btns>div.active').index() == performancebtns.length - 1) {
        $('.performance-btns>div:first-child').addClass('active').siblings().removeClass('active');
    } else {
        $('.performance-btns>div.active').removeClass('active').next().addClass('active');
    }
    PerformanceEffects();
}, 6000);

$('.performance-btns>div').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
    clearInterval(performancebtnsAuto);
    PerformanceEffects();
});

function PerformanceEffects() {
    var index = $('.performance-btns>div.active').index() + 1
    $('.performance-img:nth-child(' + index + ')').addClass('active').siblings().removeClass('active');
}
/*//////////////////////////////////////////////// lcd-btns ////////////////////////////////////////////////*/
let LCDbtns = document.querySelectorAll('.lcd-btns>div');
$('.lcd-btns>div').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
    LcdEffects();
});

function LcdEffects() {
    var index = $('.lcd-btns>div.active').index() + 2
    $('.lcd-img-video:nth-child(' + index + ')').addClass('active').siblings().removeClass('active');
}
/*//////////////////////////////////////////////// excellence-btns ////////////////////////////////////////////////*/
let excellencebtns = document.querySelectorAll('.excellence-btns>div');
let excellencebtnsAuto = setInterval(() => {
    if ($('.excellence-btns>div.active').index() == excellencebtns.length - 1) {
        $('.excellence-btns>div:first-child').addClass('active').siblings().removeClass('active');
    } else {
        $('.excellence-btns>div.active').removeClass('active').next().addClass('active');
    }
    excellencebtnsEffect();
    excellenceAsidesEffect();
}, 5000);
$('.excellence-btns>div').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
    clearInterval(excellencebtnsAuto);
    excellencebtnsEffect();
    excellenceAsidesEffect();
});

function excellenceAsidesEffect() {
    $('.excellence-asides>div:nth-child(' + ($('.excellence-btns>div.active').index() + 1) + ')').addClass('active').siblings().removeClass('active');
}

function excellencebtnsEffect() {
    if ($(window).width() > 1200) {
        if ($('.excellence-btns>div.active').index() == 0) {
            $('.excellence-img-bg').css('transform', 'translate(-46%, -28%) scale(1.3)');
        } else if ($('.excellence-btns>div.active').index() == 1) {
            $('.excellence-img-bg').css('transform', 'translate(-51%, -42%) scale(0.8)');
        } else if ($('.excellence-btns>div.active').index() == 2) {
            $('.excellence-img-bg').css('transform', 'translate(-36%, -47%) scale(1.2)');
        } else if ($('.excellence-btns>div.active').index() == 3) {
            $('.excellence-img-bg').css('transform', 'translate(-52%, -70%)');
        } else if ($('.excellence-btns>div.active').index() == 4) {
            $('.excellence-img-bg').css('transform', 'translate(-47%, -54%)');
        } else if ($('.excellence-btns>div.active').index() == 5) {
            $('.excellence-img-bg').css('transform', 'translate(-51%, -50%) scale(.7)');
        }
    } else {
        $('.excellence-img-bg').css('transform', 'translate(-60%, -20%)');
    }
}
/*/////////////////////////////////////////////// RGB ///////////////////////////////////////////////*/
$('.rgb-btns div:nth-child(1)').addClass('active').siblings().removeClass('active');
$('.rgb-bgs>*:nth-child(1)').addClass('active').siblings().removeClass('active');
$('.rgb-btns div').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
    var index = $(this).index() + 1;
    $('.rgb-bgs>*:nth-child(' + index + ')').addClass('active').siblings().removeClass('active');
    $('.rgb-gesture').remove();
});

var wheelPicker = new iro.ColorPicker("#wheelPicker", {
    width: 100,
    color: "rgb(255, 100, 0)",
    borderWidth: 0,
    borderColor: "#fff0",
    layout: [{
        component: iro.ui.Wheel,
    },]
});

wheelPicker.on(['color:init', 'color:change'], function (color) {
    $('.rgb-bg-fill').css('fill', color.hexString);
});

var sliderPicker = new iro.ColorPicker("#sliderPicker", {
    width: 300,
    color: "rgb(255, 100, 0)",
    borderWidth: 0,
    borderColor: "#fff0",
    layout: [{
        component: iro.ui.Slider,
        options: {
            sliderType: 'hue',
            sliderSize: '20'
        }
    },
    {
        component: iro.ui.Slider,
        options: {
            sliderType: 'saturation',
            sliderSize: '20'
        }
    },
    ]
});

sliderPicker.on(['color:init', 'color:change'], function (color) {
    $('.rgb-bg-fill').css('fill', color.hexString);
});

gsap.registerPlugin(ScrollTrigger);

/*/////////////////////////////////////////////// GameAssist ///////////////////////////////////////////////*/
let GameAssistDots = document.querySelectorAll('.GameAssistDots div');
let GameAssistImg = document.querySelectorAll('.GameAssistImgs img');
let GameAssistAuto = setInterval(() => {
    if ($('.GameAssistDots div.active').index() == GameAssistDots.length - 1) {
        $('.GameAssistDots div:first-child').addClass('active').siblings().removeClass('active');
    } else {
        $('.GameAssistDots div.active').removeClass('active').next().addClass('active');
    }
}, 3000);
$('.GameAssistDots div').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
    clearInterval(GameAssistAuto);
});
setInterval(() => {
    for (let i = 0; i < GameAssistDots.length; i++) {
        for (let j = 0; j < GameAssistDots.length; j++) {
            if ($('.GameAssistDots div.active').index() == j) {
                $(GameAssistImg[i]).css('transform', 'translateX(' + ((i - j) * 100) + '%)');
            }
        }
    }
    $(GameAssistImg[$('.GameAssistDots div.active').index()]).addClass('active').siblings().removeClass('active');
});

/////////////////////////////////////////////////// learn more link //////////////////////////////////////////////////
$('.cool-learn-more .link').attr('href', '../WebPage/648/index.html#' + window.location.pathname.replace(/.*\//g, ''));
/////////////////////////////////////////////////// support-link //////////////////////////////////////////////////
$('#support-link').attr('href', window.location.pathname + '/support');
/*/////////////////////////////////////////////// dots ///////////////////////////////////////////////*/
let dots = document.querySelectorAll(".dots a")
dots.forEach(element => {
    ScrollTrigger.create({
        trigger: element.getAttribute('href'),
        // markers: true,
        start: "top center",
        end: "+=" + $(element.getAttribute('href')).outerHeight(),
        onUpdate: () => {
            $(element).find('div').addClass('active').parent().siblings().find('div').removeClass('active');
        }
    });
})

$(function () {
    $.scrollify({
        section: ".InnerGIGABYTEContent .wheel-scroll",
        sectionName: "",
        interstitialSection: "#model-header,.scroll-style,.nvidia-footer,.illustration-announce",
        easing: "easeInOutCubic",
        scrollSpeed: 100,
        offset: 0,
        scrollbars: true,
        standardScrollElements: "",
        setHeights: false,
        overflowScroll: !1,
        updateHash: true,
        touchScroll: false,
        before: function () { },
        after: function () { },
        afterResize: function () {
            $(window).width() > 1200 ? $.scrollify.enable() : $.scrollify.disable()
        },
        afterRender: function () {
            $(window).width() > 1200 ? $.scrollify.enable() : $.scrollify.disable()
        }
    })
})
setInterval(() => { $(document).scrollTop() == 0 ? $.scrollify.update() : void 0 }, 1000)