
// // onscroll and on load header class 'add' and 'remove' fucntion
$(document).ready(function () {
  function checkScroll() {
    if ($(window).scrollTop() >= 100) {
      $("header").addClass("scrolled");
    } else {
      $("header").removeClass("scrolled");
    }
  }
  // Run on load
  checkScroll();
  // Run on scroll
  $(window).on("scroll", checkScroll);
});

// counter section script
$(document).ready(function() {
  const counters = $(".count");
  const countersQuantity = counters.length;
  const counter = [];

  for (let i = 0; i < countersQuantity; i++) {
    counter[i] = parseInt(counters[i].innerHTML);
  }

  const count = function(start, value, id) {
    let localStart = start;
    const increment = () => {
      if (localStart < value) {
        localStart++;
        counters[id].innerHTML = localStart;
        setTimeout(increment, 50); // Adjusted interval to 10ms
      }
    };
    increment();
  };

  // Create an intersection observer
  const observer = new IntersectionObserver((entries, observer) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        const index = $(entry.target).index('.count');
        count(0, counter[index], index);
        observer.unobserve(entry.target); // Stop observing once it has been counted
      }
    });
  }, { threshold: 0.1 }); // Adjust the threshold as needed

  // Observe each counter element
  counters.each(function() {
    observer.observe(this);
  });
});

// keyfocusslide
$(document).ready(function(){
	/* Owl Carousel */
  $('#ourclients').owlCarousel({
    loop: true,
    margin: 20,
    nav: false,
    autoplayTimeout:5000,
    autoplay:true,
    responsive: {
        0: {
            items: 2
        },
        600: {
            items: 3
        },
        768: {
            items: 4
        },
        1000: {
          items: 4
        },
        1200: {
        items: 5
        },
        1366: {
            items: 5
        }
    }
}) 

});


$(document).ready(function(){

  $('#buildapplicationslide').owlCarousel({
    loop: true,
    margin: 22,
    nav: false,
    autoplayTimeout:5000,
    autoplay:true,
    responsive: {
      0: {
          items: 1
      },
      600: {
          items: 1
      },
      768: {
          items: 2
      },
      1000: {
        items: 2
      },
      1200: {
      items: 3
      },
      1366: {
          items: 3
      }
    }
})

});


$(document).ready(function(){

  $('#developerhireslider').owlCarousel({
    loop: true,
    margin: 22,
    nav: false,
    autoplayTimeout:5000,
    // autoplay:true,
    responsive: {
        0: {
            items: 1
        },
        600: {
            items: 1
        },
        768: {
            items: 2
        },
        1000: {
          items: 2
        },
        1200: {
        items: 3
        },
        1366: {
            items: 3
        }
    }
})

});

$(document).ready(function(){

  $('#govermentprogram').owlCarousel({
    loop: true,
    margin: 22,
    center: true,
    nav: false,
    autoplayTimeout:5000,
    autoplay:true,
    responsive: {
        0: {
            items: 1
        },
        600: {
            items: 1
        },
        768: {
            items: 1.3
        },
        1000: {
          items: 1.5
        },
        1200: {
        items: 1.8
        },
        1366: {
            items: 1.8
        },
         1600: {
            items: 2
        }
    }
})

});


$(document).ready(function(){

  $('#testimonialsslider').owlCarousel({
    loop: true,
    margin: 22,
    nav: false,
    autoplayTimeout:5000,
    autoplay:true,
    responsive: {
        0: {
            items: 1
        },
        600: {
            items: 1
        },
        768: {
            items: 1
        },
        1000: {
          items: 1
        },
        1200: {
        items: 1
        },
        1366: {
            items: 1
        }
    }
})

});



  tabControl();
  
  var resizeTimer;
  $(window).on('resize', function(e) {
    clearTimeout(resizeTimer);
    resizeTimer = setTimeout(function() {
      tabControl();
    }, 250);
  });

  function tabControl() {
    var tabs = $('.tabbed-content').find('.tabs');
    if(tabs.is(':visible')) {
      tabs.find('a').on('click', function(event) {
        event.preventDefault();
        var target = $(this).attr('href'),
            tabs = $(this).parents('.tabs'),
            buttons = tabs.find('a'),
            item = tabs.parents('.tabbed-content').find('.item');
        buttons.removeClass('active');
        item.removeClass('active');
        $(this).addClass('active');
        $(target).addClass('active');
      });
    } else {
      $('.item').on('click', function() {
        var container = $(this).parents('.tabbed-content'),
            currId = $(this).attr('id'),
            items = container.find('.item');
        container.find('.tabs a').removeClass('active');
        items.removeClass('active');
        $(this).addClass('active');
        container.find('.tabs a[href$="#'+ currId +'"]').addClass('active');
      });
    } 
  }


  	$(".show-more").click(function(event) {
		var txt = $(".hide-part").is(':visible') ? 'Show more +' : 'Show Less -';
		$(".hide-part").toggleClass("show-part");
		$(this).html(txt);
		event.preventDefault();
	});

// const uploadInput = document.getElementById('upload');
//     const fileInfo = document.getElementById('file-info');
//     const removeBtn = document.getElementById('remove-file');
 
//     uploadInput.addEventListener('change', function () {
//         const files = this.files;
 
//         if (files.length > 0) {
//             const fileNames = Array.from(files).map(file => file.name).join(', ');
//             fileInfo.textContent = `Selected file${files.length > 1 ? 's' : ''}: ${fileNames}`;
//             removeBtn.style.display = 'inline-block';
//         } else {
//             fileInfo.textContent = '';
//             removeBtn.style.display = 'none';
//         }
//     });
 
//     removeBtn.addEventListener('click', function () {
//         uploadInput.value = ''; // Clear file input
//         fileInfo.textContent = ''; // Clear display
//         removeBtn.style.display = 'none'; // Hide remove button
//     });

// file upload script
document.querySelectorAll('.file-upload').forEach(uploadBlock => {
  const input = uploadBlock.querySelector('.file-upload__input');
  const info = uploadBlock.querySelector('.file-info');
  const removeBtn = uploadBlock.querySelector('.remove-file');

  input.addEventListener('change', function () {
    const files = input.files;
    if (files.length > 0) {
      const fileNames = Array.from(files).map(file => file.name).join(', ');
      info.textContent = `Selected file${files.length > 1 ? 's' : ''}: ${fileNames}`;
      removeBtn.style.display = 'inline-block';
    } else {
      info.textContent = '';
      removeBtn.style.display = 'none';
    }
  });

  removeBtn.addEventListener('click', function () {
    input.value = '';       // Reset file input
    info.textContent = '';  // Clear file info
    removeBtn.style.display = 'none'; // Hide button
  });
});

const slider = document.getElementById('ratingSlider');
    const slides = slider.children;
    const slideHeight = 60;
    let index = 0;

    // Clone slides for smooth infinite effect
    slider.innerHTML += slider.innerHTML;

    const totalSlides = slider.children.length;

    function moveSlide() {
      index++;
      slider.style.transform = `translateY(-${index * slideHeight}px)`;
      slider.style.transition = "transform 0.5s ease-in-out";

      if (index === totalSlides / 2) {
        setTimeout(() => {
          slider.style.transition = "none";
          index = 0;
          slider.style.transform = `translateY(0)`;
        }, 500);
      }
    }

    setInterval(moveSlide, 2500);