// $(document).ready(function(){ // $(".personaliseDiv").hide(); // $(".show_hide").show(); // // $('.show_hide').click(function(){ // $(".personaliseDiv").slideToggle(); // }); // }); var descriptionButton = $('#description-button'); function removeFocus() { //$('input[autofocus]').blur(); //$("input").removeAttr("autofocus"); //$("input").prop("autofocus", false); } //when dom is ready $(document).ready(function(){ $('body').attr('style', ''); // Remove autofocus from personalisations // ====================================== removeFocus(); // Make all usp description same size fMakeAllUSPDescriptionsSameSize(); // On window resize $(window).on('resize', function() { // Make all usp description same size fMakeAllUSPDescriptionsSameSize(); }); // Grab all product size boxes var aProductSizeBoxs = $(".product-size"); // Store the max size var nMaxSize = 0; // Loop through every box aProductSizeBoxs.each( function() { // If this is the biggest box if( $(this).width() > nMaxSize ) { // Make this the big box nMaxSize = $(this).width(); } }); // Loop through every box to set the size aProductSizeBoxs.each( function() { // Set the size of the box $(this).width( nMaxSize); }); $('[data-toggle="popover"]').popover(); fUpdateDropdowns(); // call firstload function fFirstLoad(); //initialise the fancybox plugin on all a tags with class preview-img-2 $("a.preview-img-2").fancybox(); //$("a.preview-img-2").prettyphoto(); $.ajax({ type: "GET", url: "ajax/ajax_seo-content-fix.php", data:{nPage_ID: 8005, sPageContent: "main"}, success: function(data){ $("#tabbed-delivery .tab-view-inner-wrapper").html(data); } }); $(".top-cart-override").click(function(){ $('html, body').animate({ scrollTop: $('#description-button').offset().top }, 2000); descriptionButton.click(); }); if($("#nVehicleModel_ID").length) { $(".ShopProd_Detail_Variations tr").each(function(){ // get the tc var oTC = $(this).find(".tc"); if(oTC.html().indexOf("Size")>=0 || oTC.html().indexOf("SIZE")>=0) { $(this).find(".ShopProd_Detail_OptionsDropDown").eq(0).attr("disabled","disabled"); $(this).find(".ShopProd_Detail_OptionsDropDown").eq(0).find("option").eq(0).html("Choose a make and model above"); } }); } fVehicleVariationDropdown($("#nVehicleModel_ID")[0]); $(".car-button").click(function(){ $(".car-4x4-button").removeClass("active-button"); $(".car-button").addClass("active-button"); $('.car-4x4-preview-container').fadeOut(400); setTimeout(function(){ $('.car-preview-container').fadeIn(); }, 400); }); $(".car-4x4-button").click(function(){ $(".car-button").removeClass("active-button"); $(".car-4x4-button").addClass("active-button"); $('.car-preview-container').fadeOut(400); setTimeout(function(){ $('.car-4x4-preview-container').fadeIn(); }, 400); }); // CA changes May 2023 // ------------------- // Only certain car makes allow logos, as such we need to get/display the logo // fields as relevant when a car make is selected that allows the logos // If this shop product is the Custom Indoor Car Cover (88 is the logo personalisation ID for this car cover) if( $("select[data-personalisation-id='88']").length ) { // Disable the logo customisation category by default, as we only want to display if // this is enabled for the specific car make (EG on custom car indoor cover there is a section) // for the 'Logo' field where you can seled 2 buttons to add a logo, disable it by default on page load $("#CustomisationCategory_4").hide(); } // If we have a logo block (EG there is a logo personalisation for this cover // that isn't wanting to always be on display) // // If a peronslisation is set to be ignored because its a logo cover and needs come from the frontend, // then we instead have a 'logo-block' class added to a hidden table row which allows us to know where to inser // the logo options to the ordering is correct if( $(".logo-block").length ) { // When a different vehicle model is selected $("#nVehicleMake_ID").on("change", function(){ // Load the logo option if applicable fLoadLogoOptionIfApplicable(); }); // If we by default have a vehicle make selected, work out if we need the logo option initally or not if( $("#nVehicleMake_ID").val() != "" ) { fLoadLogoOptionIfApplicable(); } } // Store an array of all the select option IDs for custom made covers var aCustomPersonalisationSelectOptionIDs = [ 78, ]; // Loop over all the custom personalisation select option IDs for( let nIndex = 0; nIndex < aCustomPersonalisationSelectOptionIDs.length; nIndex++ ) { // If there is a select box for this ID if( $("select[data-personalisation-id='"+ aCustomPersonalisationSelectOptionIDs[nIndex] + "']").length ) { // When this option is changed $("select[data-personalisation-id='"+ aCustomPersonalisationSelectOptionIDs[nIndex] + "']").on("change", function(){ // Store the new val let sNewValue = $(this).val(); // Find the button matching this val let oMatchingButton = $(".additional-custom-section button[data-personalisation-id='"+ aCustomPersonalisationSelectOptionIDs[nIndex] + "'][data-button-value='" + sNewValue + "']"); // Click it if it exists, to make sure that all relevant changes are made if( oMatchingButton.length ) { oMatchingButton.click(); } }); } } if($("#WindDeflectorInfo").length) { $("#nVehicleModel_ID").on("change", function(){ // AJAX a page to get the wind deflector information, dump it in the Wind Deflector Info div $.ajax({ type: "POST", url: "ajax/vehicle_get-wind-deflector.php", data:{nVehicleModel_ID: $(this).val()}, success: function(data){ $("#WindDeflectorInfo").html(data); } }); }); if($("#nVehicleModel_ID").length) { if($("#nVehicleModel_ID").val()!="0" && $("#nVehicleModel_ID").val()!="") { $.ajax({ type: "POST", url: "ajax/vehicle_get-wind-deflector.php", data:{nVehicleModel_ID: $("#nVehicleModel_ID").val()}, success: function(data){ $("#WindDeflectorInfo").html(data); } }); } } } $(".col-xs-6 > .color-box").click(function(){ if($(this).data("customisation-id")!="") { var $colorPicker = $(".color-picker"); // default to hiding the piping and stripes only colours $('div[data-stripes-only="true"]').hide(); $('div[data-piping-only="true"]').hide(); // stripes - show stripes only colours (if applicable) if ( ($(this).attr("data-preview-image") ==="stripe-centre") || ($(this).attr("data-preview-image") ==="stripe-left") || ($(this).attr("data-preview-image") ==="stripe-right") ) { $('div[data-stripes-only="true"]').show(); } // piping - show piping only colours (if applicable) if($(this).attr("data-preview-image") ==="car-piping") { $('div[data-piping-only="true"]').show(); } if($colorPicker.css("display") != "none") { $this = $(this); $(".color-picker .nAddCustomOption_ID").val($this.data("customisation-id")); $colorPicker.insertAfter($this); if($(window).outerWidth(true)>768) { $colorPicker.css("top",($this.position().top-($colorPicker.innerHeight()/2)+15)+"px"); $colorPicker.css("left",($this.position().left-270)+"px"); } else { $colorPicker.css("left", "20px"); $colorPicker.css("right", "20px"); $colorPicker.css("top", "50%"); if( ($colorPicker.offset().left + $colorPicker.innerWidth()) > $(window).width() ) { $colorPicker.css("left", "-100px"); $colorPicker.css("right", "20px"); $colorPicker.css("top", "50%"); } } } else { $this = $(this); $(".color-picker .nAddCustomOption_ID").val($(this).data("customisation-id")); $colorPicker.insertAfter($(this)); $colorPicker.fadeIn(); if($(window).outerWidth(true)>768) { $colorPicker.css("top",($this.position().top-($colorPicker.innerHeight()/2)+15)+"px"); $colorPicker.css("left",($this.position().left-270)+"px"); } else { $colorPicker.css("left", "20px"); $colorPicker.css("right", "20px"); $colorPicker.css("top", "50%"); if( ($colorPicker.offset().left + $colorPicker.innerWidth()) > $(window).width() ) { $colorPicker.css("left", "-120px"); $colorPicker.css("right", "20px"); $colorPicker.css("top", "50%"); } } } } }); $(".color-picker .color-box").click(function(){ var $colorPicker = $(".color-picker"); if($colorPicker.css("display") != "none") { var nAddCustomOption_ID = $(".color-picker .nAddCustomOption_ID").val(); var $oBaseColorBox = $(".color-box[data-customisation-id='"+nAddCustomOption_ID+"']"); $oBaseColorBox.attr("style",$(this).attr("style")); var sPreviewImage = $oBaseColorBox.data("preview-image"); $("img[data-piece='"+sPreviewImage+"'][data-type='car']").attr("src","images/customisations/car/car-get-image.php?sRGB="+$oBaseColorBox.css("background-color").replace("rgb(","").replace(")","")+"&sImageName=base-"+sPreviewImage); $("img[data-piece='"+sPreviewImage+"'][data-type='car-top']").attr("src","images/customisations/car/car-get-image.php?sRGB="+$oBaseColorBox.css("background-color").replace("rgb(","").replace(")","")+"&sImageName=base-top-"+sPreviewImage); $("img[data-piece='"+sPreviewImage+"'][data-type='4x4']").attr("src","images/customisations/4x4/4x4-get-image.php?sRGB="+$oBaseColorBox.css("background-color").replace("rgb(","").replace(")","")+"&sImageName=base-"+sPreviewImage); $("img[data-piece='"+sPreviewImage+"'][data-type='4x4-top']").attr("src","images/customisations/4x4/4x4-get-image.php?sRGB="+$oBaseColorBox.css("background-color").replace("rgb(","").replace(")","")+"&sImageName=base-top-"+sPreviewImage); $("#inputfield"+$(".color-box[data-customisation-id='"+nAddCustomOption_ID+"']").data("personalisation-id")).val($(this).data("colour-name")); $colorPicker.fadeOut(); } }); $(".color-picker .close-button").click(function(){ var $colorPicker = $(".color-picker"); if($colorPicker.css("display") != "none") { $colorPicker.fadeOut(); } }); $(".additional-custom-section button").click(function(){ // First, turn off all other buttons on this row $(this).parent().find("button").each(function(){ $(this).removeClass("selected-option"); if($(this).data("preview-image")) { var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").hide(); } }); // Hide all colour boxes relating to buttons in this section $(this).parent().find(".col-xs-6").addClass("hidden-color-box"); // Hide all previews relating to buttons in this section $(this).parent().find(".col-xs-6 .color-box").each(function(){ var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").hide(); // Set all personalisation colour boxes to NA $("#inputfield"+$(this).data("personalisation-id")).val("Not Applicable"); }); // Turn on this box $(this).addClass("selected-option"); var $nCustomisation_ID = $(this).data("customisation-id"); var $sButtonValue = $(this).data("button-value"); var $nPersonalisationOption_ID = $(this).data("personalisation-id"); // Does this select box have it's own toggle? if($(this).attr("data-toggle")) { // Is this an on toggle or an off toggle? if($(this).data("toggle")=="on") { // If on, show everything // Show our colour boxes $(".customisation-field-"+$nCustomisation_ID+"[data-parent-value='"+$sButtonValue+"']").removeClass("hidden-color-box"); // Show all previews relating to buttons in this section $(".customisation-field-"+$nCustomisation_ID+"[data-parent-value='"+$sButtonValue+"'] .color-box").each(function(){ var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").show(); }); // Does this have previews? If so, show them if($(this).data("preview-image")) { var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").show(); } // Change the personalisation dropdown $("select[data-personalisation-id='"+$nPersonalisationOption_ID+"']").val($sButtonValue); } else { // If off, hide everything // Hide our colour boxes $(".customisation-field-"+$nCustomisation_ID+"[data-parent-value='"+$sButtonValue+"']").addClass("hidden-color-box"); // Hide all previews relating to buttons in this section $(".customisation-field-"+$nCustomisation_ID+"[data-parent-value='"+$sButtonValue+"'] .color-box").each(function(){ var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").hide(); }); // Does this have previews? If so, hide them if($(this).data("preview-image")) { var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").hide(); } // Change the personalisation dropdown $("select[data-personalisation-id='"+$nPersonalisationOption_ID+"']").val($sButtonValue); } } else { // Show our colour boxes $(".customisation-field-"+$nCustomisation_ID+"[data-parent-value='"+$sButtonValue+"']").each(function(){ $(this).removeClass("hidden-color-box"); $(this).find(".color-box").each(function(){ $("#inputfield"+$(this).data("personalisation-id")).val("White"); }); }); // Show all previews relating to buttons in this section $(".customisation-field-"+$nCustomisation_ID+"[data-parent-value='"+$sButtonValue+"'] .color-box").each(function(){ var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").show(); }); // Does this have previews? If so, show them if($(this).data("preview-image")) { var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").show(); } // Change the personalisation dropdown $("select[data-personalisation-id='"+$nPersonalisationOption_ID+"']").val($sButtonValue); } }); $(".col-xs-6 > .color-box").each(function(){ var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"'][data-type='car']").attr("src","images/customisations/car/car-get-image.php?sRGB="+$(this).css("background-color").replace("rgb(","").replace(")","")+"&sImageName=base-"+sPreviewImage); $("img[data-piece='"+sPreviewImage+"'][data-type='car-top']").attr("src","images/customisations/car/car-get-image.php?sRGB="+$(this).css("background-color").replace("rgb(","").replace(")","")+"&sImageName=base-top-"+sPreviewImage); $("img[data-piece='"+sPreviewImage+"'][data-type='4x4']").attr("src","images/customisations/4x4/4x4-get-image.php?sRGB="+$(this).css("background-color").replace("rgb(","").replace(")","")+"&sImageName=base-"+sPreviewImage); $("img[data-piece='"+sPreviewImage+"'][data-type='4x4-top']").attr("src","images/customisations/4x4/4x4-get-image.php?sRGB="+$(this).css("background-color").replace("rgb(","").replace(")","")+"&sImageName=base-top-"+sPreviewImage); $("#inputfield"+$(this).data("personalisation-id")).val($(this).data("colour-name")); $("#inputfield"+$(this).data("personalisation-id")).parent().parent().parent().hide(); }); $(".additional-custom-section button").each(function(){ if(!$(this).hasClass("selected-option")) { // Hide our previews var $nCustomisation_ID = $(this).data("customisation-id"); var $sButtonValue = $(this).data("button-value"); $(this).parent().find(".customisation-field-"+$nCustomisation_ID+"[data-parent-value='"+$sButtonValue+"'] .color-box").each(function(){ var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").hide(); }); // Does this have previews? If so, hide them if($(this).data("preview-image")) { var sPreviewImage = $(this).data("preview-image"); $("img[data-piece='"+sPreviewImage+"']").hide(); } // Turn all colour boxes within to Not Applicable $(this).parent().find(".color-box").each(function(){ $("#inputfield"+$(this).data("personalisation-id")).val("Not Applicable"); }); } //$(".ShopProd_Detail_PersonalisationOptionsDropDown[data-personalisation-id='"+$(this).data("personalisation-id")+"']").parent().parent().parent().hide(); }); $("a.youtube-link").fancybox({ 'transitionIn' : 'none', maxWidth: 1000, maxHeight: 750, fitToView: false, width: '80%', height: '80%', autoSize: false, }); $('body').attr('style', ''); }); //hides the non selected tabs when the document loads function fFirstLoad(){ $('#tabbed-specifications').hide(); $('#tabbed-sizing').hide(); $('#tabbed-delivery').hide(); $('#tabbed-review').hide(); } //controller for the tab section , fed in by the buttoms function fSelectTab($tab){ //the first time the script runs it removes the class fakehover. //face hover exists to give the default tab option have the same //style as if it was selected manually if(descriptionButton.hasClass('fakehover')){ descriptionButton.removeClass('fakehover'); } //this uses the naming convention of divs with a set class having the //the id 'tabber-$tab" so you can loop through the class // and identify the one that should be shown by id $tabprefix = "tabbed-"; $btnsuffix = "-button"; //for each div class hidable tab $('.hidable-tab').each(function(element){ //check if it has the correct id, if it does show it //otherwise hide it if(this.id == $tabprefix+$tab) { $(this).show(); } else{ $(this).hide(); } }); $('.category-button').each(function(element){ if(this.id == $tab+$btnsuffix){ $(this).addClass('fakehover'); } else { $(this).removeClass('fakehover'); } }); } //this manages the social buttons on the main image, //pull the contianer down over the image if the button //is pushed function fPullDown(){ $('#social-left-img-wrapper').toggleClass('social-pulldown'); $('#mg-glass-main').toggleClass('mg-push'); } function fVehicleModelDropdown(oElement, nShopProd_ID) { var $oElement = $(oElement); var val = $oElement.val(); var oVehicleModelDropdown = $("#nVehicleModel_ID"); $.ajax({ type: "POST", url: "ajax/vehicle_get-models.php", data:{nVehicleMake_ID: val, nShopProd_ID: nShopProd_ID}, success: function(data){ oVehicleModelDropdown.html(data); } }); } /* fLoadLogoOptionIfApplicable =========================== This function is called when there is a change to the car selection box, it loads the relevant logo option if applicable */ function fLoadLogoOptionIfApplicable(){ // Do an AJAX request to get logo information (EG if the logo is not enabled for car make) // then it'll do nothing, otherwise it'll display the logo box $.ajax({ type: "POST", url: "ajax/vehicle_get-logo.php", data:{nVehicleMake_ID: $("#nVehicleMake_ID").val(), nShopProdPersonalisationOption_ID : $(".logo-block").data("logo-personalisation-id")}, success: function(data){ // If we already have some logo data then we will want to remove it with the most // up to date information if( $(".logo-data").length ) { // Then delete it $(".logo-data").remove(); } // If we are on the custom indoor car cover page, we also // have an option to display the colour, so disable it if // applicable var oAdditionalLogoOption = $("select[data-personalisation-id='88']"); // If the response is not empty, then we need to inser the data response // into the HTML below the logo block to preserve the correct ordering if( data != '' ) { // Set the HTML for the logo block to contain the response $(".logo-block").after(data); // If there is a logo additional option for custom indoor car cover, then show it if( oAdditionalLogoOption.length ) { // Show all relevant logo fields (The parent.parent selector gets the table row) // whilst oAdditionalLogoOption is the select field oAdditionalLogoOption.show(); oAdditionalLogoOption.parent().parent().parent().show(); // Show the logo customisation category $("#CustomisationCategory_4").show(); // Make it so when the logo box is changed, it also updates the relevant button // If there is a select box for this ID if( $("select[data-personalisation-id='"+ "81" + "']").length ) { // When this option is changed $("select[data-personalisation-id='"+ "81" + "']").on("change", function(){ // Store the new val let sNewValue = $(this).val(); // Find the button matching this val let oMatchingButton = $(".additional-custom-section button[data-personalisation-id='"+ "81" + "'][data-button-value='" + sNewValue + "']"); // If the button exists if( oMatchingButton.length ) { // Click it oMatchingButton.click(); } }); } } } else // If there is a logo additional option, then hide it if( oAdditionalLogoOption.length ) { // Hide all relevant logo fields (The parent.parent selector gets the table row) // whilst oAdditionalLogoOption is the select field, and also reset the logo value to nothing oAdditionalLogoOption.val(""); oAdditionalLogoOption.hide(); oAdditionalLogoOption.parent().parent().parent().hide(); // On custom car covers we also have a section for the add a logo, of which when clicked // will change the car cover image to contain a spot for the logo. // If we have switched to a car cover that doesn't allow logos, then we want to hide this // on the car cover selection, so invoke the button click for no if( $("button[data-toggle='off']").length ) { // As there is no data provided for a logo option, make sure that logos // isn't on the custom indoor car cover images $("button[data-toggle='off']").click(); } // Hide the logo customisation category $("#CustomisationCategory_4").hide(); } } }); } function fVehicleVariationDropdown(oElement) { if(typeof(oVehicleModelLink) !== "undefined" && typeof(oElement) !== "undefined") { for(var nShopProdVariation_ID in oVehicleModelLink[oElement.value]) { document.getElementsByName(nShopProdVariation_ID+"nShopProdVariationOption_ID")[0].value = oVehicleModelLink[oElement.value][nShopProdVariation_ID]; fUpdateDropdowns(); } fShowHidePersonalisations(oElement.value); } // Store the product modal var oProductInfoModal = $(".product-info-modal-hide"); // If we haven't already displayed the modal if( oProductInfoModal.length != 0 ) { // If the dropdown box isn't empty if( $("#nVehicleModel_ID").val() != "" ) { // Show the modal oProductInfoModal.show(300); // Remove the class oProductInfoModal.removeClass("product-info-modal-hide"); } } } function fShowHidePersonalisations(nVehicleModel_ID) { if(nVehicleModel_ID>0) { $("tr").each(function(){ var vehicleids = $(this).attr("data-vehicleids"); if(typeof vehicleids !== typeof undefined && vehicleids !== false) { if(vehicleids.indexOf(nVehicleModel_ID)>=0) { $(this).show(); $(this).find("input").removeAttr("disabled"); $(this).find("select").removeAttr("disabled"); $(this).find("select").show(); $(".mirror-pockets-desc").show(); // CA ticket #20205 // ---------------- // Make it so that if for Ultimate Car cover, if selecting toyota yaris GR, is forces customer to have mirror pockets if( $("#nVehicleMake_ID").length && $("#nVehicleMake_ID").val() == "17027" && $("#nVehicleModel_ID").length && $("#nVehicleModel_ID").val() == "172620" ) { // If we have the personalisation enabled for this (Ultimate car cover personalisation for mirror pockets) if( $("select[data-personalisation-id='198']").length ) { // Get the personalisation option for mirror pockets for the ultimate outdoor car cover var oMirrorPocketsPersonalisation = $("select[data-personalisation-id='198']"); // Force the selection of 'Yes' oMirrorPocketsPersonalisation.val("Yes"); // Disable it oMirrorPocketsPersonalisation.attr("disabled","disabled"); } } } else { // If we have the personalisations enabled for ultimate outdoor car covers, then we want to reset it before disabiling if( $("select[data-personalisation-id='198']").length ) { // Get the personalisation option for mirror pockets on the toyota yaris var oMirrorPocketsPersonalisation = $("select[data-personalisation-id='198']"); // Reset it oMirrorPocketsPersonalisation.val(""); } $(this).hide(); $(this).find("input").attr("disabled","disabled"); $(this).find("select").attr("disabled","disabled"); $(".mirror-pockets-desc").hide(); } } }); // Classic Additions Colour Fix if($("select[data-personalisation-id='147']").length && $("select[name='128nShopProdVariationOption_ID']")) { var oColourBox = $("select[name='128nShopProdVariationOption_ID']"); var oMirrorBox = $("select[data-personalisation-id='147']"); if(oMirrorBox.parent().is(":visible")) { if(oColourBox.val()=="399" || oColourBox.val()=="401") { oMirrorBox.hide(); oMirrorBox.attr("disabled","disabled"); oMirrorBox.parent().find(".mirror-pockets-unavailable").show(); } else { oMirrorBox.show(); oMirrorBox.removeAttr("disabled"); oMirrorBox.parent().find(".mirror-pockets-unavailable").hide(); } } } } } /* MAKE ALL USP DESCRIPTIONS SAME SIZE =================================== */ function fMakeAllUSPDescriptionsSameSize() { // IF we are on desktop if( $(window).width() >= 991 ) { // Store the beiggest USP description height var nBiggestUSPDescriptionHeight = 0; // Loop through all usp descriptions $(".usp-desc").each( function() { // If the height of this is the biggest if( $(this).height() > nBiggestUSPDescriptionHeight ) { // Store the height nBiggestUSPDescriptionHeight = $(this).height(); } }); // Loop through all usp descriptions $(".usp-desc").each( function() { // Store the height $(this).css( { height : nBiggestUSPDescriptionHeight + "px" } ); }); } else { // Loop through all usp descriptions $(".usp-desc").each( function() { // Store the height $(this).css( { height : "" } ); }); } } /* Slideshow ========= */ var oSlideshowInterval = null; var nPointer = 0; var aSlideIDs = []; var bTransitioning = false; var nSeconds = 4; $(window).on("load", function(){ $(".slide").each(function(element){ aSlideIDs.push($(this).attr("id")); }); nPointer = aSlideIDs.length-1; $('
').appendTo(".slides-container"); oSlideshowInterval = setInterval(function(){ if(bTransitioning) return; bTransitioning = true; nPointer++; if(nPointer>(aSlideIDs.length-1)) nPointer = 0; fRenderSlides(); },nSeconds*1000); }); function fRenderSlides() { var $oLastImage = $(".slide[id='"+aSlideIDs[nPointer]+"']").last(); $(".slide[id!='"+aSlideIDs[nPointer]+"']").each(function(){ $(this).fadeOut(1000); }); // If we have a data image (Lazyloading, then load the next slide's image) if( $oLastImage.attr("data-image") != null ) { $oLastImage.css("background-image", "url(" + $oLastImage.attr("data-image") + ")"); $oLastImage.removeAttr("data-image"); } $oLastImage.fadeIn(1000); setTimeout(function(){ bTransitioning = false; }, 1000); } function fLeft() { if(bTransitioning) return; bTransitioning = true; if(oSlideshowInterval!=null) clearInterval(oSlideshowInterval); nPointer--; if(nPointer<0) nPointer = aSlideIDs.length-1; fRenderSlides(); } function fRight() { if(bTransitioning) return; bTransitioning = true; if(oSlideshowInterval!=null) clearInterval(oSlideshowInterval); nPointer++; if(nPointer>(aSlideIDs.length-1)) nPointer = 0; fRenderSlides(); }