var app = { init: function () { var t = this; t.win = $(window); t.body = $('body'); t.boxes = $('.box'); t.heightToBox = $('.box, .box2, .box3, .box4, .inner-box-1, .inner-box-2'); t.heightDouble = $('.height2'); t.boxInner1 = $('.inner-box-1'); t.boxInner2 = $('.inner-box-2'); t.kappaMan = $('#kappa-man'); t.perMoto = $('#hp-per-moto'); t.prDx = $('#hp-products-right'); t.prBox = $('.box-product'); t.boxNews = $('.box-news a'); t.boxNewsContainer = $('.box-news'); t.videoPlay = $('.video-play'); t.win.on('load', function () { t.positioning(); }).on('resize', t.debounce(function () { t.positioning(); }, 100)); }, initMobile: function () { var t = this; t.initOverlay(); }, debounce: function (a, b, c) { var d; return function () { var e = this, f = arguments; clearTimeout(d), d = setTimeout(function () { d = null, c || a.apply(e, f) }, b), c && !d && a.apply(e, f) } }, positioning: function () { var t = this; t.videoPlay.height(t.boxNewsContainer.height()); //heightBoxAdjustHeight.height(heightBoxFooter.height()); t.perMoto.height(t.kappaMan.height()); t.prBox.height(t.prDx.height() / 2); //t.overlayNl.css('height', t.win.height()); //t.overlayNl.find('.row').css('height', t.win.height()); }, initOverlay: function () { var t = this; //t.overlayNl = $('#overlay_nl'); // //var overlayNlClose = t.overlayNl.find('#overlay_nl_close'), // leanBanner = t.overlayNl.find('#lean_banner'); // //overlayNlClose.on('click', function (e) { // e.preventDefault(); // // t.overlayNl.fadeOut(); // leanBanner.hide(); // // $.ajax({ // type: 'POST', // url: 'common/cambia_sessione_BannerChiusoNl.php' // }); //}); } }; var slideHPv = { init: function () { // var t = this; // t.win = $(window); // $('#customElement').height(t.win.height() - 250); // $(".player").YTPlayer(); } }; var slideHP = { init: function () { var t = this; t.win = $(window); $('.tp-banner').revolution({ delay: 4000, onHoverStop: "no", navigationType: "none", navigationArrows: "solo", hideTimerBar: "on", fullWidth: "on", autoHeight: "off", startheight: t.win.height() - 100 }); }, initMobile: function () { $('.tp-banner').revolution({ delay: 4000, onHoverStop: "no", navigationType: "none", navigationArrows: "solo", hideTimerBar: "on", fullWidth: "on", autoHeight: "on" }); } }; var novita = { init: function () { var t = this; var viewportW = ($(window).width() / 100) * 90; var slider = $('.bxslider'); var sliderOptions = { adaptiveHeight: true, pager: false, autoStart: false, slideWidth: viewportW / 4, slideMargin: 0, infiniteLoop: true, hideControlOnEnd: true, maxSlides: 4 }; slider.bxSlider(sliderOptions); $(window).on('resize', app.debounce(function () { slider.reloadSlider(sliderOptions); }, 200)); }, initMobile: function () { var viewportW = ($(window).width() / 100) * 90; $('.bxslider').bxSlider({ adaptiveHeight: true, pager: false, autoStart: false, slideWidth: viewportW, slideMargin: 0, infiniteLoop: true, hideControlOnEnd: true, maxSlides: 1 }); }, equalizeHeights: function (selector) { var heights = [], $selector = $(selector); // Loop to get all element heights $selector.each(function () { var $this = $(this); // Need to let sizes be whatever they want so no overflow on resize $this.css({ 'min-height': 0, 'max-height': 'none', 'height': 'auto' }); // Then add size (no units) to array heights.push($this.height()); }); // Find max height of all elements var max = Math.max.apply(Math, heights); // Set all heights to max height $selector.each(function () { $(this).height(max); }); }, }; var prodottoFotogallery = { init: function () { if ($('.bxslider-gallery').length > 0) { $('.bxslider-gallery').bxSlider({ adaptiveHeight: true, pager: false, autoStart: false, minSlides: 3, maxSlides: 3, moveSlides: 1, slideWidth: 200, slideMargin: 0, infiniteLoop: false }); $('.cl_gallery').on('click', function () { $('#prodotto_big_foto').attr('src', $(this).find('img').attr('src')); }); } if ($('.colore-prodotto').length > 0) { $('.colore-prodotto').on('click', function () { $('#prodotto_big_foto').attr('src', $(this).attr('src')); $('html,body').animate({scrollTop: $("#prodotto_big_foto").offset().top}, 1000); }); } } }; var prodottoSlider = { init: function () { if ($('.bxslider-slider').length > 0) { $('.bxslider-slider').bxSlider({ adaptiveHeight: true, pager: false, autoStart: false, minSlides: 1, maxSlides: 1, moveSlides: 1, slideMargin: 0, infiniteLoop: true, slideWidth: "1600" }); } } }; var gallery = { init: function () { var t = this; t.sliderGalleryMobile = $('.bxslider-gallery-mobile'), t.win = $(window); if (t.sliderGalleryMobile.length == 0) { return; } var params = t.slideParams(); t.sliderGalleryMobile.bxSlider({ adaptiveHeight: true, pager: false, autoStart: false, minSlides: params.minSlides, maxSlides: params.maxSlides, slideWidth: params.slideWidth, slideMargin: 0, infiniteLoop: true }); $(window).on('load', function () { // Fix heights on page load valignMiddle('.bxslider-gallery-mobile .gallery img'); // Fix heights on window resize }).on('resize', function () { // Needs to be a timeout function so it doesn't fire every ms of resize setTimeout(function () { valignMiddle('.bxslider-gallery-mobile .gallery img'); var params = t.slideParams(); t.sliderGalleryMobile.reloadSlider({ adaptiveHeight: true, pager: false, autoStart: false, minSlides: params.minSlides, maxSlides: params.maxSlides, slideWidth: params.slideWidth, slideMargin: 0, infiniteLoop: true }); }, 120); }); }, slideParams: function () { var t = this; var w = t.win.width(); var params = { slideWidth: w - 30, minSlides: 1, maxSlides: 1 } if (w > 500 && w <= 1024) { params = { slideWidth: w * .8 / 3, minSlides: 3, maxSlides: 3 } } if (w > 1024) { params = { slideWidth: (w * .8 / 5), minSlides: 5, maxSlides: 5 } } return params; }, equalizeHeights: function (selector) { var heights = [], $selector = $(selector); // Loop to get all element heights $selector.each(function () { var $this = $(this); // Need to let sizes be whatever they want so no overflow on resize $this.css({ 'min-height': 0, 'max-height': 'none', 'height': 'auto' }); // Then add size (no units) to array heights.push($this.height()); }); // Find max height of all elements var max = Math.max.apply(Math, heights); // Set all heights to max height $selector.each(function () { $(this).height(max); }); }, }; var correlati = { init: function () { var t = this; t.sliderCorrelati = $('.bxslider-correlati'), t.win = $(window); if (t.sliderCorrelati.length == 0) { return; } var params = t.slideParams(); t.sliderCorrelati.bxSlider({ adaptiveHeight: true, pager: false, autoStart: false, minSlides: params.minSlides, maxSlides: params.maxSlides, slideWidth: params.slideWidth, slideMargin: 0, infiniteLoop: true }); $(window).on('load', function () { // Fix heights on page load valignMiddle('.correlati-img img'); // Fix heights on window resize }).on('resize', function () { // Needs to be a timeout function so it doesn't fire every ms of resize setTimeout(function () { valignMiddle('.correlati-img img'); var params = t.slideParams(); t.sliderCorrelati.reloadSlider({ adaptiveHeight: true, pager: false, autoStart: false, minSlides: params.minSlides, maxSlides: params.maxSlides, slideWidth: params.slideWidth, slideMargin: 0, infiniteLoop: true }); }, 120); }); }, slideParams: function () { var t = this; var w = t.win.width(); var params = { slideWidth: w - 30, minSlides: 1, maxSlides: 1 } if (w > 500 && w <= 1024) { params = { slideWidth: w * .8 / 3, minSlides: 3, maxSlides: 3 } } if (w > 1024) { params = { slideWidth: (w * .8 / 5), minSlides: 5, maxSlides: 5 } } return params; }, equalizeHeights: function (selector) { var heights = [], $selector = $(selector); // Loop to get all element heights $selector.each(function () { var $this = $(this); // Need to let sizes be whatever they want so no overflow on resize $this.css({ 'min-height': 0, 'max-height': 'none', 'height': 'auto' }); // Then add size (no units) to array heights.push($this.height()); }); // Find max height of all elements var max = Math.max.apply(Math, heights); // Set all heights to max height $selector.each(function () { $(this).height(max); }); }, }; var valignMiddle = function (selector) { var $selector = $(selector), heights = []; $selector.each(function () { var $this = $(this); $this.css({ 'min-height': 0, 'max-height': 'none', 'height': 'auto' }); heights.push($this.height()); }); var max = Math.max.apply(Math, heights); $selector.each(function () { var $this = $(this); //console.log(selector); //console.log($this.attr("src")); //console.log("max:"+max); //console.log("this:"+$this.height()); if (max > $this.height()) { var margin = (max - $this.height()) / 2; $this.css({ 'margin-top': margin, 'margin-bottom': margin }); // console.log("margin:"+margin); } }); }; var iconeColori = { init: function () { $(window).on('load', function () { valignMiddle('.prodotto-icone.colori img'); }); } }; var locator = { init: function () { var $currentHash = document.location.hash; load(); if ($currentHash != '' && $currentHash != '#') { searchLocations(); } } }; var accessori = { init: function () { var $accessorioShow = $('.accessorio-show'); $(window).on('load', function () { if ($accessorioShow.length > 0) { valignMiddle('.accessorio-show img'); var minHeight = 0; $accessorioShow.each(function () { var $this = $(this); minHeight = Math.max($(this).height(), minHeight); }); minHeight=minHeight+15; //$accessorioShow.height(minHeight); $accessorioShow.css("min-height",minHeight+'px'); } }); } }; var perlatuamoto = { init: function () { $(window).on('load', function () { if ($('.accessorio-img').length > 0) { valignMiddle('.accessorio-img img'); } var $containerMotoSingola = $('.container-moto-singola'); if ($containerMotoSingola.length > 0) { valignMiddle('.container-moto-singola img'); var h = 0; $containerMotoSingola.each(function () { h = Math.max($(this).height(), h); }); $containerMotoSingola.height(h); } }); } }; var catalogo = { init: function () { var t = this; t.win = $(window); var $items = $('.catalogo-lista-item'); $items.height($items.width()); $(window).on('load', function () { valignMiddle('.catalogo-lista-img img'); }).on('resize', function () { $items.height($items.width()); }); var $isotope = $('#catalogo-lista').isotope({ itemSelector: '.catalogo-lista-item', layoutMode: 'fitRows', resizable: false }); $('.filter').on('click', function () { var $this = $(this); if ($this.hasClass('selected_filter')) { return false; } var $optionSet = $this.parents('#filters'); $optionSet.find('.selected_filter').removeClass('selected_filter'); $this.addClass('selected_filter'); var filterValue = $(this).attr('data-filter'); $isotope.isotope({filter: filterValue}); $.ajax({ type: "POST", url: "ajax/recupera_descrizioni.php", data: "w=" + filterValue, success: function (data) { $('#descrizione-categoria div').html(data); $('#descrizione-categoria').show(); } }); }); $(window).on('load', function () { var hash = window.location.hash; if (hash) { var activeFilter = hash.replace('#', '.').toLowerCase(); var filterButton = $('.filter').filter(function () { return $(this).data('filter') == activeFilter; }, activeFilter); filterButton.trigger('click'); } }); }, heightIntro: function () { var minHeight = 0; //$(window).load(function() { minHeight = $("#intro-foto").height(); $(".descrizione-cat-catalogo").height(minHeight); //}); }, debounce: function (a, b, c) { var d; return function () { var e = this, f = arguments; clearTimeout(d), d = setTimeout(function () { d = null, c || a.apply(e, f) }, b), c && !d && a.apply(e, f) } } }; var news = { init: function () { var t = this; if ($('.elenco-news').length > 0) { $(window).load(function () { // Fix heights on page load t.equalizeHeights('.elenco-news'); // Fix heights on window resize $(window).resize(function () { // Needs to be a timeout function so it doesn't fire every ms of resize setTimeout(function () { t.equalizeHeights('.elenco-news'); }, 120); }); }); } }, equalizeHeights: function (selector) { var t = this; var heights = new Array(); // Loop to get all element heights $(selector).each(function () { // Need to let sizes be whatever they want so no overflow on resize $(this).css('min-height', '0'); $(this).css('max-height', 'none'); $(this).css('height', 'auto'); // Then add size (no units) to array heights.push($(this).height()); }); // Find max height of all elements var max = Math.max.apply(Math, heights); // Set all heights to max height $(selector).each(function () { $(this).css('height', max + 'px'); }); } }; var videoInterni = { init: function () { var t = this; if ($('.videogallery_interna').length > 0) { $(window).load(function () { // Fix heights on page load t.equalizeHeights('.bloccoVideo'); // Fix heights on window resize $(window).resize(function () { // Needs to be a timeout function so it doesn't fire every ms of resize setTimeout(function () { t.equalizeHeights('.bloccoVideo'); }, 120); }); }); } }, equalizeHeights: function (selector) { var t = this; var heights = new Array(); // Loop to get all element heights $(selector).each(function () { // Need to let sizes be whatever they want so no overflow on resize $(this).css('min-height', '0'); $(this).css('max-height', 'none'); $(this).css('height', 'auto'); // Then add size (no units) to array heights.push($(this).height()); }); // Find max height of all elements var max = Math.max.apply(Math, heights); // Set all heights to max height $(selector).each(function () { $(this).css('height', max + 'px'); }); } }; var prodotti = { init: function () { $('.prodotti-hover').hover( function () { var $this = $(this); $this.find('img').addClass('grayscale', 1000); $this.find('.prodotti-testo-nascosto').fadeIn(); }, function () { var $this = $(this); $this.find('img').removeClass('grayscale', 1000); $this.find('.prodotti-testo-nascosto').fadeOut(); } ); } };