// smooth scroll $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') || location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top }, 1000); return false; } } }); }); function verifyCallback(response) { $("#captcha").val(response); $('#error-message').modal('hide'); $.ajax({ type: 'POST', url: $('#subscribe-form').attr("action"), dataType: 'json', data: $('#subscribe-form').serialize(), success: function(response) { $('#captcha-modal').modal('hide'); if(response.success == 1) { $("#email, #name").val(''); $('#success-message').modal('show'); setTimeout(function() { $('#success-message').modal('hide'); }, 2000); } else { if(response.error.email == 1) { $("#email").addClass('has-error'); } if(response.error.name == 1) { $("#name").addClass('has-error'); } $('#error-message').modal('show'); setTimeout(function() { $('#error-message').modal('hide'); }, 2000); } grecaptcha.reset(); } }); } function onloadCallback() { grecaptcha.render('g-recaptcha', { 'sitekey' : '6Le35xUUAAAAACvQBDQTC4yPKgt3cBQagF6s3CUp', 'callback' : verifyCallback, 'theme' : 'dark' }); } // fix vertical when not overflow // call fullscreenFix() if .fullscreen content changes function fullscreenFix(){ if(screen.width > 768) { var height = $(window).height(); $('.fullscreen').css('height', height + "px"); } } // resize background images function backgroundResize() { var windowH = $(window).height(); $(".landing, .why-golpas").each(function(i){ var path = $(this); // variables var contW = path.width(); var contH = path.height(); var imgW = path.attr("data-img-width"); var imgH = path.attr("data-img-height"); var ratio = imgW / imgH; // overflowing difference var diff = parseFloat(path.attr("data-diff")); diff = diff ? diff : 0; // remaining height to have fullscreen image only on parallax var remainingH = 0; if(path.hasClass("parallax") && !$("html").hasClass("touch")){ var maxH = contH > windowH ? contH : windowH; remainingH = windowH - contH; } // set img values depending on cont imgH = contH + remainingH + diff; imgW = imgH * ratio; // fix when too large if(contW > imgW){ imgW = contW; imgH = imgW / ratio; } // path.data("resized-imgW", imgW); path.data("resized-imgH", imgH); path.css("background-size", imgW + "px " + imgH + "px"); }); } // set parallax background-position function parallaxPosition(e) { // do not change position!!! return true; // console.log(e); var heightWindow = $(window).height(); var topWindow = $(window).scrollTop(); var bottomWindow = topWindow + heightWindow; var currentWindow = (topWindow + bottomWindow) / 2; $(".parallax").each(function(i) { //console.log(i); var path = $(this); var height = path.height(); var top = path.offset().top; var bottom = top + height; // only when in range if(bottomWindow > top && topWindow < bottom) { var imgW = path.data("resized-imgW"); var imgH = path.data("resized-imgH"); // min when image touch top of window var min = 0; // max when image touch bottom of window var max = - imgH + heightWindow; // overflow changes parallax var overflowH = height < heightWindow ? imgH - height : imgH - heightWindow; // fix height on overflow top = top - overflowH; bottom = bottom + overflowH; // value with linear interpolation var value = min + (max - min) * (currentWindow - top) / (bottom - top); // set background-position var orizontalPosition = path.attr("data-oriz-pos"); orizontalPosition = orizontalPosition ? orizontalPosition : "50%"; $(this).css("background-position", orizontalPosition + " " + value + "px"); } }); } // scrollspy -- also uncomment the a.scrollToTop in the bottom // $('body').scrollspy({ target: '#navbar-scroll' }); // // lets run all JS // jQuery(document).ready(function($) { // site preloader -- also uncomment the div in the header $(window).load(function(){ $('#preloader').fadeOut('slow',function(){$(this).remove();}); }); // scrollToTop -- also uncomment the a.scrollToTop in the bottom // check to see if the window is top if not then display button //$(window).scroll(function(){ // if ($(this).scrollTop() > 500) { // $('.scrollToTop').fadeIn(); // } else { // $('.scrollToTop').fadeOut(); // } //}); // click event to scroll to top -- also uncomment the a.scrollToTop in the bottom //$('.scrollToTop').click(function(){ // $('html, body').animate({scrollTop : 0},800); // return false; //}); // parallax background image http://www.minimit.com/articles/lets-animate/parallax-backgrounds-with-centered-content detect touch if("ontouchstart" in window){ document.documentElement.className = document.documentElement.className + " touch"; } if(!$("html").hasClass("touch")){ // background fix $(".parallax").css("background-attachment", "fixed"); } // magic $(window).resize(fullscreenFix); fullscreenFix(); $(window).resize(backgroundResize); $(window).focus(backgroundResize); backgroundResize(); if(!$("html").hasClass("touch")){ $(window).resize(parallaxPosition); // $(window).focus(parallaxPosition); $(window).scroll(parallaxPosition); parallaxPosition(); } // init WOW effects new WOW().init(); $(".subscribe-form-btn").click(function(e) { $("#email, #name").removeClass('has-error'); var re = /^[^@]+@.*.[a-z]{2,15}$/i; if($('#name').val() && ($('#email').val() && re.test($('#email').val()))) { $('#captcha-modal').modal('show'); } else { if(!$('#email').val() || !re.test($('#email').val())) { $("#email").addClass('has-error'); } if(!$('#name').val()) { $("#name").addClass('has-error'); } } }); });