(function($) { "use strict"; $(document).ready(function() { var aviabodyclasses = AviaBrowserDetection('html'); $.avia_utilities = $.avia_utilities || {}; //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(); //Resize menu if logo is overlapped by th menu items avia_resize_menu(); // decreases header size when user scrolls down avia_header_size(); //show scroll top button avia_scroll_top_fade(); //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", 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({callback:'avia_lightbox_callback'}); //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'}); } // ------------------------------------------------------------------------------------------- // 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.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.$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') , $href = /^#\w/.test(this.hash) && $(this.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; 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('.dropdown-menu').length) { active = active.closest('li.dropdown').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.defaults = { offset: (parseInt($('.fixed_header #header').height(), 10)) + parseInt($('html').css('margin-top'),10), applyClass: 'current-menu-item' } // ------------------------------------------------------------------------------------------- // detect browser and add class to body // ------------------------------------------------------------------------------------------- function AviaBrowserDetection(outputClassElement) { if(typeof($.browser) !== 'undefined') { var bodyclass = ''; 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 + '-' + parseInt($.browser.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 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, bottom_menu = $('html').is('.bottom_nav_header'), switchWidth = 767; if(first_level_items > 7 + header.find('#menu-item-search').length && !bottom_menu) { switchWidth = 989; header.addClass('mobile_menu_tablet'); } if(header.is('.mobile_drop_down')) { menu.mobileMenu({ switchWidth: switchWidth, //width (in px to switch at) topOptionText: jQuery('.main_menu').data('selectname'), //first option text indentString: 'ontouchstart' in document.documentElement ? '- ' : "   "//string for indenting nested items }); } else { var container = $('#wrap_all'), show_menu = $('#advanced_menu_toggle'), hide_menu = $('#advanced_menu_hide'), mobile_advanced = menu.clone().attr({id:"mobile-advanced", "class":""}), menu_added = false; mobile_advanced.find('.noMobile').remove(); jQuery(document).on('click', '#mobile-advanced li a[href*=#]', function() { container.removeClass('show_mobile_menu'); container.css({'height':"auto"}); }); show_menu.click(function() { if(container.is('.show_mobile_menu')) { container.removeClass('show_mobile_menu'); container.css({'height':"auto"}); } else { container.addClass('show_mobile_menu'); set_height(); } return false; }); hide_menu.click(function() { container.removeClass('show_mobile_menu'); container.css({'height':"auto"}); return false; }); var set_visibility = function() { if(win.width() > switchWidth) { header.removeClass('mobile_active'); container.removeClass('show_mobile_menu'); container.css({'height':"auto"}); } else { header.addClass('mobile_active'); if(!menu_added) { var after_menu = $('#header .logo'); show_menu.insertAfter(after_menu); mobile_advanced.prependTo(container); hide_menu.prependTo(container); menu_added = true; } if(container.is('.show_mobile_menu')) { set_height(); } } }, set_height = function() { var height = mobile_advanced.css({position:'relative'}).outerHeight(true), win_h = win.height(); if(height < win_h) height = win_h; mobile_advanced.css({position:'absolute'}); container.css({'height':height}); }; win.on("debouncedresize", set_visibility); set_visibility(); } } // ------------------------------------------------------------------------------------------- //Calculate the width of the header container which contains the logo and the menu, if logo + menu exceed the container size try to reduce the menu item padding and resize the logo // ------------------------------------------------------------------------------------------- function avia_resize_menu() { var win = $(window), header = $('#header:not( .bottom_nav_header #header)'); if(!header.length) return; var menu = header.find('.main_menu ul:eq(0)'), menu_container = header.find('.main_menu'), logo = header.find('.logo'), logo_selector = $('#header:not( .bottom_nav_header #header) .logo, #header:not( .bottom_nav_header #header) .logo a img'), original_item_padding_right = new Array(), original_item_padding_left = new Array(), original_menu_width = $(menu).outerWidth(true), original_logo_width = logo.outerWidth(true), header_position_changed = 0, store_menu_data = function() { $(menu.find('>li>a').each(function(index,value){ original_item_padding_right[index] = parseInt($(this).css('padding-right').replace("px", "")); original_item_padding_left[index] = parseInt($(this).css('padding-left').replace("px", "")); })); $('#header .logo a img').load(function() { original_logo_width = logo.outerWidth(true); }); }, adjust_menu_width = function() { /* Calculate the width of the header container which contains the logo and the menu, then calculate the logo and menu width and check if we need to take care of an offset */ var headercontainer = header.find('.container'), header_width = headercontainer.innerWidth(), logo_width = logo.outerWidth(true), menu_width = $(menu).outerWidth(true), headercontainer_offset = headercontainer.offset(), logo_offset = logo.offset(), menu_offset = menu.offset(); if(typeof logo_offset == "undefined" || typeof menu_offset == "undefined") { var offset_right = 0, offset_left = 0; } else if(logo_offset.left < menu_offset.left) { var offset_left = logo_offset.left - headercontainer_offset.left, offset_right = header_width - (menu_offset.left - headercontainer_offset.left + menu_width); } else { var offset_left = menu_offset.left - headercontainer_offset.left, offset_right = header_width - (logo_offset.left - headercontainer_offset.left + logo_width); } var remaining_space = header_width - (menu_width + offset_left + offset_right + logo_width); if(!header.hasClass('mobile_active')) { /* ok, now try to reduce the padding left/right a bit. Maybe then the logo & menu have enough space */ var menu_item = $(menu.find('>li>a')), item_padding_right = new Array(), item_padding_left = new Array(), item_ratio = new Array(), item_ratio_left = new Array(), item_ratio_right = new Array(), reduction_space_left = 0, reduction_space_right = 0; $(menu_item.each(function(index,value){ item_padding_right[index] = parseInt($(this).css('padding-right').replace("px", "")); item_padding_left[index] = parseInt($(this).css('padding-left').replace("px", "")); })); $.each(item_padding_right, function(index,value){ reduction_space_right = reduction_space_right + value; }); $.each(item_padding_left, function(index,value){ reduction_space_left = reduction_space_left + value; }); $(menu_item.each(function(index,value){ item_ratio_left[index] = item_padding_left[index] / (item_padding_left[index] + item_padding_right[index]); item_ratio_right[index] = item_padding_right[index] / (item_padding_left[index] + item_padding_right[index]); item_ratio[index] = (item_padding_left[index] + item_padding_right[index]) / (reduction_space_right + reduction_space_left); })); if(original_logo_width > 0) logo_selector.css({'max-width':original_logo_width+'px', 'width':'auto'}); if((original_menu_width + original_logo_width + offset_left + offset_right) <= header_width) { $(menu_item.each(function(index,value){ $(this).css({"padding-right":original_item_padding_right[index]+"px", "padding-left":original_item_padding_left[index]+"px"}); })); } else { var total_padding = 0, left_padding = 0, right_padding = 0, new_remaining_space = remaining_space + reduction_space_left + reduction_space_right; $(menu_item.each(function(index,value){ total_padding = new_remaining_space * item_ratio[index]; right_padding = total_padding * item_ratio_right[index]; left_padding = total_padding * item_ratio_left[index]; if(original_item_padding_right[index] < right_padding && original_item_padding_left[index] < left_padding) { right_padding = original_item_padding_right[index]; left_padding =original_item_padding_left[index]; } else if(original_item_padding_right[index] < right_padding) { right_padding = original_item_padding_right[index]; left_padding = total_padding - right_padding; } else if(original_item_padding_left[index] < left_padding) { left_padding = original_item_padding_left[index]; right_padding = total_padding - left_padding; } else if(right_padding < 6 || left_padding < 6) { if(right_padding < 6) right_padding = 6; if(left_padding < 6) left_padding = 6; } $(this).css({"padding-right":Math.floor(right_padding)+"px", "padding-left":Math.floor(left_padding)+"px"}); })); if(!header.hasClass('header-scrolled')) { logo_width = (header_width - ($(menu).outerWidth(true) + offset_left + offset_right)); if(original_logo_width > 0 && logo_width > original_logo_width) logo_width = original_logo_width; logo_selector.css({'max-width':logo_width+'px', 'width':'auto'}); } else { logo_selector.css({'max-width':'none', 'width':'auto'}); } } } else { logo_selector.css({'max-width':'none', 'width':'auto'}); } }, check_header_position_change = function() { if(header_position_changed > 0 && !header.hasClass('header-scrolled')) { adjust_menu_width(); header_position_changed = 0; } else if(header_position_changed == 0 && header.hasClass('header-scrolled')) { adjust_menu_width(); header_position_changed = 1; } } if(!($('body').hasClass('avia_deactivate_menu_resize'))) { store_menu_data(); win.on("debouncedresize", adjust_menu_width); adjust_menu_width(); var check_header_position_change = self.setInterval(check_header_position_change, 500); } } // ------------------------------------------------------------------------------------------- // html 5 videos // ------------------------------------------------------------------------------------------- $.fn.avia_html5_activation = function(options) { var defaults = { ratio: '16:9' }; var options = $.extend(defaults, options); this.each(function() { var fv = $(this), id_to_apply = '#' + fv.attr('id'), posterImg = fv.attr('poster'); fv.mediaelementplayer({ // if the