/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2020 PrestaShop SA
*  @version  Release: jQueryRevisionjQuery
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

  
jQuery(window).load(function ($) {
 
    jQuery('#tvmain-slider').addClass('loading').show();
    var tvmain_slider = jQuery('#tvmain-slider').width();
    jQuery('#tvmain-slider.loading a img').css("width","100%").css("height", ((tvmain_slider*42)/100)+"px");
  
/*************** Start Main Slider Js*****************************************/
    // jQuery(window).on('load', function() {
    //     var tvMainSliderSpeed = jQuery('.tvcmsmain-slider-wrapper').attr('data-speed');
    //     var tvMainSliderPause = '';
    //     if (jQuery('.tvcmsmain-slider-wrapper').attr('data-pause-hover') == 'true') {
    //         tvMainSliderPause = true;
    //     }
    //     jQuery('#tvmain-slider').nivoSlider({
    //           pauseTime: tvMainSliderSpeed,
    //           pauseOnHover: tvMainSliderPause,
    //           controlNav: true,
    //           controlNavThumbs: true,
    //           effect: "random"
    //     });
    // });

    // jQuery('.tvcmsmain-prev').click(function(e){
    //     e.preventDefault();
    //     jQuery('.nivo-directionNav .nivo-prevNav').trigger('click');
    //     jQuery('.tvmain-slider-contant').fadeIn();
    // });

    // jQuery('.tvcmsmain-next').click(function(e){
    //     e.preventDefault();
    //     jQuery('.nivo-directionNav .nivo-nextNav').trigger('click');

    //     jQuery('.tvmain-slider-contant').fadeIn();
    // });
  
 
  function customImgLazyLoadMainSlider() {
    jQuery('#tvmain-slider.loading img.lazy').each(function(e){
        var data_src = jQuery(this).attr('data-src');
        jQuery(this).attr('src',data_src);
        if(!jQuery(this).hasClass('loaded'))        {
          jQuery(this).addClass('loaded');
              jQuery(this).attr({
                  'data-lazyloading': 1
              });
        }
    })/*
      jQuery('#tvmain-slider.loading img.lazy').Lazy({
          scrollDirection: 'vertical',
          visibleOnly: !0,
          onError: function(element) {
              console.log('error loading ' + element.data('src'))
          },
          afterLoad: function(element) {
              element.addClass('loaded');
              element.attr({
                  'data-lazyloading': 1
              });
          },
      });*/
     loadMainSlider();
  }
  setTimeout(function(){customImgLazyLoadMainSlider();},500);
 

  function loadMainSlider(){
    
    jQuery('#tvmain-slider.loading a img').css({'width':'','height':''});
    jQuery('#tvmain-slider').removeClass('loading');
    var tvMainSliderSpeed = jQuery('.tvcmsmain-slider-wrapper').attr('data-speed');
    var tvMainSliderPause = '';
    if (jQuery('.tvcmsmain-slider-wrapper').attr('data-pause-hover') == 'true') {
        tvMainSliderPause = true;
    }

    var mainSliderHomePage = jQuery('.tv-main-slider #tvmain-slider');
    mainSliderHomePage.owlCarousel({
      loop: true,
      dots: true,
      nav: false,
      autoplay:true,
      autoplayTimeout: tvMainSliderSpeed,
      autoplayHoverPause: tvMainSliderPause,
      responsive: {
        0: { items: 1},
        320:{ items: 1, slideBy: 1},
        640:{ items: 1, slideBy: 1},
        768:{ items: 1, slideBy: 1},
        1024:{ items: 1, slideBy: 1},
        1399:{ items: 1, slideBy: 1},
      },
    });
    jQuery('.tvmain-slider-next-pre-btn .tvcmsmain-prev').click(function(e){
      e.preventDefault();
      jQuery('.tv-main-slider .owl-nav .owl-prev').trigger('click');
    });

    jQuery('.tvmain-slider-next-pre-btn .tvcmsmain-next').click(function(e){
      e.preventDefault();
      jQuery('.tv-main-slider .owl-nav .owl-next').trigger('click');
    });

    mainSliderHomePage.on('translated.owl.carousel', function(event) {
      mainSliderHomePageJs();
    });

    function mainSliderHomePageJs()
    {
      var num_index = jQuery('#tvmain-slider .owl-dots').find('.owl-dot.active').index();
      jQuery('.tvmain-slider-content-wrapper .tvmain-slider-content-inner').removeClass('active');
      jQuery('.tvmain-slider-content-wrapper .tvmain-slider-content-inner').eq(num_index).addClass('active');
    }

    jQuery(document).on('click', '.tvmain-slider-content-wrapper .tvmain-slider-content-inner', function(){
      var num_index = jQuery(this).attr('data-index');
      jQuery('.tvmain-slider-content-wrapper .tvmain-slider-content-inner').removeClass('active');
      jQuery(this).addClass('active');
      jQuery('#tvmain-slider .owl-dots .owl-dot').eq(num_index).trigger('click')
    });
  }
   
/*************** End Main Slider Js*****************************************/
});
