var product_images_swiper; $( document ).ready(function() { // Navigation open/close $('.nav-button').on('click', function () { if ($('.animated-icon').hasClass('open')) { $('.animated-icon').removeClass('open'); $('nav').animate({opacity: 0}, 300); setTimeout(function(){ $('nav').removeClass('display'); }, 300); } else { $('.animated-icon').addClass('open'); $('nav').addClass('display'); $('nav').animate({opacity: 1}, 300); } }); // Initialise the carousels var home_swiper_desktop; if (home_swiper_desktop != undefined) { home_swiper_desktop.destroy(); } home_swiper_desktop = new Swiper('#home-swiper-desktop', { autoplay: { delay: 5000, }, effect: 'slide', loop: true, noSwiping: false, noSwipingClass: 'no-swiping', // navigation: { // nextEl: '.swiper-button-next', // prevEl: '.swiper-button-prev', // }, pagination: { el: '.swiper-pagination', }, observer: true, observeParents: true }); var home_swiper_mobile; if (home_swiper_mobile != undefined) { home_swiper_mobile.destroy(); } home_swiper_mobile = new Swiper('#home-swiper-mobile', { autoplay: { delay: 5000, }, effect: 'slide', loop: true, noSwiping: false, noSwipingClass: 'no-swiping', // navigation: { // nextEl: '.swiper-button-next', // prevEl: '.swiper-button-prev', // }, pagination: { el: '.swiper-pagination', }, observer: true, observeParents: true }); // var product_images_swiper; if (product_images_swiper != undefined) { product_images_swiper.destroy(); } product_images_swiper = new Swiper('#product-images-swiper', { autoplay: false, effect: 'slide', loop: true, noSwiping: false, noSwipingClass: 'no-swiping', // navigation: { // nextEl: '.swiper-button-next', // prevEl: '.swiper-button-prev', // }, pagination: { el: '.swiper-pagination', }, observer: true, observeParents: true, watchOverflow: true }); var checkout_swiper; if (checkout_swiper != undefined) { checkout_swiper.destroy(); } checkout_swiper = new Swiper('#checkout-swiper', { autoplay: false, effect: 'slide', loop: false, noSwiping: true, noSwipingClass: 'no-swiping', // navigation: { // nextEl: '.swiper-button-next', // prevEl: '.swiper-button-prev', // }, pagination: { el: '.swiper-pagination', }, observer: true, observeParents: true, watchOverflow: true, preventClicks: false, preventClicksPropagation: false }); // Set click actions $('.qty-minus').unbind('click'); $('.qty-plus').unbind('click'); $('.qty-minus').click(function() { if (parseInt($(this).parent().find('.qty-display').html()) > 1) { $(this).parent().find('.qty-display').html(parseInt($(this).parent().find('.qty-display').html()) - 1); } }); $('.qty-plus').click(function() { if (parseInt($(this).parent().find('.qty-display').html()) < $('#num-in-stock').val()) { $(this).parent().find('.qty-display').html(parseInt($(this).parent().find('.qty-display').html()) + 1); } }); $(".go-to-checkout-1").click(function() { calculateBagTotals(); setTimeout(function(){ window.location.href='checkout.php'; }, 2000); }); $(".go-to-checkout-2").click(function() { checkout_swiper.slideTo(1); }); $(".go-to-checkout-3").click(function() { if ($('#ShoppingBagString').val().indexOf('|') > 0) { checkout_swiper.slideTo(2); sendOrder(); } else { alert('Your shopping bag is empty.'); } }); // Set enter press actions $("#DiscountAmount").on('keyup', function (e) { if (e.keyCode === 13) { $("#DiscountAmountButton").click(); } }); $("#DiscountPercentage").on('keyup', function (e) { if (e.keyCode === 13) { $("#DiscountPercentageButton").click(); } }); // Set correct product attributes as name $('.attribute.active').click(); // Initialise bag totals calculateBagTotals(); }); function formatPrice(price) { price = String(price).replace(',',''); if (price >= 0) { is_negative = ''; price = parseFloat(price); } else { is_negative = '-'; price = parseFloat(price*-1); } return is_negative + document.getElementById('DefaultCurrencySymbol').value + price.toFixed(2).replace(/./g, function(c, i, a) { return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c; }); } function changeTab(evt, tabs, tabid) { var i, tabcontent, tablinks; tabcontent = document.getElementsByClassName(tabs + " tabcontent"); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; } tablinks = document.getElementsByClassName(tabs + " tablinks"); for (i = 0; i < tablinks.length; i++) { tablinks[i].className = tablinks[i].className.replace(" active", ""); } document.getElementById(tabid).style.display = "block"; evt.currentTarget.className += " active"; } var attributes_string = ''; function updateSelectedOption(product_id, attribute_type, attribute) { $('.attribute' + '.' + attribute_type).removeClass('active'); $('.attribute' + '.' + attribute_type + '.' + attribute).addClass('active'); // Find all selected attributes attributes_string = ''; $(".attribute-type").each(function(){ attribute_type = $(this).attr('data-value'); attributes_string = attributes_string + '"'+attribute_type+'":'; // Loop through all attributes and find what is selected $(".attribute-type-"+$(this).attr('data-value')+".active").each(function(){ attribute = $(this).attr('data-value'); attributes_string = attributes_string + '"'+attribute+'",'; if (attribute_type == 'colour') { select_image_attribute = attribute; } }); }); // Find matching data in product options json $.each(JSON.parse(eval('product_options_'+product_id)), function(key, value) { if (JSON.stringify(value).search(attributes_string) > 0) { $('#product_form_'+product_id+'_ProductOptionID').val(value.product_option_id); if (value.sale_price > ' ') { $('#product_form_'+product_id+'_Price').val(value.sale_price); $('#Price'+product_id).html('' + formatPrice(value.price) + ' ' + formatPrice(value.sale_price) + ''+' (excl. VAT)'); } else { $('#product_form_'+product_id+'_Price').val(value.price); $('#Price'+product_id).html(formatPrice(value.price)+' (excl. VAT)'); } if (parseFloat(value.tot_in_stock) > 0) { $('#add-to-bag').removeAttr('disabled'); $('#add-to-bag').html('ADD TO BAG'); $('#availability').html('In Stock'); $('#num-in-stock').val(value.tot_in_stock); $('.qty-display').html('1'); } else { $('#add-to-bag').attr('disabled', 'disabled'); $('#add-to-bag').html('OUT OF STOCK'); $('#availability').html('Out of Stock'); $('#num-in-stock').val(0); } if (parseFloat($('.qty-display').html()) > $('#num-in-stock').val()) { $('.qty-display').html($('#num-in-stock').val()); } } }); $('.qty-plus').unbind('click'); $('.qty-plus').click(function() { if (parseInt($(this).parent().find('.qty-display').html()) < $('#num-in-stock').val()) { $(this).parent().find('.qty-display').html(parseInt($(this).parent().find('.qty-display').html()) + 1); } }); // Select approprate image var x = 1; $("#product-images-swiper .swiper-slide").each(function(){ if (!$(this).hasClass('swiper-slide-duplicate')) { if ($(this).hasClass(select_image_attribute)) { product_images_swiper.slideTo(x); $('#product_form_'+product_id+'_ProductImageName').val($(this).find('img').attr('src')); return false; } x = x + 1; } }); } function addToBag(productOptionId, secondaryGroupName, productOptionName, productImageName, quantity, price) { shoppingBagLineRef = createShoppingBagLineRef(); attributes_json = JSON.parse('{'+attributes_string+' "none": "none"}'); for (attribute in attributes_json) { if (attribute != 'none') { productOptionName = productOptionName + ' / ' + attributes_json[attribute]; } } $("#shopping-bag-no-items").fadeOut(10); $('#shopping-bag-list').fadeIn(); $(".shopping-bag-link").click(); $("#shopping-bag-list").append('\
'); $('.shopping-bag-list-row:last').fadeIn(1500); calculateBagTotals('addToBag'); } function removeFromBag(shoppingBagLineRef) { $('#shopping-bag-select-method').fadeOut(); $('#shopping-bag-bottom').fadeIn(function(){ if (countShoppingBagRows() == 1) { $('#shopping-bag-bottom').fadeOut(); } $('#row-'+shoppingBagLineRef).animate({ height: 0, opacity: 0 }, function(){ $('#row-'+shoppingBagLineRef).remove(); calculateBagTotals('removeFromBag'); }); }); } var total_quantity = 0; var total_subprice = 0; var total_discount = 0; var total_shipping = 0; var total_tax = 0; var total_price = 0; var shipping_id = ''; var shopping_bag_string = ''; var discount_codes = ['','156713f6f57c38a7492899f9e5132aef|1|15.00','156713f6f57c38a7492899f9e5132aef|1|15.00','156713f6f57c38a7492899f9e5132aef|1|10.00','1f9dc8dc4a31d123e3e3e974cedced71|1|15.00','1f9dc8dc4a31d123e3e3e974cedced71|1|15.00','1f9dc8dc4a31d123e3e3e974cedced71|1|10.00','85ea40602ba28df420f7fba9d3d00e72|1|15.00','85ea40602ba28df420f7fba9d3d00e72|1|15.00','85ea40602ba28df420f7fba9d3d00e72|1|10.00','da4b2d948d34fb55a9ea5622c306bfad|1|15.00','da4b2d948d34fb55a9ea5622c306bfad|1|15.00','da4b2d948d34fb55a9ea5622c306bfad|1|10.00','e769ae9749a0077873f72febc3168c62|1|15.00','e769ae9749a0077873f72febc3168c62|1|15.00','e769ae9749a0077873f72febc3168c62|1|10.00','165bd2d812ac7a8406e3247205b14745|1|15.00','165bd2d812ac7a8406e3247205b14745|1|15.00','165bd2d812ac7a8406e3247205b14745|1|10.00','92932e230190731c32b0feaaa2ee7cf0|1|10.00','c0a0253cdf4358bf4ff88de53dcf98b5|1|15.00']; function setDiscount(discount_code) { var discount_code = arguments[0] !== undefined ? arguments[0] : ''; $('#discount-code-error').fadeOut(10); discount_code_md5 = md5(discount_code); discount_matched = 0; for (x=0; x