
////site-uploads/1001454/frontjs/odometer.js
function ad_odmeter() { 
   $("#page_59260 .thumb.card").each(function(index,element){
   $(element).find(".stock-num").after( $(element).find(".spec-col.odometer"));
});
}

$(function(){
   ad_odmeter();
 });

$( document ).ajaxComplete(function( event, request, settings ) {
   ad_odmeter();
 });

////site-uploads/1001454/frontjs/main_v2.2.js
/* Menu */
$(document).ready(function () {
  $(".navbar-toggle").on("click", function () {
      $(this).toggleClass("active");
  });
});

/* Active State Menu */
$(document).ready(function () {
  var url = window.location.pathname;
  $('ul.nav a[href="'+ url +'"]').parent().addClass('active');
  $('ul.nav a').filter(function() {
       return this.href == url;
  }).parent().addClass('active');
});

/* Sticky Menu on Scroll */
$(function () {
  $(window).on("scroll", function () {
      if ($(window).scrollTop() > 48) {
          $("#comp_1668452153863").addClass("sticky-nav");
      } else {
          $("#comp_1668452153863").removeClass("sticky-nav");
      }
  });
});

/* Slide to top */
$(document).ready(function () {
  $("a[href='#top']").on('click', function (e) {
    e.preventDefault();
    $("html, body").animate({
      scrollTop: 0
    }, "slow");
    return false;
  });
});

$(function () {
	/*Delete slider component in mobile*/
	if ($(window).width() < 768) {
		$('.slide').remove();
		$('.hidden-xs').remove();
		$('.desktop-only').remove();
		$('.bottom-sheet').remove();
	}
});

$(function(){
  $( document ).ajaxComplete(function( event, request, settings ) {
    if($('.stock-num').size()>0){
      if($('.stock-num').html().search('  MN')>0){
        $('.price-box').hide();
      }
    }
  
    for(var i=0; i<$('.specs').length; i++){
      if($('.specs').eq(i).html().search('<span> MN')>0 || $('.specs').eq(i).html().search('<span>MN')>0){
        $('.specs').eq(i).parent().addClass("stock-MN");
      }
    }
  
  
    /*Adding shop Online Policy*/
    if($('.add-to-cart').size()>0 && $('.srp-online-shop').size()==0){
      //$('.add-to-cart').parent().before("<a class='srp-online-shop' data-target='#myModal' data-toggle='modal' data-whatever='' href='#' type='button'>Online Shopping Policy</a>");
	  $('.right-cta-buttons').prepend("<a class='srp-online-shop' data-target='#myModal' data-toggle='modal' data-whatever='' href='#' type='button'>Online Shopping Policy</a>")
    }
    
    /*Hide order by lowest to highest when instock is selected*/
    if($('#order').val()=="instock"){
      $('.orderAD').hide();
    }
    else{
      $('.orderAD').show();
    }
  
  
    /*Add Newsletter checkbox to all forms */
    if($('.formsParent').size()>0 && $(".Newsletter-signup").size()==0){
      $('.formsParent .SendCopyCheck').before('<div class="Newsletter-signup"><input type="checkbox" name="Newsletter" checked id="Newsletter-btn" value="1" title="Newsletter Sign up"><label>Sign Up for our Newsletter</label></div>');
    }
  
  
    /*Mailchimp code*/
    window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';
  /* Remove Kawasaki Parts prices  in SRP */
    /*$('.parts2021 .grid-group-item').each(function(event){
      if($(this).text().search('Kawasaki')>0){
        $(this).find('.price, .srp-online-shop, .add-to-cart-btn').hide();
      }
    });*/
  
  /*Adding condition to collapse subcategory in parts SRP based on Jesse request */
/*make sub category open based on Task #36168 from Jonathan Renner */
  if($('.parts2021').size()>0){
    if(!(window.location.href.search("lastFilter]=categoryId")>1||window.location.href.search("lastFilter]=subcategoryId")>1)){
      /*$('.static_filter_gather_data_subcategory_filter').collapse('hide');*/

	$('.static_filter_gather_data_make_filter').collapse('hide');
      $('.static_filter_gather_data_price_stats').collapse('hide');
    }
  }
  });
  
  $(function(){
    /* Remove Kawasaki Parts prices  in SRP */ // Commented by abdallah while it marked some ads as hidden that was manually uploaded by them and removing prices was handled byb CDK side unsin stock number starts with AK or WN
    /*$('.parts2021 .grid-group-item').each(function(event){
      if($(this).text().search('Kawasaki')>0){
        $(this).find('.price, .srp-online-shop, .add-to-cart-btn').hide();
      }
    });
    // Remove Kawasaki Parts prices  in VDP 
    if($('.parts-vdp .manufacturer').text().search('Kawasaki')>0){
      $('.parts-price-div, #qautity-add-box').hide();
    }*/
    
    
  });
  
  /*Custom titles for Yamaha and Kawasaki Parts pages*/
  if(pageId==59376 || pageId==59377){
    $('.yamaha-parts a').click(function(){
      localStorage.setItem("parentpage", $(this).text());
      localStorage.setItem("parent_ttl", $(this).parents('.yamaha-parts').children('.online-text').text());
      });	
  }
  if(pageId==59370 || pageId==59369){
    var oldTitle= $('.title-container h3').text()+ " - ";
    if(pageId==59369){
      var oldTitle2= localStorage.getItem("parent_ttl");
      oldTitle = oldTitle+ oldTitle2+", ";
    }
  
    $('.title-container h3').text(oldTitle+ localStorage.getItem("parentpage"));
  }
  
  /*Force VDP to open the first option when load */
    if($('.parts-vdp').size()>0 && $('.main-option').size()>0){
      if( $('.main-option').val().indexOf($('.add-to-cart-btn').attr('data-itemid'))<0){
        window.location = ('/'+pageName+$('.main-option').val());
      }
    }
    
  });

  /* Hide html above component on vdp */
if($("#detailsParentDiv").size()>0){
	$('.inventory-page').css("display","none");
	};
	
	
/*Add custom script to hide make and siplay only if cat and sub cats are selected for shop online page, requested by Jesse , subject: CATEGORIES */

$(function(){
  $( document ).ajaxComplete(function( event, request, settings ) {
	  $('.parts2021 .filter-collapse-container.Make').hide();
	  $('.parts2021 #subcategory_filterSection .regular-checkbox').each(function(elem){
			if($(this).is(":checked")){
			  $('.filter-collapse-container.Make').show();
			}
		});
	});
});
////site-uploads/1001454/frontjs/breadcrumbs.js
jQuery(function ($) {
  /* Start for add custom breadcrumb Link */
  function returnPageSlug() {
    console.log('window.location.href => ', window.location.href);
    var allURL = window.location.href;
    var domainName = window.location.hostname;
    var currentPage = allURL.replace(domainName, '');
    var currentPage = currentPage.replace('https', '');
    var currentPage = currentPage.replace('http', '');
    var currentPage = currentPage.replace(/\//g, '');
    var currentPage = currentPage.replace(/:/g, '');
    if (currentPage.includes('?')) {
      var currentPage = currentPage.slice(0, currentPage.indexOf('?'));
    }
    console.log('currentPage => ', currentPage);
    return currentPage;
  }

  var pagesNeedCustomBreadcrumb = [
    // {
    //   target: {
    //     name: 'BOAT & PWC LIFTS',
    //     url: '/Boat-&-PWC-Lifts'
    //   },
    //   pages: [
    //     'Naylor-Dock-Products-'
    //   ]
    // }
  ];
  /* End It Here*/
  if ($('nav.breadcrumbParent').length) {
    var breadcrumbListItemsCount = $('ol.breadcrumb li').length;

    /*Related to add custom breadcrumb*/
    if (pagesNeedCustomBreadcrumb && pagesNeedCustomBreadcrumb.length !== 0) {
      var currentPageURL = returnPageSlug();
      for (let i = 0; i < pagesNeedCustomBreadcrumb.length; i++) {
        console.log(pagesNeedCustomBreadcrumb[i]);
        if (pagesNeedCustomBreadcrumb[i].pages.includes(currentPageURL)) {
          console.log('found');
          var el =
            '<li class="breadcrumb-item" style="text-transform: capitalize;"><a href="' +
            pagesNeedCustomBreadcrumb[i].target.url +
            '">' +
            pagesNeedCustomBreadcrumb[i].target.name +
            '</a></li>';
          $(el).insertBefore($('.breadcrumb-item.active'));
          breadcrumbListItemsCount++;
        }
      }
    }
    /* End It Here*/

    var modelTitle = '';
    if ($('.model-details-content.container .model-title').length) {
      $('.model-details-content.container .model-title').hide();
      modelTitle = $('.model-details-content.container .model-title').text();
    }

    var elementToHide = $('.breadcrumb-item.active');
    var new_title = elementToHide.text();
    console.log('new_title => ', new_title);
    elementToHide.hide();
    new_title = new_title
      .split('-')
      .filter(function (item) {
        item = item ? item.replace(/-/g, '') : item;
        return item;
      })
      .join(' ');

    new_title =
      modelTitle.length === 0 ? new_title.replace(/  +/g, ' - ') : modelTitle;
    /* handle get breadcrumb text from DOM Element */
    var customTitleExist = document.getElementById('_custome_breadcrumb_title');
    if (customTitleExist) {
      console.log(customTitleExist.innerText);
      customTitleExist.style.display = 'none';
      new_title = customTitleExist.innerText;
    }
    console.log('customTitleExist => ', customTitleExist);
    new_titleCharCount = new_title.length;
    if (new_titleCharCount > 25 || breadcrumbListItemsCount > 2 || 1 === 1) {
      var style =
        '<style>@media screen and (max-width: 620px){.breadcrumbParent {flex-direction: column;}.breadcrumbParent h2 {padding-top: 1.5vw;}}</style>';
      $('nav.breadcrumbParent').prepend(style);
    }
    ttlelement = '<h1>' + new_title + '</h1>';
    $('nav.breadcrumbParent').prepend(ttlelement);
    if ($('.col-sm-9.col-xs-12.model-ttl .model-title').length) {
      $('.col-sm-9.col-xs-12.model-ttl .model-title').hide();
    }

    /* start Capitalize other breadcrumb li elements */
    var oltherListItems = $('ol.breadcrumb li').not('.active');
    oltherListItems.each(function () {
      $(this).css({ 'text-transform': 'capitalize' });
    });
    /* End */
  }
});

function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

jQuery(function ($) {
  if (
    $(
      'div.col-lg-8.col-md-10.col-sm-10.col-xs-7.text-left.descColumnResponsive'
    ).length
  ) {
    $(
      'div.col-lg-8.col-md-10.col-sm-10.col-xs-7.text-left.descColumnResponsive'
    ).each(function () {
      console.log($(this).text());
      var text = $(this).text().replace(/\s/g, '');
      if (text === 'N/A') {
        $(this).parent().hide();
      }
    });
  }
});
////site-uploads/1001454/frontjs/speed.js
$(function () {
  /*Delete slider component in mobile*/
  if ($(window).width() < 700) {
    $('#comp_1668452285662').remove();
    $('.slide').remove();
    $('.hidden-xs').remove();
    $('.desktop-only').remove();
  }

  /* load weatehr widget  */
  const userInteractionEvents = [
    'mouseover',
    'keydown',
    'touchmove',
    'touchstart',
  ];
  userInteractionEvents.forEach(function (event) {
    window.addEventListener(event, triggerScriptLoader, {
      passive: true,
    });
  });

  function triggerScriptLoader() {
    loadScripts();
    userInteractionEvents.forEach(function (event) {
      window.removeEventListener(event, triggerScriptLoader, {
        passive: true,
      });
    });
  }

  function loadScripts() {
    if (!$('#myVideo').attr('src')) {
      $('#myVideo').attr('src', '/site-uploads/1001454/Files/video.mp4');
    }

    // if (!$('#_twitter_widgets').length) {
    //   $('._twitter_widgets_wrapper').append(
    //     '<script id="_twitter_widgets" async="" src="https://platform.twitter.com/widgets.js"\
    //     charset="utf-8"></script>'
    //   );
    // }

    // if (!$('.fb-page.fb_iframe_widget').length) {
    //   $('._facebook_iframe_wrapper').prepend(
    //     '<div class="fb-page fb_iframe_widget" data-adapt-container-width="true"\
    //     data-height="400" data-hide-cover="false"\
    //     data-href="https://www.facebook.com/factoryrecreation" data-show-facepile="true"\
    //     data-small-header="true" data-tabs="timeline" data-width=""\
    //     fb-iframe-plugin-query="adapt_container_width=true&amp;app_id=&amp;container_width=300&amp;height=400&amp;hide_cover=false&amp;href=https%3A%2F%2Fwww.facebook.com%2Ffactoryrecreation&amp;locale=en_GB&amp;sdk=joey&amp;show_facepile=true&amp;small_header=true&amp;tabs=timeline&amp;width="\
    //     fb-xfbml-state="rendered"><span\
    //         style="vertical-align: bottom; width: 300px; height: 400px;">\
    //         <iframe allow="encrypted-media" allowfullscreen="true"\
    //             allowtransparency="true" data-testid="fb:page Facebook Social Plugin"\
    //             frameborder="0" height="400px" name="f1f54475f2dff2" scrolling="no"\
    //             src="https://www.facebook.com/v12.0/plugins/page.php?adapt_container_width=true&amp;app_id=&amp;channel=https%3A%2F%2Fstaticxx.facebook.com%2Fx%2Fconnect%2Fxd_arbiter%2F%3Fversion%3D46%23cb%3Dfbacd903315ed%26domain%3Dsimplywebeditor.com%26is_canvas%3Dfalse%26origin%3Dhttp%253A%252F%252Fsimplywebeditor.com%252Ff32796880d54f94%26relation%3Dparent.parent&amp;container_width=300&amp;height=400&amp;hide_cover=false&amp;href=https%3A%2F%2Fwww.facebook.com%2Ffactoryrecreation&amp;locale=en_GB&amp;sdk=joey&amp;show_facepile=true&amp;small_header=true&amp;tabs=timeline&amp;width="\
    //             style="border: none; visibility: visible; width: 300px; height: 400px;"\
    //             title="fb:page Facebook Social Plugin" width="1000px"></iframe></span>\
    // </div>'
    //   );
    // }
  }
});
