var windowH = 0; var windowW = 0; var videoOpt = {taped: false}; function IsJsonString(str) { try{ JSON.parse(str); } catch(e){ return false; } return true; } String.prototype.trunc = function(n,useWordBoundary){ var toLong = this.length>n, s_ = toLong ? this.substr(0,n-1) : this; s_ = useWordBoundary && toLong ? s_.substr(0,s_.lastIndexOf(' ')) : s_; return toLong ? s_ + '…' : s_; }; String.prototype.reverse = function(){ return this.split("").reverse().join(""); }; String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp(search, 'g'), replacement); }; function isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); } function inArray(needle, haystack) { var length = haystack.length; for(var i = 0; i < length; i++) { if(haystack[i] == needle) return true; } return false; } function getJSONsize(data){ var key, count = 0; for(key in data) { if(data.hasOwnProperty(key)) { count++; } } return count; } function goTo(element, offset, timing, callback, callbackData){ var timing = timing || 1000; var offset = offset || 0; var callback = callback || function(){}; var callbackData = callbackData || ""; (function ($) { var value=jQuery(element).offset().top - offset; $('html, body').stop().animate({ 'scrollTop': value }, timing, 'swing'); setInterval(timing, callback(callbackData.id)); })(jQuery); } function goToBinder(){ $("[data-goto-target]").click(function(){ var target = $(this).data("goto-target"); var offset = 0; var timing = 700; if($(this).data("offset") != undefined){ offset = $(this).data("offset"); } if($(this).data("timing") != undefined){ timing = $(this).data("timing"); } goTo(target, offset, timing); }); } function setVerticalAlign(functionalLimit){ functionalLimit = functionalLimit || 767; $(".col-vertical-align").each(function(){ if($(window).width() > functionalLimit){ if($(this).data("vertical-rel-to") != undefined){ var selector = $(this).data("vertical-rel-to"); var h = $(this).parents(selector).height(); } else{ var h = $(this).parents(".row").height(); } $(this).css('margin-top', ((h - parseInt($(this).css('height'))) / 2) + 'px'); } else{ $(this).css('margin-top', ''); } }); } function setHeightFrom(){ $("[data-set-height-from]").each(function(){ var from = $(this).data("set-height-from"); var h = $(from).css("height"); $(this).css("height", h); }) } function setPositionFromParent(){ $("[data-set-position-from-parent]").each(function(){ var elem = $(this); var position = elem.data("set-position-from-parent"); var h = parseInt(elem.css("height")); var ph = parseInt(elem.parent().css("height")); switch(position){ case 'center': elem.css("margin-top", ((ph - h)/2) + "px"); break; case 'bottom': elem.css("margin-top", ((ph - h)/2) + "px"); } }); } function closeAlertBind(){ $("[data-hide]").click(function(){ var elem = $(this).closest("." + $(this).data("hide")); var feedbackBlock = $(this).parents(".iffInfoToShow"); feedbackBlock.css("height", "0px"); setTimeout(function(){ elem.removeClass("showError"); $(feedbackBlock.data("rel-to")).find(".errorBlock.showError").removeClass("showError"); }, 300); }); } function clearAlert(elem){ var target = elem.parent(".inputContainer").find(".errorBlock"); target.hasClass(".showError") ? target.removeClass(".showError") : null; } function initMap(){ if(document.getElementById("map-canvas") != null){ var map, marker, centerMap; var zoom = 15; var locations = [ {name: "timeout", coordinates: {lat: 41.089674, lng: 16.883578}} ]; function move(){ map.setCenter(centerMap); marker.setPosition(centerMap); } function initialize() { centerMap = new google.maps.LatLng(locations[0].coordinates.lat, locations[0].coordinates.lng); var mapOptions = { zoom: zoom, center: centerMap, scrollwheel: false, styles: [ { elementType: 'labels.text.stroke', stylers: [ {color: '#1C1D1B'}, {"weight":0.0} ] }, { elementType: 'labels.text.fill', stylers: [ {color: '#FFFFFF'} ] }, { "featureType": "landscape", "elementType": "geometry", "stylers": [ { "color": "#1C1D1B" } ] }, { "featureType": "road.highway", "elementType": "geometry.fill", "stylers": [ { "color": "#FEDB78" } ] }, { "featureType": "road.highway", "elementType": "geometry.stroke", "stylers": [ { "color": "#FBA927" } ] }, { "featureType": "road.local", "elementType": "geometry.fill", "stylers": [ { "color": "#0E8140" } ] }, { "featureType": "road.arterial", "elementType": "geometry.fill", "stylers": [ { "color": "#0E8140" } ] }, { "featureType":"poi", "elementType":"geometry.fill", "stylers":[ {"color":"#1C1D1B"} ] }, { "featureType":"poi", "elementType":"geometry.stroke", "stylers":[ {"color":"#ffffff"}, {"weight":0.85} ] }, { "featureType":"landscape.natural", "elementType":"geometry.stroke", "stylers":[ {"color":"#ffffff"}, {"weight":3.18} ] }, { "featureType":"water", "elementType":"geometry.fill", "stylers":[ {"color":"#2e93c5"} ] } ] }; map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); var i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i].coordinates.lat, locations[i].coordinates.lng), map: map, animation: google.maps.Animation.DROP }); } google.maps.event.addDomListener(window, "resize", move); } google.maps.event.addDomListener(window, "load", initialize); } } function validateInput(feedBackBlockId, elementsToValidate, allowedMimeType, limit){ var elementsToValidate = elementsToValidate || []; var allowedMimeType = allowedMimeType || []; var limit = limit || 2097152; var pass = true; var errorBlockSelector = ""; for(var i = 0; i < elementsToValidate.length; i++){ errorBlockSelector = $(elementsToValidate[i]).data("errblock"); if($(elementsToValidate[i]).attr("type") == "checkbox"){ if(!$(elementsToValidate[i]).prop("checked")){ $(errorBlockSelector).addClass("showError"); pass &= false; } else{ $(errorBlockSelector).removeClass("showError"); pass &= true; } } else if($(elementsToValidate[i]).attr("type") == "file"){ var file_data = $(elementsToValidate[i]).prop("files")[0]; if(($(elementsToValidate[i]).prop("files").length == 0) || !inArray(file_data.type, allowedMimeType) || !(file_data.size <= limit)){ $(errorBlockSelector).addClass("showError"); pass &= false; } else{ $(errorBlockSelector).removeClass("showError"); pass &= true; } } else{ if($(elementsToValidate[i]).val() == ""){ $(errorBlockSelector).addClass("showError"); pass &= false; } else{ $(errorBlockSelector).removeClass("showError"); pass &= true; } } } if(!pass){ $(feedBackBlockId + ".iffInfoToShow").addClass("hasMsg"); $(feedBackBlockId + ".iffInfoToShow .alert-danger").addClass("showError"); $(feedBackBlockId + ".iffInfoToShow").css("height", (parseInt($(feedBackBlockId + ".iffInfoToShow .alert-danger").css("height")) + 20) + "px"); } else{ $(feedBackBlockId + ".iffInfoToShow").removeClass("hasMsg"); $(feedBackBlockId + ".iffInfoToShow").css("height", "0px"); } return pass; } function menuMinifierController(){ if($(window).width() < 1200){ $("#mainMenuContainer").addClass("minified"); } else{ if($(window).scrollTop() > ($(window).height()/2)){ if(!$("#mainMenuContainer").hasClass("minified")){ $("#mainMenuContainer").addClass("minified"); } } else{ if($("#mainMenuContainer").hasClass("minified")){ $("#mainMenuContainer").removeClass("minified"); } } } } function setFullScreenSize(){ windowW = $(window).width(); windowH = $(window).height(); $(".fullScreen").each(function(){ $(this).width(windowW); $(this).height(windowH); }); } function menuDockerManager(){ if($(".introBox").length != 0){ if($(window).scrollTop() > windowH){ $("#mainMenuContainer").addClass("navbar-fixed-top"); $(".pageContent").addClass("menuSpacer"); } else{ $("#mainMenuContainer").removeClass("navbar-fixed-top"); $(".pageContent").removeClass("menuSpacer"); } } else{ $("#mainMenuContainer").addClass("navbar-fixed-top"); } } function clipTheCorner(){ $(".ctc").each(function(){ var l = $(this).data("corner-length") || 6; var h = parseInt($(this).css("height")); var w = parseInt($(this).css("width")); clipPath = "polygon(" + l + "px 0px, " + (w - l) + "px 0px, " + w + "px " + l + "px, " + w + "px " + (h - l) + "px, " + (w - l) + "px " + h + "px, " + l + "px " + h + "px, 0px " + (h - l) + "px, 0px " + l + "px)"; $(this).css({ '-webkit-clip-path': clipPath, '-mozkit-clip-path': clipPath, '-o-clip-path': clipPath, 'clip-path': clipPath, }); }) } function setVideoDim(selector, opts){ var defaults = { taped: false, W: parseInt($(selector).parent().css("width")), H: parseInt($(selector).parent().css("height")), callback: function(){}, callbackData: null } var options = $.extend(true, {}, defaults, opts); function heightTied(H, videoRatio){ h = options.H; w = h * videoRatio; return { width: w, height: h } } function widthTied(W, videoRatio){ w = W; h = w / videoRatio; return { width: w, height: h } } if($(selector) != undefined){ var videoRatio = 16/9; var windowRatio = options.W / options.H; var vH, vW, dim; if(videoRatio == windowRatio){ dim.height = options.H; dim.widht = options.W; } else{ if((videoRatio > 1 && windowRatio > 1) || (videoRatio < 1 && windowRatio < 1)){ // caso video orizzontale e finestra orizzontale if(videoRatio < windowRatio){ // video meno rettangolare della finestra if(options.taped){ dim = heightTied(options.H, videoRatio); } else{ dim = widthTied(options.W, videoRatio); } } else{ // video piĆ¹ rettangolare della finestra if(options.taped){ dim = widthTied(options.W, videoRatio); } else{ dim = heightTied(options.H, videoRatio); } } } else if(videoRatio > 1 && windowRatio < 1){ // caso video orizzontale e finestra verticale if(options.taped){ dim = widthTied(options.W, videoRatio); } else{ dim = heightTied(options.H, videoRatio); } } else{ // caso video verticale e finestra orizzontale if(options.taped){ dim = heightTied(options.H, videoRatio); } else{ dim = widthTied(options.W, videoRatio); } } } vH = dim.height; vW = dim.width; $(selector + " > video").attr("height", vH); $(selector + " > video").attr("width", vW); $(selector + " > video").css({ "margin-top": parseInt((options.H - vH) / 2), "margin-left": parseInt((options.W - vW) / 2), }); options.callback(options.callbackData); } else{ console.log("no video: inert activation"); } } $(document).ready(function(){ windowH = $(window).height(); closeAlertBind(); setFullScreenSize(); $("body").scrollspy({offset: 100}); $(".smoothScroll").click(function(e){ if($(this).data("prevent-default-link") == 1){ e.preventDefault(); } }); if($(window).scrollTop() > ($(window).height()/2)){ $("#mainMenuContainer").addClass("minified"); } $(".newsletterBlock .customBtn").click(function(){ $(".iffInfoToShow .showError").removeClass("showError"); var feedBackBlockId = $(this).data("feedback"); var elementsToValidate = ["#newsletterSubscription", "#newsletterPrivacy"]; var checkResult = validateInput(feedBackBlockId, elementsToValidate); if(checkResult){ var email = $("#newsletterSubscription").val(); var privacy = $("#newsletterPrivacy").val(); data = { "sendmail": "sent", "mailType": "newsletterSubscription", "email": email, "privacy": privacy, } $.ajax({ url: "/mailManager.php", data: data, type: "post", beforeSend: function() { $(feedBackBlockId + ".iffInfoToShow").css("height", "0px"); $(feedBackBlockId + ".iffInfoToShow").removeClass("hasMsg"); $(feedBackBlockId + ".iffInfoToShow .showError").removeClass("showError"); $(feedBackBlockId + ".iffInfoToShow .waiting").addClass("showError"); $(feedBackBlockId + ".iffInfoToShow").addClass("hasMsg"); $(feedBackBlockId + ".iffInfoToShow").css("height", (parseInt($(feedBackBlockId + ".iffInfoToShow .alert-danger").css("height")) + 20) + "px"); }, success: function(response) { var alertBox = ""; $(feedBackBlockId + ".iffInfoToShow .showError").removeClass("showError"); if(IsJsonString(response)){ alertBox = ".alert-info"; response = JSON.parse(response); response = response.msg; $(feedBackBlockId + ".iffInfoToShow .alert-info .msgTitle").html("Informazione"); $(feedBackBlockId + ".iffInfoToShow .alert-info .successMsg").html(response); } else if(response != "OK"){ alertBox = ".alert-success"; $(feedBackBlockId + ".iffInfoToShow .alert-success .successMsg").html(response); } else{ alertBox = ".alert-success"; } $(feedBackBlockId + ".iffInfoToShow " + alertBox).addClass("showError"); }, error: function(error){ $(feedBackBlockId + ".iffInfoToShow .showError").removeClass("showError"); error = error.responseText; $(feedBackBlockId + ".iffInfoToShow .alert-danger .errorMsg").html(error); $(feedBackBlockId + ".iffInfoToShow .alert-danger").addClass("showError"); } }) } }) $(".inputContainer input, .inputContainer textarea, .inputContainer label").click(function(){ console.log("try to clean"); clearAlert($(this)); }); $(".customDropdown").hover( function(){ $(this).addClass("hovered"); }, function(){ $(this).removeClass("hovered"); } ); $(".currency-dropdown").hover( function(){ $(this).addClass("hovered"); }, function(){ $(this).removeClass("hovered"); } ); }); $(window).bind("load", function(){ setTimeout(function(){ $(".waintingScreen").fadeOut(300, function(){ $(this).remove(); setVerticalAlign(991); menuMinifierController(); }); }, 2000); clearTimeout(); goToBinder(); setHeightFrom(); clipTheCorner(); setVideoDim("#introVideo", videoOpt); }); $(window).resize(function(){ setVerticalAlign(991); menuMinifierController(); setFullScreenSize(); setHeightFrom(); clipTheCorner(); setVideoDim("#introVideo", videoOpt); }); $(window).scroll(function(){ menuMinifierController(); menuDockerManager(); })