(function($) { "use strict"; //fix back forward cache issue: http://stackoverflow.com/questions/11979156/mobile-safari-back-button $(window).bind("pageshow", function(event) { if (event.originalEvent.persisted) { avia_site_preloader(); } }); $(document).ready(function() { var aviabodyclasses = AviaBrowserDetection('html'); $.avia_utilities = $.avia_utilities || {}; if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && 'ontouchstart' in document.documentElement) { $.avia_utilities.isMobile = true; } else { $.avia_utilities.isMobile = false; } //check if user uses IE7 - if yes don't execute the function or the menu will break if(aviabodyclasses.indexOf("avia-msie-7") == -1) avia_responsive_menu(); // decreases header size when user scrolls down avia_header_size(); // set sidebar main menu option avia_sidebar_menu(); //activates the sticky submenu avia_sticky_submenu(); //show scroll top button avia_scroll_top_fade(); //site preloader script avia_site_preloader(); //creates search tooltip new $.AviaTooltip({"class": 'avia-search-tooltip',data: 'avia-search-tooltip', event:'click', position:'bottom', scope: "body", attach:'element'}); //creates relate posts tooltip new $.AviaTooltip({"class": 'avia-related-tooltip', data: 'avia-related-tooltip', scope: ".related_posts, .av-share-box", attach:'element', delay:0}); //creates ajax search new $.AviaAjaxSearch({scope:'#header'}); // actiavte portfolio sorting if($.fn.avia_iso_sort) $('.grid-sort-container').avia_iso_sort(); //activates the mega menu javascript if($.fn.aviaMegamenu) $(".main_menu .menu").aviaMegamenu({modify_position:true}); $.avia_utilities.avia_ajax_call(); }); $.avia_utilities = $.avia_utilities || {}; $.avia_utilities.avia_ajax_call = function(container) { if(typeof container == 'undefined'){ container = 'body';}; $('a.avianolink').on('click', function(e){ e.preventDefault(); }); $('a.aviablank').attr('target', '_blank'); //activates the prettyphoto lightbox $(container).avia_activate_lightbox(); //scrollspy for main menu. must be located before smoothscrolling if($.fn.avia_scrollspy) { if(container == 'body') { $('body').avia_scrollspy({target:'.main_menu .menu li > a'}); } else { $('body').avia_scrollspy('refresh'); } } //smooth scrooling if($.fn.avia_smoothscroll) $('a[href*="#"]', container).avia_smoothscroll(container); avia_small_fixes(container); avia_hover_effect(container); avia_iframe_fix(container); //activate html5 video player if($.fn.avia_html5_activation && $.fn.mediaelementplayer) $(".avia_video, .avia_audio", container).avia_html5_activation({ratio:'16:9'}); } // ------------------------------------------------------------------------------------------- // Error log helper // ------------------------------------------------------------------------------------------- $.avia_utilities.log = function(text, type, extra) { if(typeof console == 'undefined'){return;} if(typeof type == 'undefined'){type = "log"} type = "AVIA-" + type.toUpperCase(); console.log("["+type+"] "+text); if(typeof extra != 'undefined') console.log(extra); } // ------------------------------------------------------------------------------------------- // modified SCROLLSPY by bootstrap // ------------------------------------------------------------------------------------------- function AviaScrollSpy(element, options) { var self = this; var process = $.proxy(self.process, self) , refresh = $.proxy(self.refresh, self) , $element = $(element).is('body') ? $(window) : $(element) , href self.$body = $('body') self.$win = $(window) self.options = $.extend({}, $.fn.avia_scrollspy.defaults, options) self.selector = (self.options.target || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 || '') self.activation_true = false; if(self.$body.find(self.selector + "[href*='#']").length) { self.$scrollElement = $element.on('scroll.scroll-spy.data-api', process); self.$win.on('av-height-change', refresh); self.$body.on('av_resize_finished', refresh); self.activation_true = true; self.checkFirst(); setTimeout(function() { self.refresh() self.process() },100); } } AviaScrollSpy.prototype = { constructor: AviaScrollSpy , checkFirst: function () { var current = window.location.href.split('#')[0], matching_link = this.$body.find(this.selector + "[href='"+current+"']").attr('href',current+'#top'); } , refresh: function () { if(!this.activation_true) return; var self = this , $targets this.offsets = $([]) this.targets = $([]) $targets = this.$body .find(this.selector) .map(function () { var $el = $(this) , href = $el.data('target') || $el.attr('href') , hash = this.hash , hash = hash.replace(/\//g, "") , $href = /^#\w/.test(hash) && $(hash) return ( $href && $href.length && [[ $href.position().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]] ) || null }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { self.offsets.push(this[0]) self.targets.push(this[1]) }) } , process: function () { if(!this.offsets) return; if(isNaN(this.options.offset)) this.options.offset = 0; var scrollTop = this.$scrollElement.scrollTop() + this.options.offset , scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight , maxScroll = scrollHeight - this.$scrollElement.height() , offsets = this.offsets , targets = this.targets , activeTarget = this.activeTarget , i if (scrollTop >= maxScroll) { return activeTarget != (i = targets.last()[0]) && this.activate ( i ) } for (i = offsets.length; i--;) { activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) && this.activate( targets[i] ) } } , activate: function (target) { var active , selector this.activeTarget = target $(this.selector) .parent('.' + this.options.applyClass) .removeClass(this.options.applyClass) selector = this.selector + '[data-target="' + target + '"],' + this.selector + '[href="' + target + '"]' active = $(selector) .parent('li') .addClass(this.options.applyClass) if (active.parent('.sub-menu').length) { active = active.closest('li.dropdown_ul_available').addClass(this.options.applyClass) } active.trigger('activate') } } /* AviaScrollSpy PLUGIN DEFINITION * =========================== */ $.fn.avia_scrollspy = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('scrollspy') , options = typeof option == 'object' && option if (!data) $this.data('scrollspy', (data = new AviaScrollSpy(this, options))) if (typeof option == 'string') data[option]() }) } $.fn.avia_scrollspy.Constructor = AviaScrollSpy $.fn.avia_scrollspy.calc_offset = function() { var offset_1 = (parseInt($('.html_header_sticky #main').data('scroll-offset'), 10)) || 0, offset_2 = ($(".html_header_sticky:not(.html_top_nav_header) #header_main_alternate").outerHeight()) || 0, offset_3 = ($(".html_header_sticky.html_header_unstick_top_disabled #header_meta").outerHeight()) || 0, offset_4 = 1, offset_5 = parseInt($('html').css('margin-top'),10) || 0, offset_6 = parseInt($('.av-frame-top ').outerHeight(),10) || 0; return offset_1 + offset_2 + offset_3 + offset_4 + offset_5 + offset_6; } $.fn.avia_scrollspy.defaults = { offset: $.fn.avia_scrollspy.calc_offset(), applyClass: 'current-menu-item' } function avia_site_preloader() { var win = $(window), preloader_active = $('html.av-preloader-active'), pre_wrap; if( preloader_active.length ) { var hide = function() { pre_wrap.avia_animate({opacity:0}, function() { preloader_active.removeClass('av-preloader-active'); }); }; pre_wrap = $('.av-siteloader-wrap'); setTimeout(function() { $.avia_utilities.preload({container: preloader_active, global_callback: hide }); //fallback setTimeout(function() { if(preloader_active.is('.av-preloader-active')) {  hide(); $.avia_utilities.log('Hide Preloader (Fallback)'); } },4000); if( pre_wrap.is('.av-transition-enabled') ) { var comp = new RegExp(location.host), exclude = " .no-transition, .mfp-iframe, .lightbox-added, .grid-links-ajax a, #menu-item-search a"; preloader_active.on('click', 'a:not('+exclude+')',function(e) { if(!e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey) { var link = this; if(comp.test(link.href) && link.href.split('#')[0] != location.href.split('#')[0] && link.target == "") { if(link.href.indexOf('mailto:') == -1 && link.href.indexOf('add-to-cart=') == -1 ) { e.preventDefault(); preloader_active.addClass('av-preloader-active av-preloader-reactive'); pre_wrap.avia_animate({opacity:1}, function() { window.location = link.href; }); } } } }); } }, 500); } } // ------------------------------------------------------------------------------------------- // detect browser and add class to body // ------------------------------------------------------------------------------------------- function AviaBrowserDetection(outputClassElement) { if(typeof($.browser) !== 'undefined') { var bodyclass = '', version = $.browser.version ? parseInt($.browser.version) : ""; if($.browser.msie){ bodyclass += 'avia-msie'; }else if($.browser.webkit){ bodyclass += 'avia-webkit'; }else if($.browser.mozilla) { bodyclass += 'avia-mozilla'; } if($.browser.version) bodyclass += ' ' + bodyclass + '-' + version + ' '; if($.browser.name) bodyclass += ' avia-' + $.browser.name + ' avia-' +$.browser.name +'-' + version + ' '; if($.browser.ipad){ bodyclass += ' avia-ipad '; }else if($.browser.iphone){ bodyclass += ' avia-iphone '; }else if($.browser.android){ bodyclass += ' avia-android '; }else if($.browser.win){ bodyclass += ' avia-windows '; }else if($.browser.mac){ bodyclass += ' avia-mac '; }else if($.browser.linux){ bodyclass += ' avia-linux '; } } if(outputClassElement) $(outputClassElement).addClass(bodyclass) return bodyclass; } // ------------------------------------------------------------------------------------------- // responsive menu function // ------------------------------------------------------------------------------------------- function avia_responsive_menu() { var $html = $('html'), win = $(window), header = $('.responsive #header'); if(!header.length) return; var menu = header.find('.main_menu ul:eq(0)'), first_level_items = menu.find('>li').length, container = $('#wrap_all'), show_menu_btn = $('#advanced_menu_toggle'), hide_menu_btn = $('#advanced_menu_hide'), mobile_advanced = menu.clone().attr({id:"mobile-advanced", "class":""}), sub_hidden = $html.is('.html_header_mobile_behavior'), insert_menu = function() { if(first_level_items == 0) { show_menu_btn.remove(); } else { var after_menu = $('#header .logo'); if(after_menu.length == 0) after_menu = "#main .logo:eq(0)"; show_menu_btn.insertAfter(after_menu); mobile_advanced.find('.noMobile').remove(); mobile_advanced.prependTo(container); hide_menu_btn.prependTo(container); } }, set_height = function() { var height = mobile_advanced.outerHeight(true), win_h = win.height(); if(height < win_h) height = win_h; container.css({'height':height}); mobile_advanced.css({position:'absolute', 'min-height':win_h}); }, hide_menu = function() { container.removeClass('show_mobile_menu'); setTimeout(function(){ container.css({'height':"auto", 'overflow':'hidden', 'minHeight':0}); mobile_advanced.css({display:'none'}); },600); return false; }, autohide = function() { if(container.is('.show_mobile_menu') && hide_menu_btn.css('display') == 'none'){ hide_menu(); } }, show_menu = function() { if(container.is('.show_mobile_menu')) { hide_menu(); } else { win.scrollTop(0); mobile_advanced.css({display:'block'}); setTimeout(function(){container.addClass('show_mobile_menu'); },10); set_height(); } return false; }; $html.on('click', '#mobile-advanced li a, #mobile-advanced .mega_menu_title', function() { var current = $(this); //if submenu items are hidden do the toggle if(sub_hidden) { var list_item = current.siblings('ul, .avia_mega_div'); if ( current.siblings('ul').children('.avia_mega_text_block').length && current.siblings('ul').children('li').length == 1 ) { list_item = ''; } if(list_item.length) { if(list_item.hasClass('visible_sublist')) { list_item.removeClass('visible_sublist'); } else { list_item.addClass('visible_sublist'); } set_height(); return false; } } //when clicked on anchor link remove the menu so the body can scroll to the anchor if(current.filter('[href*="#"]').length) { container.removeClass('show_mobile_menu'); container.css({'height':"auto"}); } }); show_menu_btn.click(show_menu); hide_menu_btn.click(hide_menu); win.on( 'debouncedresize', autohide ); insert_menu(); } // ------------------------------------------------------------------------------------------- // html 5 videos // ------------------------------------------------------------------------------------------- $.fn.avia_html5_activation = function(options) { var defaults = { ratio: '16:9' }; var options = $.extend(defaults, options), isMobile = $.avia_utilities.isMobile; // if(isMobile) return; this.each(function() { var fv = $(this), id_to_apply = '#' + fv.attr('id'), posterImg = fv.attr('poster'); fv.mediaelementplayer({ // if the