Advertisement
Guest User

dfsdfds

a guest
Aug 10th, 2017
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 156.29 KB | None | 0 0
  1. (function($)
  2. {
  3.     "use strict";
  4.  
  5.     $(document).ready(function()
  6.     {
  7.         //global variables that are used on several ocassions
  8.         $.avia_utilities = $.avia_utilities || {};
  9.  
  10.         if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && 'ontouchstart' in document.documentElement)
  11.         {
  12.             $.avia_utilities.isMobile =  true;
  13.         }
  14.         else
  15.         {
  16.             $.avia_utilities.isMobile =  false;
  17.         }
  18.  
  19.         //activate fixed bg fallback for mobile
  20.         if($.fn.avia_mobile_fixed)
  21.         $('.avia-bg-style-fixed').avia_mobile_fixed();
  22.  
  23.         //activate parallax scrolling for backgrounds.
  24.         if($.fn.avia_parallax)
  25.         $('.av-parallax').avia_parallax();
  26.  
  27.         //calculate the browser height and append a css rule to the head
  28.         if($.fn.avia_browser_height)
  29.         $('.av-minimum-height, .avia-fullscreen-slider, .av-cell-min-height').avia_browser_height();
  30.  
  31.         //calculate the height of each video section
  32.         if($.fn.avia_video_section)
  33.          $('.av-section-with-video-bg').avia_video_section();
  34.  
  35.         //creates team social icon tooltip
  36.         new $.AviaTooltip({'class': "avia-tooltip", data: "avia-tooltip", delay:0, scope: "body"});
  37.  
  38.         //creates icon element tooltip
  39.         new $.AviaTooltip({'class': "avia-tooltip avia-icon-tooltip", data: "avia-icon-tooltip", delay:0, scope: "body"});
  40.  
  41.         activate_shortcode_scripts();
  42.  
  43.         //layer slider height helper
  44.         $('.avia-layerslider').layer_slider_height_helper();
  45.  
  46.         //"ajax" portfolio
  47.         $('.grid-links-ajax').avia_portfolio_preview();
  48.  
  49.         // actiavte the masonry script: sorting/loading/etc
  50.         if($.fn.avia_masonry)
  51.         $('.av-masonry').avia_masonry();
  52.  
  53.         //activate the accordion
  54.         if($.fn.aviaccordion)
  55.         $('.aviaccordion').aviaccordion();
  56.  
  57.  
  58.         //activate the accordion
  59.         if($.fn.avia_textrotator)
  60.         $('.av-rotator-container').avia_textrotator();
  61.  
  62.         //activates the tab section shortcode
  63.         if($.fn.avia_sc_tab_section)
  64.         {
  65.             $('.av-tab-section-container').avia_sc_tab_section();
  66.         }
  67.  
  68.         //activates the hor gallery  shortcode
  69.         if($.fn.avia_hor_gallery)
  70.         {
  71.             $('.av-horizontal-gallery').avia_hor_gallery();
  72.         }
  73.  
  74.  
  75.         if($.fn.avia_delayed_animation_in_container)
  76.         {
  77.             $('.av-animation-delay-container').avia_delayed_animation_in_container();
  78.         }
  79.  
  80.  
  81.     });
  82.  
  83.  
  84.  
  85.  
  86.  
  87. // -------------------------------------------------------------------------------------------
  88. // ACTIVATE ALL SHORTCODES
  89. // -------------------------------------------------------------------------------------------
  90.  
  91.     function activate_waypoints(container)
  92.     {
  93.         //activates simple css animations of the content once the user scrolls to an elements
  94.         if($.fn.avia_waypoints)
  95.         {
  96.             if(typeof container == 'undefined'){ container = 'body';};
  97.  
  98.             $('.avia_animate_when_visible', container).avia_waypoints();
  99.             $('.avia_animate_when_almost_visible', container).avia_waypoints({ offset: '80%'});
  100.  
  101.             if(container == 'body') container = '.avia_desktop body';
  102.             $('.av-animated-generic', container).avia_waypoints({ offset: '95%'});
  103.         }
  104.     }
  105.  
  106.  
  107.     function activate_shortcode_scripts(container)
  108.     {
  109.         if(typeof container == 'undefined'){ container = 'body';}
  110.  
  111.         //activates the form shortcode
  112.         if($.fn.avia_ajax_form)
  113.         {
  114.             $('.avia_ajax_form:not( .avia-disable-default-ajax )', container).avia_ajax_form();
  115.         }
  116.  
  117.         activate_waypoints(container);
  118.  
  119.         //activate the video api
  120.         if($.fn.aviaVideoApi)
  121.         {
  122.             $('.avia-slideshow iframe[src*="youtube.com"], .av_youtube_frame, .avia-slideshow iframe[src*="vimeo.com"], .avia-slideshow video').aviaVideoApi({}, 'li');
  123.         }
  124.  
  125.         //activates the toggle shortcode
  126.         if($.fn.avia_sc_toggle)
  127.         {
  128.             $('.togglecontainer', container).avia_sc_toggle();
  129.         }
  130.  
  131.         //activates the tabs shortcode
  132.         if($.fn.avia_sc_tabs)
  133.         {
  134.             $('.top_tab', container).avia_sc_tabs();
  135.             $('.sidebar_tab', container).avia_sc_tabs({sidebar:true});
  136.         }
  137.  
  138.         //activates behavior and animation for gallery
  139.         if($.fn.avia_sc_gallery)
  140.         {
  141.             $('.avia-gallery', container).avia_sc_gallery();
  142.         }
  143.  
  144.         //activates animated number shortcode
  145.         if($.fn.avia_sc_animated_number)
  146.         {
  147.             $('.avia-animated-number', container).avia_sc_animated_number();
  148.         }
  149.  
  150.         //animation for elements that are not connected like icon shortcode
  151.         if($.fn.avia_sc_animation_delayed)
  152.         {
  153.             $('.av_font_icon', container).avia_sc_animation_delayed({delay:100});
  154.             $('.avia-image-container', container).avia_sc_animation_delayed({delay:100});
  155.             $('.av-hotspot-image-container', container).avia_sc_animation_delayed({delay:100});
  156.             $('.av-animated-generic', container).avia_sc_animation_delayed({delay:100});
  157.         }
  158.  
  159.         //activates animation for iconlist
  160.         if($.fn.avia_sc_iconlist)
  161.         {
  162.             $('.avia-icon-list.av-iconlist-big', container).avia_sc_iconlist();
  163.         }
  164.  
  165.         //activates animation for progress bar
  166.         if($.fn.avia_sc_progressbar)
  167.         {
  168.             $('.avia-progress-bar-container', container).avia_sc_progressbar();
  169.         }
  170.  
  171.         //activates animation for testimonial
  172.         if($.fn.avia_sc_testimonial)
  173.         {
  174.             $('.avia-testimonial-wrapper', container).avia_sc_testimonial();
  175.         }
  176.  
  177.         //activate the fullscreen slider
  178.         $('.avia-slideshow.av_fullscreen', container).aviaFullscreenSlider();
  179.  
  180.         //activate the aviaslider
  181.         $('.avia-slideshow:not(.av_fullscreen)', container).aviaSlider();
  182.  
  183.         //content slider
  184.         $('.avia-content-slider-active', container).aviaSlider({wrapElement: '.avia-content-slider-inner', slideElement:'.slide-entry-wrap', fullfade:true});
  185.  
  186.         //testimonial slider
  187.         $('.avia-slider-testimonials', container).aviaSlider({wrapElement: '.avia-testimonial-row', slideElement:'.avia-testimonial', fullfade:true});
  188.  
  189.         //load and activate maps
  190.         if($.fn.aviaMaps)
  191.         {
  192.             $('.avia-google-map-container', container).aviaMaps();
  193.         }
  194.  
  195.          //load magazine sorting
  196.         if($.fn.aviaMagazine)
  197.         {
  198.             $('.av-magazine-tabs-active', container).aviaMagazine();
  199.         }
  200.  
  201.          //load image hotspot
  202.         if($.fn.aviaHotspots)
  203.         {
  204.             $('.av-hotspot-image-container', container).aviaHotspots();
  205.         }
  206.  
  207.          //load countdown
  208.         if($.fn.aviaCountdown)
  209.         {
  210.             $('.av-countdown-timer', container).aviaCountdown();
  211.         }
  212.  
  213.  
  214.  
  215.     }
  216.  
  217.  
  218.  
  219. // -------------------------------------------------------------------------------------------
  220. //
  221. // AVIA Countdown
  222. //
  223. // -------------------------------------------------------------------------------------------
  224. (function($)
  225. {
  226.     "use strict";
  227.  
  228.     var _units  = ['weeks','days','hours','minutes','seconds'],
  229.         _second = 1000,
  230.         _minute = _second * 60,
  231.         _hour   = _minute * 60,
  232.         _day    = _hour * 24,
  233.         _week   = _day * 7,
  234.         ticker  = function(_self)
  235.         {
  236.             var _time       = {},
  237.                 _now        = new Date(),
  238.                 _timestamp  = _self.end - _now;
  239.  
  240.             if(_timestamp <= 0)
  241.             {
  242.                 clearInterval(_self.countdown);
  243.                 return;
  244.             }
  245.  
  246.             _self.time.weeks    = Math.floor( _timestamp / _week);
  247.             _self.time.days     = Math.floor((_timestamp % _week) / _day);
  248.             _self.time.hours    = Math.floor((_timestamp % _day) / _hour);
  249.             _self.time.minutes  = Math.floor((_timestamp % _hour) / _minute);
  250.             _self.time.seconds  = Math.floor((_timestamp % _minute) / _second);
  251.  
  252.             switch(_self.data.maximum)
  253.             {
  254.                 case 1: _self.time.seconds  = Math.floor(_timestamp / _second); break;
  255.                 case 2: _self.time.minutes  = Math.floor(_timestamp / _minute); break;
  256.                 case 3: _self.time.hours    = Math.floor(_timestamp / _hour);   break;
  257.                 case 4: _self.time.days     = Math.floor(_timestamp / _day);    break;
  258.             }
  259.  
  260.             for (var i in _self.time)
  261.             {
  262.                 if(typeof _self.update[i] == "object")
  263.                 {
  264.                     if(_self.firstrun || _self.oldtime[i] != _self.time[i])
  265.                     {
  266.                         var labelkey = ( _self.time[i] === 1 ) ? "single" : "multi";
  267.  
  268.                         _self.update[i].time_container.text(_self.time[i]);
  269.                         _self.update[i].label_container.text(_self.update[i][labelkey]);
  270.                     }
  271.                 }
  272.             }
  273.  
  274.             //show ticker
  275.             if(_self.firstrun) _self.container.addClass('av-countdown-active')
  276.  
  277.             _self.oldtime   = $.extend( {}, _self.time );
  278.             _self.firstrun  = false;
  279.         };
  280.  
  281.  
  282.     $.fn.aviaCountdown = function( options )
  283.     {
  284.         if(!this.length) return;
  285.  
  286.         return this.each(function()
  287.         {
  288.             var _self           = {};
  289.             _self.update        = {};
  290.             _self.time          = {};
  291.             _self.oldtime       = {};
  292.             _self.firstrun      = true;
  293.  
  294.             _self.container     = $(this);
  295.             _self.data          = _self.container.data();
  296.             _self.end           = new Date(_self.data.year, _self.data.month, _self.data.day, _self.data.hour, _self.data.minute );
  297.  
  298.             for (var i in _units)
  299.             {
  300.                 _self.update[_units[i]] = {
  301.                     time_container:  _self.container.find('.av-countdown-' + _units[i] + ' .av-countdown-time'),
  302.                     label_container: _self.container.find('.av-countdown-' + _units[i] + ' .av-countdown-time-label'),
  303.                 };
  304.  
  305.                 if(_self.update[_units[i]].label_container.length)
  306.                 {
  307.                     _self.update[_units[i]].single = _self.update[_units[i]].label_container.data('label');
  308.                     _self.update[_units[i]].multi  = _self.update[_units[i]].label_container.data('label-multi');
  309.                 }
  310.             }
  311.  
  312.             ticker(_self);
  313.             _self.countdown     = setInterval(function(){ ticker(_self); }, 1000);
  314.  
  315.  
  316.         });
  317.     }
  318.  
  319. }(jQuery));
  320.  
  321.  
  322.  
  323. // -------------------------------------------------------------------------------------------
  324. //
  325. // AVIA Image Hotspots
  326. //
  327. // -------------------------------------------------------------------------------------------
  328. (function($)
  329. {
  330.     "use strict";
  331.  
  332.     $.fn.aviaHotspots = function( options )
  333.     {
  334.         if(!this.length) return;
  335.  
  336.         return this.each(function()
  337.         {
  338.             var _self = {};
  339.  
  340.             _self.container = $(this);
  341.             _self.hotspots  = _self.container.find('.av-image-hotspot');
  342.  
  343.                 _self.container.on('avia_start_animation', function()
  344.                 {
  345.                     setTimeout(function()
  346.                     {
  347.                         _self.hotspots.each(function(i)
  348.                         {
  349.                             var current = $(this);
  350.                             setTimeout(function(){ current.addClass('av-display-hotspot'); },300 * i);
  351.                         });
  352.                     },400);
  353.                 });
  354.  
  355.         });
  356.     }
  357.  
  358. }(jQuery));
  359.  
  360.  
  361.  
  362.  
  363. // -------------------------------------------------------------------------------------------
  364. //
  365. // AVIA Magazine function for magazine sorting
  366. //
  367. // -------------------------------------------------------------------------------------------
  368. (function($)
  369. {
  370.     "use strict";
  371.  
  372.     var animating = false,
  373.         methods = {
  374.  
  375.         switchMag: function(clicked, _self)
  376.         {
  377.             var current         = $(clicked)
  378.  
  379.             if(current.is('.active_sort') || animating) return;
  380.  
  381.             var filter          = current.data('filter'),
  382.                 oldContainer    = _self.container.filter(':visible'),
  383.                 newContainer    = _self.container.filter('.' + filter);
  384.  
  385.             //switch Class
  386.             animating = true;
  387.             _self.sort_buttons.removeClass('active_sort');
  388.             current.addClass('active_sort');
  389.  
  390.             //apply fixed heiht for transition
  391.             _self.magazine.height(_self.magazine.outerHeight());
  392.  
  393.             //switch items
  394.             oldContainer.avia_animate({opacity:0}, 200, function()
  395.             {
  396.                 oldContainer.css({display:'none'});
  397.                 newContainer.css({opacity:0, display:'block'}).avia_animate({opacity:1}, 150, function()
  398.                 {
  399.                     _self.magazine.avia_animate({height: (newContainer.outerHeight() + _self.sort_bar.outerHeight())}, 150, function()
  400.                     {
  401.                         _self.magazine.height('auto');
  402.                         animating = false;
  403.                     });
  404.  
  405.                 });
  406.             });
  407.         }
  408.     };
  409.  
  410.  
  411.     $.fn.aviaMagazine = function( options )
  412.     {
  413.         if(!this.length) return;
  414.  
  415.         return this.each(function()
  416.         {
  417.             var _self = {};
  418.  
  419.             _self.magazine      = $(this),
  420.             _self.sort_buttons  = _self.magazine.find('.av-magazine-sort a');
  421.             _self.container     = _self.magazine.find('.av-magazine-group');
  422.             _self.sort_bar      = _self.magazine.find('.av-magazine-top-bar');
  423.  
  424.             _self.sort_buttons.on('click', function(e){ e.preventDefault(); methods.switchMag(this, _self);  } );
  425.         });
  426.     }
  427.  
  428. }(jQuery));
  429.  
  430. // -------------------------------------------------------------------------------------------
  431. //
  432. // AVIA MAPS API - loads the google maps api asynchronously
  433. //
  434. // afterwards applies the map to the container
  435. //
  436. // -------------------------------------------------------------------------------------------
  437.  
  438.  
  439. (function($)
  440. {
  441.     "use strict";
  442.  
  443.     $.AviaMapsAPI  =  function(options, container)
  444.     {
  445.         if(typeof window.av_google_map == 'undefined')
  446.         {
  447.             $.avia_utilities.log('Map creation stopped, var av_google_map not found'); return
  448.         }
  449.  
  450.         // gatehr container and map data
  451.         this.container  = container;
  452.         this.$container = $( container );
  453.         this.$body      = $('body');
  454.         this.$mapid     = this.$container.data('mapid') - 1;
  455.         this.$data      = window.av_google_map[this.$mapid];
  456.         this.retina     = window.devicePixelRatio > 1;
  457.  
  458.         // set up the whole api object
  459.         this._init( options );
  460.     }
  461.  
  462.     $.AviaMapsAPI.apiFiles =
  463.     {
  464.         loading: false,
  465.         finished: false,
  466.         src: 'https://maps.googleapis.com/maps/api/js?v=3.27&callback=aviaOnGoogleMapsLoaded'
  467.     }
  468.  
  469.     $.AviaMapsAPI.prototype =
  470.     {
  471.         _init: function()
  472.         {
  473.             this._bind_execution();
  474.             this._getAPI();
  475.         },
  476.  
  477.         _getAPI: function( )
  478.         {
  479.             //make sure the api file is loaded only once
  480.             if((typeof window.google == 'undefined' || typeof window.google.maps == 'undefined') && $.AviaMapsAPI.apiFiles.loading == false)
  481.             {
  482.                 $.AviaMapsAPI.apiFiles.loading = true;
  483.                 var script  = document.createElement('script');
  484.                 script.type = 'text/javascript';
  485.                 script.src  = $.AviaMapsAPI.apiFiles.src;
  486.  
  487.                 if(avia_framework_globals.gmap_api != 'undefined' && avia_framework_globals.gmap_api != "")
  488.                 {
  489.                     script.src  += "&key=" + avia_framework_globals.gmap_api;
  490.                 }
  491.  
  492.                 document.body.appendChild(script);
  493.             }
  494.             else if((typeof window.google != 'undefined' && typeof window.google.maps != 'undefined') || $.AviaMapsAPI.apiFiles.loading == false)
  495.             //else if($.AviaMapsAPI.apiFiles.finished === true)
  496.             {
  497.                 this._applyMap();
  498.             }
  499.         },
  500.  
  501.         _bind_execution: function()
  502.         {
  503.             this.$body.on('av-google-maps-api-loaded', $.proxy( this._applyMap, this) );
  504.         },
  505.  
  506.         _applyMap: function()
  507.         {
  508.             if(typeof this.map != 'undefined') return;
  509.             if(!this.$data.marker || !this.$data.marker[0] || !this.$data.marker[0].long || !this.$data.marker[0].long)
  510.             {
  511.                 $.avia_utilities.log('Latitude or Longitude missing', 'map-error');
  512.                 return;
  513.             }
  514.  
  515.             var _self = this,
  516.                 mobile_drag = $.avia_utilities.isMobile ? this.$data.mobile_drag_control : true,
  517.                 zoomValue   = this.$data.zoom == "auto" ? 10 : this.$data.zoom;
  518.  
  519.             this.mapVars = {
  520.                 mapMaker: false, //mapmaker tiles are user generated content maps. might hold more info but also be inaccurate
  521.                 mapTypeControl: false,
  522.                 backgroundColor:'transparent',
  523.                 streetViewControl: false,
  524.                 zoomControl: this.$data.zoom_control,
  525.                 //draggable: mobile_drag,
  526.                 gestureHandling: 'cooperative',
  527.                 scrollwheel: false,
  528.                 zoom: zoomValue,
  529.                 mapTypeId:google.maps.MapTypeId.ROADMAP,
  530.                 center: new google.maps.LatLng(this.$data.marker[0].lat, this.$data.marker[0].long),
  531.                 styles:[{featureType: "poi", elementType: "labels", stylers: [ { visibility: "off" }] }]
  532.             };
  533.  
  534.             this.map = new google.maps.Map(this.container, this.mapVars);
  535.  
  536.             this._applyMapStyle();
  537.  
  538.             if(this.$data.zoom == "auto")
  539.             {
  540.                 this._setAutoZoom();
  541.             }
  542.  
  543.             google.maps.event.addListenerOnce(this.map, 'tilesloaded', function() {
  544.                 _self._addMarkers();
  545.             });
  546.         },
  547.  
  548.         _setAutoZoom: function()
  549.         {
  550.             var bounds = new google.maps.LatLngBounds();
  551.  
  552.             for (var key in this.$data.marker)
  553.             {
  554.                 bounds.extend( new google.maps.LatLng (this.$data.marker[key].lat , this.$data.marker[key].long) );
  555.             }
  556.  
  557.             this.map.fitBounds(bounds);
  558.         },
  559.  
  560.         _applyMapStyle: function()
  561.         {
  562.             var stylers = [], style = [], mapType, style_color = "";
  563.  
  564.             if(this.$data.hue != "") stylers.push({hue: this.$data.hue});
  565.             if(this.$data.saturation != "") stylers.push({saturation: this.$data.saturation});
  566.  
  567.             if(stylers.length)
  568.             {
  569.                 style = [{
  570.                           featureType: "all",
  571.                           elementType: "all",
  572.                           stylers: stylers
  573.                         }, {
  574.                           featureType: "poi",
  575.                           stylers: [
  576.                             { visibility: "off" }
  577.                           ]
  578.                         }];
  579.  
  580.  
  581.                 if(this.$data.saturation == "fill")
  582.                 {
  583.  
  584.                     style_color = this.$data.hue || "#242424";
  585.  
  586.                     var c = style_color.substring(1);      // strip #
  587.                     var rgb = parseInt(c, 16);   // convert rrggbb to decimal
  588.                     var r = (rgb >> 16) & 0xff;  // extract red
  589.                     var g = (rgb >>  8) & 0xff;  // extract green
  590.                     var b = (rgb >>  0) & 0xff;  // extract blue
  591.  
  592.                     var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; // per ITU-R BT.709
  593.                     var lightness = 1;
  594.                     var street_light = 2;
  595.  
  596.                     if (luma > 60) {
  597.                         lightness = -1;
  598.                         street_light = 3;
  599.                     }
  600.                     if (luma > 220) {
  601.                         lightness = -2;
  602.                         street_light = -2;
  603.                     }
  604.  
  605.                 style = [
  606. {"featureType":"all","elementType":"all","stylers":[{"color":style_color},{"lightness":0}]},
  607. {"featureType":"all","elementType":"labels.text.fill","stylers":[{"color":style_color},{"lightness":(25 * street_light)}]},
  608. {"featureType":"all","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":style_color},{"lightness":3}]},
  609. {"featureType":"all","elementType":"labels.icon","stylers":[{"visibility":"off"}]},
  610. {"featureType":"administrative","elementType":"geometry.fill","stylers":[{"color":style_color},{"lightness":30}]},
  611. {"featureType":"administrative","elementType":"geometry.stroke","stylers":[{"color":style_color},{"lightness":30},{"weight":1.2}]},
  612. {"featureType":"landscape","elementType":"geometry","stylers":[{visibility: 'simplified'},{"color":style_color},{"lightness":3}]},
  613. {"featureType":"poi","elementType":"geometry","stylers":[{ "visibility": "off" }]},
  614. {"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"color":style_color},{"lightness":-3}]},
  615. {"featureType":"road.highway","elementType":"geometry.stroke","stylers":[{"color":style_color},{"lightness":2},{"weight":0.2}]},
  616. {"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":style_color},{"lightness":-3}]},
  617. {"featureType":"road.local","elementType":"geometry","stylers":[{"color":style_color},{"lightness":-3}]},
  618. {"featureType":"transit","elementType":"geometry","stylers":[{"color":style_color},{"lightness":-3}]},
  619. {"featureType":"water","elementType":"geometry","stylers":[{"color":style_color},{"lightness":-20}]}
  620.                         ];
  621.                 }
  622.  
  623.                 mapType = new google.maps.StyledMapType(style, { name:"av_map_style" });
  624.                 this.map.mapTypes.set('av_styled_map', mapType);
  625.                 this.map.setMapTypeId('av_styled_map');
  626.             }
  627.         },
  628.  
  629.         _addMarkers: function()
  630.         {
  631.             for (var key in this.$data.marker)
  632.             {
  633.                 var _self = this;
  634.  
  635.                 (function(key, _self)
  636.                 {
  637.                     setTimeout(function()
  638.                     {
  639.                             var marker = "";
  640.  
  641.                             if(!_self.$data.marker[key] || !_self.$data.marker[key].long || !_self.$data.marker[key].long)
  642.                             {
  643.                                 $.avia_utilities.log('Latitude or Longitude for single marker missing', 'map-error');
  644.                                 return;
  645.                             }
  646.  
  647.                             _self.$data.LatLng = new google.maps.LatLng(_self.$data.marker[key].lat, _self.$data.marker[key].long);
  648.  
  649.                             var markerArgs = {
  650.                               flat: false,
  651.                               position: _self.$data.LatLng,
  652.                               animation: google.maps.Animation.BOUNCE,
  653.                               map: _self.map,
  654.                               title: _self.$data.marker[key].address,
  655.                               optimized: false
  656.                             };
  657.  
  658.                             //set a custom marker image if available. also set the size and reduce the marker on retina size so its sharp
  659.                             if(_self.$data.marker[key].icon && _self.$data.marker[key].imagesize)
  660.                             {
  661.                                 var size = _self.$data.marker[key].imagesize, half = "", full = "";
  662.  
  663.                                 if(_self.retina && size > 40) size = 40;            //retina downsize to at least half the px size
  664.                                 half = new google.maps.Point(size / 2, size ) ;     //used to position the marker
  665.                                 full = new google.maps.Size(size , size ) ;         //marker size
  666.                                 markerArgs.icon = new google.maps.MarkerImage(_self.$data.marker[key].icon, null, null, half, full);
  667.                             }
  668.  
  669.                             marker = new google.maps.Marker(markerArgs);
  670.  
  671.                             setTimeout(function(){ marker.setAnimation(null); _self._infoWindow(_self.map, marker, _self.$data.marker[key]); },500);
  672.  
  673.                     },200 * (parseInt(key,10) + 1));
  674.  
  675.                 }(key, _self));
  676.             }
  677.         },
  678.  
  679.         _infoWindow: function(map, marker, data)
  680.         {
  681.             var info = $.trim(data.content);
  682.  
  683.             if(info != "")
  684.             {
  685.                 var infowindow = new google.maps.InfoWindow({
  686.                     content: info
  687.                 });
  688.  
  689.                 google.maps.event.addListener(marker, 'click', function() {
  690.                     infowindow.open(map,marker);
  691.                 });
  692.  
  693.                 if(data.tooltip_display) infowindow.open(map,marker);
  694.             }
  695.         }
  696.  
  697.  
  698.     }
  699.  
  700.     //simple wrapper to call the api. makes sure that the api data is not applied twice
  701.     $.fn.aviaMaps = function( options )
  702.     {
  703.         return this.each(function()
  704.         {
  705.             var self = $.data( this, 'aviaMapsApi' );
  706.  
  707.             if(!self)
  708.             {
  709.                 self = $.data( this, 'aviaMapsApi', new $.AviaMapsAPI( options, this ) );
  710.             }
  711.         });
  712.     }
  713.  
  714. })( jQuery );
  715.  
  716. //this function is executed once the api file is loaded
  717. window.aviaOnGoogleMapsLoaded = function(){ $('body').trigger('av-google-maps-api-loaded'); $.AviaMapsAPI.apiFiles.finished = true; };
  718.  
  719.  
  720. // -------------------------------------------------------------------------------------------
  721. //
  722. // AVIA VIDEO API - make sure that youtube, vimeo and html 5 use the same interface
  723. //
  724. // requires froogaloop vimeo library and youtube iframe api (yt can be loaded async)
  725. //
  726. // -------------------------------------------------------------------------------------------
  727.  
  728.  
  729. (function($)
  730. {
  731.     "use strict";
  732.  
  733.     $.AviaVideoAPI  =  function(options, video, option_container)
  734.     {
  735.         // actual video element. either iframe or video
  736.         this.$video = $( video );
  737.  
  738.         // container where the AviaVideoAPI object will be stored as data, and that can receive events like play, pause etc
  739.         // also the container that allows to overwrite javacript options by adding html data- attributes
  740.         this.$option_container = option_container ? $( option_container ) : this.$video;
  741.  
  742.         //mobile device?
  743.         this.isMobile   = $.avia_utilities.isMobile;
  744.  
  745.         //iamge fallback use
  746.         this.fallback = this.isMobile ? this.$option_container.is('.av-mobile-fallback-image') : false;
  747.  
  748.         if(this.fallback) return;
  749.  
  750.         // set up the whole api object
  751.         this._init( options );
  752.  
  753.     }
  754.  
  755.     $.AviaVideoAPI.defaults  = {
  756.  
  757.         loop: false,
  758.         mute: false,
  759.         controls: false,
  760.         events: 'play pause mute unmute loop toggle reset unload'
  761.  
  762.     };
  763.  
  764.     $.AviaVideoAPI.apiFiles =
  765.     {
  766.         youtube : {loaded: false, src: 'https://www.youtube.com/iframe_api' }
  767.     }
  768.  
  769.     $.AviaVideoAPI.prototype =
  770.     {
  771.         _init: function( options )
  772.         {
  773.             // set slider options
  774.             this.options = this._setOptions(options);
  775.  
  776.             // info which video service we are using: html5, vimeo or youtube
  777.             this.type = this._getPlayerType();
  778.  
  779.             // store the player object to the this.player variable created by one of the APIs (mediaelement, youtube, vimeo)
  780.             this._setPlayer();
  781.  
  782.             // set to true once the events are bound so it doesnt happen a second time by accident or racing condition
  783.             this.eventsBound = false;
  784.  
  785.             // info if the video is playing
  786.             this.playing = false;
  787.  
  788.             //set css class that video is currently not playing
  789.             this.$option_container.addClass('av-video-paused');
  790.  
  791.             //play pause indicator
  792.             this.pp = $.avia_utilities.playpause(this.$option_container);
  793.         },
  794.  
  795.  
  796.         //set the video options by first merging the default options and the passed options, then checking the video element if any data attributes overwrite the option set
  797.         _setOptions: function(options)
  798.         {
  799.             var newOptions  = $.extend( true, {}, $.AviaVideoAPI.defaults, options ),
  800.                 htmlData    = this.$option_container.data(),
  801.                 i           = "";
  802.  
  803.             //overwritte passed option set with any data properties on the html element
  804.             for (i in htmlData)
  805.             {
  806.                 if (htmlData.hasOwnProperty(i) && (typeof htmlData[i] === "string" || typeof htmlData[i] === "number" || typeof htmlData[i] === "boolean"))
  807.                 {
  808.                     newOptions[i] = htmlData[i];
  809.                 }
  810.             }
  811.  
  812.             return newOptions;
  813.         },
  814.  
  815.  
  816.         //get the player type
  817.         _getPlayerType: function()
  818.         {
  819.             var vid_src = this.$video.get(0).src || this.$video.data('src');
  820.  
  821.  
  822.             if(this.$video.is('video'))                 return 'html5';
  823.             if(this.$video.is('.av_youtube_frame'))     return 'youtube';
  824.             if(vid_src.indexOf('vimeo.com') != -1 )     return 'vimeo';
  825.             if(vid_src.indexOf('youtube.com') != -1)    return 'youtube';
  826.         },
  827.  
  828.         //get the player object
  829.         _setPlayer: function()
  830.         {
  831.             var _self = this;
  832.  
  833.             switch(this.type)
  834.             {
  835.                 case "html5":
  836.  
  837.                     this.player = this.$video.data('mediaelementplayer');
  838.                     this._playerReady();
  839.  
  840.                 break;
  841.  
  842.                 case "vimeo":
  843.  
  844.                     this.player = Froogaloop(this.$video.get(0));
  845.                     this._playerReady();
  846.  
  847.                 break;
  848.  
  849.                 case "youtube":
  850.  
  851.                     this._getAPI(this.type);
  852.                     $('body').on('av-youtube-iframe-api-loaded', function(){ _self._playerReady(); });
  853.  
  854.                 break;
  855.             }
  856.         },
  857.  
  858.         _getAPI: function( api )
  859.         {
  860.             //make sure the api file is loaded only once
  861.             if($.AviaVideoAPI.apiFiles[api].loaded === false)
  862.             {
  863.                 $.AviaVideoAPI.apiFiles[api].loaded = true;
  864.                 //load the file async
  865.                 var tag     = document.createElement('script'),
  866.                     first   = document.getElementsByTagName('script')[0];
  867.  
  868.                 tag.src = $.AviaVideoAPI.apiFiles[api].src;
  869.                 first.parentNode.insertBefore(tag, first);
  870.             }
  871.         },
  872.  
  873.  
  874.  
  875.         //wait for player to be ready, then bind events
  876.         _playerReady: function()
  877.         {
  878.             var _self = this;
  879.  
  880.             this.$option_container.on('av-video-loaded', function(){ _self._bindEvents(); });
  881.  
  882.             switch(this.type)
  883.             {
  884.                 case "html5":
  885.  
  886.                     this.$video.on('av-mediajs-loaded', function(){ _self.$option_container.trigger('av-video-loaded'); });
  887.                     this.$video.on('av-mediajs-ended' , function(){ _self.$option_container.trigger('av-video-ended');  });
  888.  
  889.                 break;
  890.                 case "vimeo":
  891.  
  892.                     //finish event must be applied after ready event for firefox
  893.                     _self.player.addEvent('ready',  function(){ _self.$option_container.trigger('av-video-loaded');
  894.                     _self.player.addEvent('finish', function(){ _self.$option_container.trigger('av-video-ended');  });
  895.                     });
  896.  
  897.                     // vimeo sometimes does not fire. fallback jquery load event should fix this
  898.                     // currently not used because it causes firefox problems
  899.                     /*
  900.                     this.$video.load(function()
  901.                     {
  902.                         if(_self.eventsBound == true || typeof _self.eventsBound == 'undefined') return;
  903.                         _self.$option_container.trigger('av-video-loaded');
  904.                         $.avia_utilities.log('VIMEO Fallback Trigger');
  905.                     });
  906.                     */
  907.  
  908.  
  909.                 break;
  910.  
  911.                 case "youtube":
  912.  
  913.                     var params = _self.$video.data();
  914.  
  915.                     if(_self._supports_video()) params.html5 = 1;
  916.  
  917.                     _self.player = new YT.Player(_self.$video.attr('id'), {
  918.                         videoId: params.videoid,
  919.                         height: _self.$video.attr('height'),
  920.                         width: _self.$video.attr('width'),
  921.                         playerVars: params,
  922.                         events: {
  923.                         'onReady': function(){ _self.$option_container.trigger('av-video-loaded'); },
  924.                         'onError': function(player){ $.avia_utilities.log('YOUTUBE ERROR:', 'error', player); },
  925.                         'onStateChange': function(event){
  926.                             if (event.data === YT.PlayerState.ENDED)
  927.                             {
  928.                                 var command = _self.options.loop != false ? 'loop' : 'av-video-ended';
  929.                                 _self.$option_container.trigger(command);
  930.                             }
  931.                           }
  932.                         }
  933.                     });
  934.  
  935.  
  936.                 break;
  937.             }
  938.  
  939.             //fallback always trigger after 2 seconds
  940.             setTimeout(function()
  941.             {
  942.                 if(_self.eventsBound == true || typeof _self.eventsBound == 'undefined' || _self.type == 'youtube' ) { return; }
  943.                 $.avia_utilities.log('Fallback Video Trigger "'+_self.type+'":', 'log', _self);
  944.  
  945.                 _self.$option_container.trigger('av-video-loaded');
  946.  
  947.             },2000);
  948.  
  949.         },
  950.  
  951.         //bind events we should listen to, to the player
  952.         _bindEvents: function()
  953.         {
  954.             if(this.eventsBound == true || typeof this.eventsBound == 'undefined')
  955.             {
  956.                 return;
  957.             }
  958.  
  959.             var _self = this, volume = 'unmute';
  960.  
  961.             this.eventsBound = true;
  962.  
  963.             this.$option_container.on(this.options.events, function(e)
  964.             {
  965.                 _self.api(e.type);
  966.             });
  967.  
  968.             if(!_self.isMobile)
  969.             {
  970.                 //set up initial options
  971.                 if(this.options.mute != false) { volume = "mute";    }
  972.                 if(this.options.loop != false) { _self.api('loop'); }
  973.  
  974.                 _self.api(volume);
  975.             }
  976.  
  977.             //set timeout to prevent racing conditions with other scripts
  978.             setTimeout(function()
  979.             {
  980.                 _self.$option_container.trigger('av-video-events-bound').addClass('av-video-events-bound');
  981.             },50);
  982.         },
  983.  
  984.  
  985.         _supports_video: function() {
  986.           return !!document.createElement('video').canPlayType;
  987.         },
  988.  
  989.  
  990.         /************************************************************************
  991.         PUBLIC Methods
  992.         *************************************************************************/
  993.  
  994.         api: function( action )
  995.         {
  996.             //commands on mobile can not be executed if the player was not started manually
  997.             if(this.isMobile && !this.was_started()) return;
  998.  
  999.             // prevent calling of unbound function
  1000.             if(this.options.events.indexOf(action) === -1) return;
  1001.  
  1002.             // broadcast that the command was executed
  1003.             this.$option_container.trigger('av-video-'+action+'-executed');
  1004.  
  1005.             // calls the function based on action. eg: _html5_play()
  1006.             if(typeof this[ '_' + this.type + '_' + action] == 'function')
  1007.             {
  1008.                 this[ '_' + this.type + '_' + action].call(this);
  1009.             }
  1010.  
  1011.             //call generic function eg: _toggle() or _play()
  1012.             if(typeof this[ '_' + action] == 'function')
  1013.             {
  1014.                 this[ '_' + action].call(this);
  1015.             }
  1016.  
  1017.         },
  1018.  
  1019.         was_started: function()
  1020.         {
  1021.             if(!this.player) return false;
  1022.  
  1023.             switch(this.type)
  1024.             {
  1025.                 case "html5":
  1026.                     if(this.player.getCurrentTime() > 0) return true;
  1027.                 break;
  1028.  
  1029.                 case "vimeo":
  1030.                     if(this.player.api('getCurrentTime') > 0) return true;
  1031.                 break;
  1032.  
  1033.                 case "youtube":
  1034.                     if(this.player.getPlayerState() !== -1) return true;
  1035.                 break;
  1036.             }
  1037.  
  1038.             return false;
  1039.         },
  1040.  
  1041.         /************************************************************************
  1042.         Generic Methods, are always executed and usually set variables
  1043.         *************************************************************************/
  1044.         _play: function()
  1045.         {
  1046.             this.playing = true;
  1047.             this.$option_container.addClass('av-video-playing').removeClass('av-video-paused');
  1048.         },
  1049.  
  1050.         _pause: function()
  1051.         {
  1052.             this.playing = false;
  1053.             this.$option_container.removeClass('av-video-playing').addClass('av-video-paused');
  1054.         },
  1055.  
  1056.         _loop: function()
  1057.         {
  1058.             this.options.loop = true;
  1059.         },
  1060.  
  1061.         _toggle: function( )
  1062.         {
  1063.             var command = this.playing == true ? 'pause' : 'play';
  1064.  
  1065.             this.api(command);
  1066.             this.pp.set(command);
  1067.         },
  1068.  
  1069.  
  1070.         /************************************************************************
  1071.         VIMEO Methods
  1072.         *************************************************************************/
  1073.  
  1074.         _vimeo_play: function( )
  1075.         {
  1076.             this.player.api('play');
  1077.         },
  1078.  
  1079.         _vimeo_pause: function( )
  1080.         {
  1081.             this.player.api('pause');
  1082.         },
  1083.  
  1084.         _vimeo_mute: function( )
  1085.         {
  1086.             this.player.api('setVolume', 0);
  1087.         },
  1088.  
  1089.         _vimeo_unmute: function( )
  1090.         {
  1091.             this.player.api('setVolume', 0.7);
  1092.         },
  1093.  
  1094.         _vimeo_loop: function( )
  1095.         {
  1096.             // currently throws error, must be set in iframe
  1097.             // this.player.api('setLoop', true);
  1098.         },
  1099.  
  1100.         _vimeo_reset: function( )
  1101.         {
  1102.             this.player.api('seekTo',0);
  1103.         },
  1104.  
  1105.         _vimeo_unload: function()
  1106.         {
  1107.             this.player.api('unload');
  1108.         },
  1109.  
  1110.         /************************************************************************
  1111.         YOUTUBE Methods
  1112.         *************************************************************************/
  1113.  
  1114.         _youtube_play: function( )
  1115.         {
  1116.             this.player.playVideo();
  1117.         },
  1118.  
  1119.         _youtube_pause: function( )
  1120.         {
  1121.             this.player.pauseVideo()
  1122.         },
  1123.  
  1124.         _youtube_mute: function( )
  1125.         {
  1126.             this.player.mute();
  1127.         },
  1128.  
  1129.         _youtube_unmute: function( )
  1130.         {
  1131.             this.player.unMute();
  1132.         },
  1133.  
  1134.         _youtube_loop: function( )
  1135.         {
  1136.             // does not work properly with iframe api. needs to manual loop on "end" event
  1137.             // this.player.setLoop(true);
  1138.             if(this.playing == true) this.player.seekTo(0);
  1139.         },
  1140.  
  1141.         _youtube_reset: function( )
  1142.         {
  1143.             this.player.stopVideo();
  1144.         },
  1145.  
  1146.         _youtube_unload: function()
  1147.         {
  1148.             this.player.clearVideo();
  1149.         },
  1150.  
  1151.         /************************************************************************
  1152.         HTML5 Methods
  1153.         *************************************************************************/
  1154.  
  1155.         _html5_play: function( )
  1156.         {
  1157.             //disable stoping of other videos in case the user wants to run section bgs
  1158.             this.player.options.pauseOtherPlayers = false;
  1159.             this.player.play();
  1160.         },
  1161.  
  1162.         _html5_pause: function( )
  1163.         {
  1164.             this.player.pause();
  1165.         },
  1166.  
  1167.         _html5_mute: function( )
  1168.         {
  1169.             this.player.setMuted(true);
  1170.         },
  1171.  
  1172.         _html5_unmute: function( )
  1173.         {
  1174.             this.player.setVolume(0.7);
  1175.         },
  1176.  
  1177.         _html5_loop: function( )
  1178.         {
  1179.             this.player.options.loop = true;
  1180.         },
  1181.  
  1182.         _html5_reset: function( )
  1183.         {
  1184.             this.player.setCurrentTime(0);
  1185.         },
  1186.  
  1187.         _html5_unload: function()
  1188.         {
  1189.             this._html5_pause();
  1190.             this._html5_reset();
  1191.         }
  1192.     }
  1193.  
  1194.     //simple wrapper to call the api. makes sure that the api data is not applied twice
  1195.     $.fn.aviaVideoApi = function( options , apply_to_parent)
  1196.     {
  1197.         return this.each(function()
  1198.         {
  1199.             // by default save the object as data to the initial video.
  1200.             // in the case of slideshows its more benefitial to save it to a parent element (eg: the slide)
  1201.             var applyTo = this;
  1202.  
  1203.             if(apply_to_parent)
  1204.             {
  1205.                 applyTo = $(this).parents(apply_to_parent).get(0);
  1206.             }
  1207.  
  1208.             var self = $.data( applyTo, 'aviaVideoApi' );
  1209.  
  1210.             if(!self)
  1211.             {
  1212.                 self = $.data( applyTo, 'aviaVideoApi', new $.AviaVideoAPI( options, this, applyTo ) );
  1213.             }
  1214.         });
  1215.     }
  1216.  
  1217. })( jQuery );
  1218.  
  1219. window.onYouTubeIframeAPIReady = function(){ $('body').trigger('av-youtube-iframe-api-loaded'); };
  1220.  
  1221.  
  1222.  
  1223. // -------------------------------------------------------------------------------------------
  1224. // Masonry
  1225. // -------------------------------------------------------------------------------------------
  1226.  
  1227. $.fn.avia_masonry = function(options)
  1228. {
  1229.     //return if we didnt find anything
  1230.     if(!this.length) return this;
  1231.  
  1232.     var the_body = $('body'),
  1233.         the_win  = $(window),
  1234.         isMobile = $.avia_utilities.isMobile,
  1235.         loading = false,
  1236.         methods = {
  1237.  
  1238.  
  1239.         masonry_filter: function()
  1240.         {
  1241.             var current     = $(this),
  1242.                 linktext    = current.html(),
  1243.                 selector    = current.data('filter'),
  1244.                 masonry     = current.parents('.av-masonry:eq(0)'),
  1245.                 container   = masonry.find('.av-masonry-container:eq(0)'),
  1246.                 links       = masonry.find('.av-masonry-sort a'),
  1247.                 activeCat   = masonry.find('.av-current-sort-title');
  1248.  
  1249.                 links.removeClass('active_sort');
  1250.                 current.addClass('active_sort');
  1251.                 container.attr('id', 'masonry_id_'+selector);
  1252.  
  1253.                 if(activeCat.length) activeCat.html(linktext);
  1254.  
  1255.                 methods.applyMasonry(container, selector, function()
  1256.                 {
  1257.                     container.css({overflow:'visible'});
  1258.                 });
  1259.  
  1260.                 return false;
  1261.         },
  1262.  
  1263.         applyMasonry: function(container, selector, callback)
  1264.         {
  1265.             var filters = selector ? {filter: '.'+selector} : {};
  1266.  
  1267.             filters['layoutMode'] = 'packery';
  1268.             filters['packery'] = {gutter:0};
  1269.             filters['percentPosition'] = true;
  1270.             filters['itemSelector'] = "a.isotope-item, div.isotope-item";
  1271.  
  1272.             container.isotope(filters, function()
  1273.             {
  1274.                 the_win.trigger('av-height-change');
  1275.             });
  1276.  
  1277.             if(typeof callback === 'function')
  1278.             {
  1279.                 setTimeout(callback, 0);
  1280.             }
  1281.         },
  1282.  
  1283.         show_bricks: function(bricks, callback)
  1284.         {
  1285.             bricks.each(function(i)
  1286.             {
  1287.                 var currentLink     = $(this),
  1288.                     browserPrefix   = $.avia_utilities.supports('transition'),
  1289.                     multiplier      = isMobile ? 0 : 100;
  1290.  
  1291.                 setTimeout(function()
  1292.                 {
  1293.                     if(browserPrefix === false)
  1294.                     {
  1295.                         currentLink.css({visibility:"visible", opacity:0}).animate({opacity:1},1500);
  1296.                     }
  1297.                     else
  1298.                     {
  1299.                         currentLink.addClass('av-masonry-item-loaded');
  1300.                     }
  1301.  
  1302.                     if(i == bricks.length - 1 && typeof callback == 'function')
  1303.                     {
  1304.                         callback.call();
  1305.                         the_win.trigger('av-height-change');
  1306.                     }
  1307.  
  1308.                 }, (multiplier * i));
  1309.             });
  1310.         },
  1311.  
  1312.         loadMore: function(e)
  1313.         {
  1314.             e.preventDefault();
  1315.  
  1316.             if(loading) return false;
  1317.  
  1318.             loading = true;
  1319.  
  1320.             var current     = $(this),
  1321.                 data        = current.data(),
  1322.                 masonry     = current.parents('.av-masonry:eq(0)'),
  1323.                 container   = masonry.find('.av-masonry-container'),
  1324.                 items       = masonry.find('.av-masonry-entry'),
  1325.                 loader      = $.avia_utilities.loading(),
  1326.                 finished    = function(){ loading = false; loader.hide(); the_body.trigger('av_resize_finished'); };
  1327.  
  1328.             //calculate a new offset
  1329.             if(!data.offset){ data.offset = 0; }
  1330.             data.offset += data.items;
  1331.             data.action = 'avia_ajax_masonry_more';
  1332.             data.loaded = []; //prevents duplicate entries from beeing loaded when randomized is active
  1333.  
  1334.             items.each(function(){
  1335.                 var item_id = $(this).data('av-masonry-item');
  1336.                 if(item_id) data.loaded.push( item_id );
  1337.             });
  1338.  
  1339.              $.ajax({
  1340.                 url: avia_framework_globals.ajaxurl,
  1341.                 type: "POST",
  1342.                 data:data,
  1343.                 beforeSend: function()
  1344.                 {
  1345.                     loader.show();
  1346.                 },
  1347.                 success: function(response)
  1348.                 {
  1349.                     if(response.indexOf("{av-masonry-loaded}") !== -1)
  1350.                     {
  1351.                         //fetch the response. if any php warnings were displayed before rendering of the items the are removed by the string split
  1352.                         var response  = response.split('{av-masonry-loaded}'),
  1353.                             new_items = $(response.pop()).filter('.isotope-item');
  1354.  
  1355.                             //check if we got more items than we need. if not we have reached the end of items
  1356.                             if(new_items.length > data.items)
  1357.                             {
  1358.                                 new_items = new_items.not(':last');
  1359.                             }
  1360.                             else
  1361.                             {
  1362.                                 current.addClass('av-masonry-no-more-items');
  1363.                             }
  1364.  
  1365.                             var load_container = $('<div class="loadcontainer"></div>').append(new_items);
  1366.  
  1367.  
  1368.  
  1369.                             $.avia_utilities.preload({container: load_container, single_callback:  function()
  1370.                             {
  1371.                                 var links = masonry.find('.av-masonry-sort a'),
  1372.                                     filter_container = masonry.find('.av-sort-by-term'),
  1373.                                     allowed_filters = filter_container.data("av-allowed-sort");
  1374.  
  1375.                                 filter_container.hide();
  1376.  
  1377.                                 loader.hide();
  1378.                                 container.isotope( 'insert', new_items);
  1379.                                 $.avia_utilities.avia_ajax_call(masonry);
  1380.                                 setTimeout( function(){ methods.show_bricks( new_items , finished); },150);
  1381.                                 setTimeout(function(){ the_win.trigger('av-height-change'); }, 550);
  1382.                                 if(links)
  1383.                                 {
  1384.                                     $(links).each(function(filterlinkindex)
  1385.                                     {
  1386.                                         var filterlink = $(this),
  1387.                                         sort = filterlink.data('filter');
  1388.  
  1389.                                         if(new_items)
  1390.                                         {
  1391.                                             $(new_items).each(function(itemindex){
  1392.                                                 var item = $(this);
  1393.  
  1394.                                                 if(item.hasClass(sort) && allowed_filters.indexOf(sort) !== -1)
  1395.                                                 {
  1396.                                                     var term_count = filterlink.find('.avia-term-count').text();
  1397.                                                     filterlink.find('.avia-term-count').text(' ' + (parseInt(term_count) + 1) + ' ');
  1398.  
  1399.                                                     if(filterlink.hasClass('avia_hide_sort'))
  1400.                                                     {
  1401.                                                         filterlink.removeClass('avia_hide_sort').addClass('avia_show_sort');
  1402.                                                         masonry.find('.av-masonry-sort .'+sort+'_sep').removeClass('avia_hide_sort').addClass('avia_show_sort');
  1403.                                                         masonry.find('.av-masonry-sort .av-sort-by-term').removeClass('hidden');
  1404.                                                     }
  1405.                                                 }
  1406.                                             });
  1407.                                         }
  1408.                                     });
  1409.  
  1410.                                 }
  1411.  
  1412.                                                 filter_container.fadeIn();
  1413.                             }
  1414.                         });
  1415.                     }
  1416.                     else
  1417.                     {
  1418.                         finished();
  1419.                     }
  1420.                 },
  1421.                 error: finished,
  1422.                 complete: function()
  1423.                 {
  1424.  
  1425.                 }
  1426.             });
  1427.         }
  1428.  
  1429.     };
  1430.  
  1431.     return this.each(function()
  1432.     {
  1433.         var masonry         = $(this),
  1434.             container       = masonry.find('.av-masonry-container'),
  1435.             bricks          = masonry.find('.isotope-item'),
  1436.             filter          = masonry.find('.av-masonry-sort').css({visibility:"visible", opacity:0}).on('click', 'a',  methods.masonry_filter),
  1437.             load_more       = masonry.find('.av-masonry-load-more').css({visibility:"visible", opacity:0});
  1438.  
  1439.         $.avia_utilities.preload({container: container, single_callback:  function()
  1440.         {
  1441.             var start_animation = function()
  1442.             {
  1443.                 filter.animate({opacity:1}, 400);
  1444.  
  1445.                 //fix for non aligned elements because of scrollbar
  1446.                 if(container.outerHeight() + container.offset().top + $('#footer').outerHeight() > $(window).height())
  1447.                 {
  1448.                     $('html').css({'overflow-y':'scroll'});
  1449.                 }
  1450.  
  1451.                 methods.applyMasonry(container, false, function()
  1452.                 {
  1453.                     masonry.addClass('avia_sortable_active');
  1454.                     container.removeClass('av-js-disabled ');
  1455.                 });
  1456.  
  1457.                 methods.show_bricks(bricks, function()
  1458.                 {
  1459.                     load_more.css({opacity:1}).on('click',  methods.loadMore);
  1460.                 });
  1461.  
  1462.                 //container.isotope( 'reLayout' );
  1463.  
  1464.             };
  1465.  
  1466.             if(isMobile)
  1467.             {
  1468.                 start_animation();
  1469.             }
  1470.             else
  1471.             {
  1472.                 masonry.waypoint(start_animation , { offset: '80%'} );
  1473.             }
  1474.  
  1475.             // update columnWidth on window resize
  1476.             $(window).on( 'debouncedresize', function()
  1477.             {
  1478.                 methods.applyMasonry(container, false, function()
  1479.                 {
  1480.                     masonry.addClass('avia_sortable_active');
  1481.                 });
  1482.             });
  1483.         }
  1484.     });
  1485.  
  1486.  
  1487.     });
  1488. };
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494. // -------------------------------------------------------------------------------------------
  1495. // Avia AJAX Portfolio
  1496. // -------------------------------------------------------------------------------------------
  1497.  
  1498. (function($)
  1499. {
  1500.     "use strict";
  1501.     $.avia_utilities = $.avia_utilities || {};
  1502.  
  1503.     $.fn.avia_portfolio_preview = function(passed_options)
  1504.     {
  1505.         var win  = $(window),
  1506.         the_body = $('body'),
  1507.         isMobile = $.avia_utilities.isMobile,
  1508.         defaults =
  1509.         {
  1510.             open_in:    '.portfolio-details-inner',
  1511.             easing:     'easeOutQuint',
  1512.             timing:     800,
  1513.             transition: 'slide' // 'fade' or 'slide'
  1514.         },
  1515.  
  1516.         options = $.extend({}, defaults, passed_options);
  1517.  
  1518.         return this.each(function()
  1519.         {
  1520.             var container           = $(this),
  1521.                 portfolio_id        = container.data('portfolio-id'),
  1522.                 target_wrap         = $('.portfolio_preview_container[data-portfolio-id="' + portfolio_id + '"]'),
  1523.                 target_container    = target_wrap.find(options.open_in),
  1524.                 items               = container.find('.grid-entry'),
  1525.                 content_retrieved   = {},
  1526.                 is_open             = false,
  1527.                 animating           = false,
  1528.                 index_open          = false,
  1529.                 ajax_call           = false,
  1530.                 methods,
  1531.                 controls,
  1532.                 loader              = $.avia_utilities.loading();
  1533.  
  1534.             methods =
  1535.             {
  1536.                 load_item: function(e)
  1537.                 {
  1538.                     e.preventDefault();
  1539.  
  1540.                     var link            = $(this),
  1541.                         post_container  = link.parents('.post-entry:eq(0)'),
  1542.                         post_id         = "ID_" + post_container.data('ajax-id'),
  1543.                         clickedIndex    = items.index(post_container);
  1544.  
  1545.                     //check if current item is the clicked item or if we are currently animating
  1546.                     if(post_id === is_open || animating == true)
  1547.                     {
  1548.                         return false;
  1549.                     }
  1550.  
  1551.                     animating = true;
  1552.  
  1553.                     container.find('.active_portfolio_item').removeClass('active_portfolio_item');
  1554.                     post_container.addClass('active_portfolio_item');
  1555.                     loader.show();
  1556.  
  1557.                     methods.ajax_get_contents(post_id, clickedIndex);
  1558.                 },
  1559.  
  1560.                 scroll_top: function()
  1561.                 {
  1562.                     setTimeout(function()
  1563.                     {
  1564.                         var target_offset = target_wrap.offset().top - 175,
  1565.                             window_offset = win.scrollTop();
  1566.  
  1567.                         if(window_offset > target_offset || target_offset - window_offset > 100  )
  1568.                         {
  1569.                             $('html:not(:animated),body:not(:animated)').animate({ scrollTop: target_offset }, options.timing, options.easing);
  1570.                         }
  1571.                     },10);
  1572.                 },
  1573.  
  1574.                 attach_item: function(post_id)
  1575.                 {
  1576.                     content_retrieved[post_id] = $(content_retrieved[post_id]).appendTo(target_container);
  1577.                     ajax_call = true;
  1578.                 },
  1579.  
  1580.                 remove_video: function()
  1581.                 {
  1582.                     var del = target_wrap.find('iframe, .avia-video').parents('.ajax_slide:not(.open_slide)');
  1583.  
  1584.                         if(del.length > 0)
  1585.                         {
  1586.                             del.remove();
  1587.                             content_retrieved["ID_" + del.data('slideId')] = undefined;
  1588.                         }
  1589.                 },
  1590.  
  1591.                 show_item: function(post_id, clickedIndex)
  1592.                 {
  1593.  
  1594.                     //check if current item is the clicked item or if we are currently animating
  1595.                     if(post_id === is_open)
  1596.                     {
  1597.                         return false;
  1598.                     }
  1599.                     animating = true;
  1600.  
  1601.  
  1602.                     loader.hide();
  1603.  
  1604.                     if(false === is_open)
  1605.                     {
  1606.                         target_wrap.addClass('open_container');
  1607.                         content_retrieved[post_id].addClass('open_slide');
  1608.  
  1609.                         methods.scroll_top();
  1610.  
  1611.                         target_wrap.css({display:'none'}).slideDown(options.timing, options.easing, function()
  1612.                         {
  1613.                             if(ajax_call)
  1614.                             {
  1615.                                 activate_shortcode_scripts(content_retrieved[post_id]);
  1616.                                 $.avia_utilities.avia_ajax_call(content_retrieved[post_id]);
  1617.                                 the_body.trigger('av_resize_finished');
  1618.                                 ajax_call = false;
  1619.                             }
  1620.  
  1621.                             methods.remove_video();
  1622.                             the_body.trigger('av_resize_finished');
  1623.                         });
  1624.  
  1625.                             index_open  = clickedIndex;
  1626.                             is_open     = post_id;
  1627.                             animating   = false;
  1628.  
  1629.  
  1630.  
  1631.                     }
  1632.                     else
  1633.                     {
  1634.                         methods.scroll_top();
  1635.  
  1636.                         var initCSS = { zIndex:3 },
  1637.                             easing  = options.easing;
  1638.  
  1639.                         if(index_open > clickedIndex) { initCSS.left = '-110%'; }
  1640.                         if(options.transition === 'fade'){ initCSS.left = '0%'; initCSS.opacity = 0; easing = 'easeOutQuad'; }
  1641.  
  1642.                         //fixate height for container during animation
  1643.                         target_container.height(target_container.height()); //outerHeight = border problems?
  1644.  
  1645.                         content_retrieved[post_id].css(initCSS).avia_animate({'left':"0%", opacity:1}, options.timing, easing);
  1646.                         content_retrieved[is_open].avia_animate({opacity:0}, options.timing, easing, function()
  1647.                         {
  1648.                             content_retrieved[is_open].attr({'style':""}).removeClass('open_slide');
  1649.                             content_retrieved[post_id].addClass('open_slide');
  1650.                                                                                                           //+ 2 fixes border problem (slides move up and down 2 px on transition)
  1651.                             target_container.avia_animate({height: content_retrieved[post_id].outerHeight() + 2}, options.timing/2, options.easing, function()
  1652.                             {
  1653.                                 target_container.attr({'style':""});
  1654.                                 is_open     = post_id;
  1655.                                 index_open  = clickedIndex;
  1656.                                 animating   = false;
  1657.  
  1658.                                 methods.remove_video();
  1659.                                 if(ajax_call)
  1660.                                 {
  1661.                                     the_body.trigger('av_resize_finished');
  1662.                                     activate_shortcode_scripts(content_retrieved[post_id]);
  1663.                                     $.avia_utilities.avia_ajax_call(content_retrieved[post_id]);
  1664.                                     ajax_call = false;
  1665.                                 }
  1666.  
  1667.                             });
  1668.  
  1669.                         });
  1670.                     }
  1671.                 },
  1672.  
  1673.                 ajax_get_contents: function(post_id, clickedIndex)
  1674.                 {
  1675.                     if(content_retrieved[post_id] !== undefined)
  1676.                     {
  1677.                         methods.show_item(post_id, clickedIndex);
  1678.                         return;
  1679.                     }
  1680.  
  1681.                     content_retrieved[post_id] = $('#avia-tmpl-portfolio-preview-' + post_id.replace(/ID_/,"")).html();
  1682.  
  1683.                     //this line is necessary to prevent w3 total cache from messing up the portfolio if inline js is compressed
  1684.                     content_retrieved[post_id] = content_retrieved[post_id].replace('/*<![CDATA[*/','').replace('*]]>','');
  1685.  
  1686.                     methods.attach_item(post_id);
  1687.  
  1688.                     $.avia_utilities.preload({container: content_retrieved[post_id] , single_callback:  function(){ methods.show_item(post_id, clickedIndex); }});
  1689.                 },
  1690.  
  1691.                 add_controls: function()
  1692.                 {
  1693.                     controls = target_wrap.find('.ajax_controlls');
  1694.  
  1695.                     target_wrap.avia_keyboard_controls({27:'.avia_close', 37:'.ajax_previous', 39:'.ajax_next'});
  1696.                     //target_wrap.avia_swipe_trigger({prev:'.ajax_previous', next:'.ajax_next'});
  1697.  
  1698.                     items.each(function(){
  1699.  
  1700.                         var current = $(this), overlay;
  1701.  
  1702.                         current.addClass('no_combo').bind('click', function(event)
  1703.                         {
  1704.                             overlay = current.find('.slideshow_overlay');
  1705.  
  1706.                             if(overlay.length)
  1707.                             {
  1708.                                 event.stopPropagation();
  1709.                                 methods.load_item.apply(current.find('a:eq(0)'));
  1710.                                 return false;
  1711.                             }
  1712.                         });
  1713.  
  1714.  
  1715.                     });
  1716.                 },
  1717.  
  1718.                 control_click: function()
  1719.                 {
  1720.                     var showItem,
  1721.                         activeID = container.find('.active_portfolio_item').data('ajax-id'),
  1722.                         active   = container.find('.post-entry-'+activeID);
  1723.  
  1724.                     switch(this.hash)
  1725.                     {
  1726.                         case '#next':
  1727.  
  1728.                             showItem = active.nextAll('.post-entry:visible:eq(0)').find('a:eq(0)');
  1729.                             if(!showItem.length) { showItem = $('.post-entry:visible:eq(0)', container).find('a:eq(0)'); }
  1730.                             showItem.trigger('click');
  1731.  
  1732.                         break;
  1733.                         case '#prev':
  1734.  
  1735.                             showItem = active.prevAll('.post-entry:visible:eq(0)').find('a:eq(0)');
  1736.                             if(!showItem.length) { showItem = $('.post-entry:visible:last', container).find('a:eq(0)'); }
  1737.                             showItem.trigger('click');
  1738.  
  1739.                         break;
  1740.                         case '#close':
  1741.  
  1742.                             animating = true;
  1743.  
  1744.                             target_wrap.slideUp( options.timing, options.easing, function()
  1745.                             {
  1746.                                 container.find('.active_portfolio_item').removeClass('active_portfolio_item');
  1747.                                 content_retrieved[is_open].attr({'style':""}).removeClass('open_slide');
  1748.                                 target_wrap.removeClass('open_container');
  1749.                                 animating = is_open = index_open = false;
  1750.                                 methods.remove_video();
  1751.                                 the_body.trigger('av_resize_finished');
  1752.                             });
  1753.  
  1754.                         break;
  1755.                     }
  1756.                     return false;
  1757.                 },
  1758.  
  1759.  
  1760.                 resize_reset: function()
  1761.                 {
  1762.                     if(is_open === false)
  1763.                     {
  1764.                         target_container.html('');
  1765.                         content_retrieved   = [];
  1766.                     }
  1767.                 }
  1768.             };
  1769.  
  1770.             methods.add_controls();
  1771.  
  1772.             container.on("click", "a", methods.load_item);
  1773.             controls.on("click", "a", methods.control_click);
  1774.             if(jQuery.support.leadingWhitespace) { win.bind('debouncedresize', methods.resize_reset); }
  1775.  
  1776.         });
  1777.     };
  1778. }(jQuery));
  1779.  
  1780.  
  1781.  
  1782. // -------------------------------------------------------------------------------------------
  1783. // Fullscreen Slideshow
  1784. //
  1785. // extends avia slideshow script with a more sophisticated preloader and fixed size for slider
  1786. // -------------------------------------------------------------------------------------------
  1787.  
  1788.  
  1789.     $.AviaFullscreenSlider  =  function(options, slider)
  1790.     {
  1791.         this.$slider    = $( slider );
  1792.         this.$inner     = this.$slider.find('.avia-slideshow-inner');
  1793.         this.$innerLi   = this.$inner.find('>li');
  1794.         this.$caption   = this.$inner.find('.avia-slide-wrap .caption_container');
  1795.         this.$win       = $( window );
  1796.         this.isMobile   = $.avia_utilities.isMobile;
  1797.         this.property   = {};
  1798.         this.scrollPos  = "0";
  1799.         this.transform3d= document.documentElement.className.indexOf('avia_transform3d') !== -1 ? true : false;
  1800.         this.ticking    = false;
  1801.  
  1802.  
  1803.         if($.avia_utilities.supported.transition === undefined)
  1804.         {
  1805.             $.avia_utilities.supported.transition = $.avia_utilities.supports('transition');
  1806.         }
  1807.  
  1808.         this._init( options );
  1809.     }
  1810.  
  1811.     $.AviaFullscreenSlider.defaults  = {
  1812.  
  1813.         //height of the slider in percent
  1814.         height: 100,
  1815.  
  1816.         //subtract elements from the height
  1817.         subtract: '#wpadminbar, #header, #main>.title_container'
  1818.  
  1819.  
  1820.     };
  1821.  
  1822.     $.AviaFullscreenSlider.prototype =
  1823.     {
  1824.         _init: function( options )
  1825.         {
  1826.             var _self = this;
  1827.             //set the default options
  1828.             this.options = $.extend( true, {}, $.AviaFullscreenSlider.defaults, options );
  1829.  
  1830.             if(this.$slider.data('slide_height')) this.options.height = this.$slider.data('slide_height');
  1831.  
  1832.             //if background attachment is set to fixed or scroll disable the parallax effect
  1833.             this.options.parallax_enabled = this.$slider.data('image_attachment') == "" ? true : false;
  1834.  
  1835.             //elements that get subtracted from the image height
  1836.             this.$subtract = $(this.options.subtract);
  1837.  
  1838.  
  1839.             // set the slideshow size
  1840.             this._setSize();
  1841.  
  1842.             // set resizing script on window resize
  1843.             this.$win.on( 'debouncedresize',  $.proxy( this._setSize, this) );
  1844.  
  1845.             //parallax scroll if element if leaving viewport
  1846.             setTimeout(function()
  1847.             {
  1848.                 if(!_self.isMobile && _self.options.parallax_enabled) //disable parallax scrolling on mobile
  1849.                 {
  1850.                     _self.$win.on( 'scroll', $.proxy( _self._on_scroll, _self) );
  1851.                 }
  1852.  
  1853.             },100);
  1854.             /**/
  1855.  
  1856.             //activate the defaule slider
  1857.             this.$slider.aviaSlider({bg_slider:true});
  1858.  
  1859.  
  1860.         },
  1861.  
  1862.         _on_scroll: function(e)
  1863.         {
  1864.             var _self = this;
  1865.  
  1866.             if(!_self.ticking) {
  1867.              _self.ticking = true;
  1868.               window.requestAnimationFrame( $.proxy( _self._parallax_scroll, _self) );
  1869.             }
  1870.         },
  1871.  
  1872.  
  1873.         _fetch_properties: function(slide_height)
  1874.         {
  1875.             this.property.offset    = this.$slider.offset().top;
  1876.             this.property.wh        = this.$win.height();
  1877.             this.property.height    = slide_height || this.$slider.outerHeight();
  1878.  
  1879.             //re-position the slider
  1880.             this._parallax_scroll();
  1881.         },
  1882.  
  1883.         _setSize: function( )
  1884.         {
  1885.             if(!$.fn.avia_browser_height)
  1886.             {
  1887.  
  1888.             var viewport        = this.$win.height(),
  1889.                 slide_height    = Math.ceil( (viewport / 100) * this.options.height );
  1890.  
  1891.             if(this.$subtract.length && this.options.height == 100)
  1892.             {
  1893.                 this.$subtract.each(function()
  1894.                 {
  1895.                     slide_height -= this.offsetHeight - 0.5;
  1896.                 });
  1897.             }
  1898.             else
  1899.             {
  1900.                 slide_height -= 1;
  1901.             }
  1902.             this.$slider.height(slide_height).removeClass('av-default-height-applied');
  1903.             this.$inner.css('padding',0);
  1904.             }
  1905.  
  1906.  
  1907.             this._fetch_properties(slide_height);
  1908.         },
  1909.  
  1910.         _parallax_scroll: function(e)
  1911.         {
  1912.             if(this.isMobile || ! this.options.parallax_enabled) return; //disable parallax scrolling on mobile
  1913.  
  1914.             var winTop      = this.$win.scrollTop(),
  1915.                 winBottom   =  winTop + this.property.wh,
  1916.                 scrollPos   = "0",
  1917.                 prop        = {}, prop2 = {};
  1918.  
  1919.             if(this.property.offset < winTop && winTop <= this.property.offset + this.property.height)
  1920.             {
  1921.                 scrollPos = Math.round( (winTop - this.property.offset) * 0.3 );
  1922.             }
  1923.  
  1924.             if(this.scrollPos != scrollPos)
  1925.             {
  1926.                 //slide background parallax
  1927.                 this.scrollPos = scrollPos;
  1928.  
  1929.                 //currently no 3d transform, because of browser quirks
  1930.                 //this.transform3d = false;
  1931.  
  1932.                 if(this.transform3d)
  1933.                 {
  1934.                     prop[$.avia_utilities.supported.transition+"transform"] = "translate3d(0px,"+ scrollPos +"px,0px)";
  1935.                 }
  1936.                 else
  1937.                 {
  1938.                     prop[$.avia_utilities.supported.transition+"transform"] = "translate(0px,"+ scrollPos +"px)";
  1939.                 }
  1940.  
  1941.  
  1942.                 this.$inner.css(prop);
  1943.  
  1944.  
  1945.  
  1946.                 //slider caption parallax
  1947.  
  1948.                 // prop2[$.avia_utilities.supported.transition+"transform"] = "translate(0px,-"+ ( scrollPos * 1) +"px)";
  1949.                 /*
  1950.                 prop2['opacity'] = Math.ceil((this.$slider.height() - (scrollPos * 2)) / 100)/ 10;
  1951.                 prop2['opacity'] = prop2['opacity'] < 0 ? 0 : prop2['opacity'];
  1952.                 this.$caption.css(prop2);
  1953.                 */
  1954.             }
  1955.  
  1956.             this.ticking = false;
  1957.         }
  1958.     };
  1959.  
  1960.  
  1961.  
  1962. $.fn.aviaFullscreenSlider = function( options )
  1963. {
  1964.     return this.each(function()
  1965.     {
  1966.         var active = $.data( this, 'aviaFullscreenSlider' );
  1967.  
  1968.         if(!active)
  1969.         {
  1970.             //make sure that the function doesnt get aplied a second time
  1971.             $.data( this, 'aviaFullscreenSlider', 1 );
  1972.  
  1973.             //create the preparations for fullscreen slider
  1974.             new $.AviaFullscreenSlider( options, this );
  1975.         }
  1976.     });
  1977. }
  1978.  
  1979. // -------------------------------------------------------------------------------------------
  1980. // makes sure that the fixed container height is removed once the layerslider is loaded, so it adapts to the screen resolution
  1981. // -------------------------------------------------------------------------------------------
  1982.  
  1983.     $.AviaParallaxElement  =  function(options, element)
  1984.     {
  1985.         this.$el        = $( element ).addClass('active-parallax');
  1986.         this.$win       = $( window );
  1987.         this.$body      = $( 'body' );
  1988.         this.$parent    = this.$el.parent();
  1989.         this.property   = {};
  1990.         this.isMobile   = $.avia_utilities.isMobile;
  1991.         this.ratio      = this.$el.data('avia-parallax-ratio') || 0.5;
  1992.         this.transform  = document.documentElement.className.indexOf('avia_transform') !== -1 ? true : false;
  1993.         this.transform3d= document.documentElement.className.indexOf('avia_transform3d') !== -1 ? true : false;
  1994.         this.ticking    = false;
  1995.  
  1996.         if($.avia_utilities.supported.transition === undefined)
  1997.         {
  1998.             $.avia_utilities.supported.transition = $.avia_utilities.supports('transition');
  1999.         }
  2000.  
  2001.         this._init( options );
  2002.     }
  2003.  
  2004.     $.AviaParallaxElement.prototype = {
  2005.  
  2006.         _init: function( options )
  2007.         {
  2008.             var _self = this;
  2009.             if(_self.isMobile)
  2010.             {
  2011.                 return; //disable parallax scrolling on mobile
  2012.             }
  2013.  
  2014.             //fetch window constants
  2015.             setTimeout(function()
  2016.             {
  2017.                 _self._fetch_properties();
  2018.             },30);
  2019.  
  2020.             this.$win.on("debouncedresize av-height-change",  $.proxy( _self._fetch_properties, _self));
  2021.             this.$body.on("av_resize_finished",  $.proxy( _self._fetch_properties, _self));
  2022.  
  2023.  
  2024.  
  2025.             //activate the scrolling
  2026.             setTimeout(function()
  2027.             {
  2028.                 _self.$win.on( 'scroll', $.proxy( _self._on_scroll, _self) );
  2029.  
  2030.             },100);
  2031.         },
  2032.  
  2033.         _fetch_properties: function()
  2034.         {
  2035.             this.property.offset    = this.$parent.offset().top;
  2036.             this.property.wh        = this.$win.height();
  2037.             this.property.height    = this.$parent.outerHeight();
  2038.  
  2039.             //set the height of the element based on the windows height, offset ratio and parent height
  2040.             this.$el.height(Math.ceil((this.property.wh * this.ratio) + this.property.height));
  2041.  
  2042.             //re-position the element
  2043.             this._parallax_scroll();
  2044.         },
  2045.  
  2046.         _on_scroll: function(e)
  2047.         {
  2048.             var _self = this;
  2049.  
  2050.             if(!_self.ticking) {
  2051.              _self.ticking = true;
  2052.               window.requestAnimationFrame( $.proxy( _self._parallax_scroll, _self) );
  2053.             }
  2054.         },
  2055.  
  2056.         _parallax_scroll: function(e)
  2057.         {
  2058.             var winTop      =  this.$win.scrollTop(),
  2059.                 winBottom   =  winTop + this.property.wh,
  2060.                 scrollPos   = "0",
  2061.                 prop = {};
  2062.  
  2063.             //shift element when it moves into viewport
  2064.             if(this.property.offset < winBottom && winTop <= this.property.offset + this.property.height)
  2065.             {
  2066.                 scrollPos = Math.ceil( (winBottom - this.property.offset) * this.ratio );
  2067.  
  2068.                 //parallax movement via backround position change, although
  2069.                 if(this.transform3d)
  2070.                 {
  2071.                     prop[$.avia_utilities.supported.transition+"transform"] = "translate3d(0px,"+ scrollPos +"px, 0px)";
  2072.                 }
  2073.                 else if(this.transform)
  2074.                 {
  2075.                     prop[$.avia_utilities.supported.transition+"transform"] = "translate(0px,"+ scrollPos +"px)";
  2076.                 }
  2077.                 else
  2078.                 {
  2079.                     prop["background-position"] = "0px "+ scrollPos +"px";
  2080.                 }
  2081.  
  2082.                 this.$el.css(prop);
  2083.             }
  2084.  
  2085.             this.ticking = false;
  2086.         }
  2087.     };
  2088.  
  2089.  
  2090. $.fn.avia_parallax = function(options)
  2091. {
  2092.     return this.each(function()
  2093.         {
  2094.             var self = $.data( this, 'aviaParallax' );
  2095.  
  2096.             if(!self)
  2097.             {
  2098.                 self = $.data( this, 'aviaParallax', new $.AviaParallaxElement( options, this ) );
  2099.             }
  2100.         });
  2101. }
  2102.  
  2103.  
  2104. // -------------------------------------------------------------------------------------------
  2105. // Helper to allow fixed bgs on mobile
  2106. // -------------------------------------------------------------------------------------------
  2107.  
  2108. $.fn.avia_mobile_fixed = function(options)
  2109. {
  2110.     var isMobile = $.avia_utilities.isMobile;
  2111.     if(!isMobile) return;
  2112.  
  2113.     return this.each(function()
  2114.     {
  2115.         var current             = $(this).addClass('av-parallax-section'),
  2116.             $background         = current.attr('style'),
  2117.             $attachment_class   = current.data('section-bg-repeat'),
  2118.             template            = "";
  2119.  
  2120.             if($attachment_class == 'stretch' || $attachment_class == 'no-repeat' )
  2121.             {
  2122.                 $attachment_class = " avia-full-stretch";
  2123.             }
  2124.             else
  2125.             {
  2126.                 $attachment_class = "";
  2127.             }
  2128.  
  2129.             template = "<div class='av-parallax " + $attachment_class + "' data-avia-parallax-ratio='0.0' style = '" + $background + "' ></div>";
  2130.  
  2131.             current.prepend(template);
  2132.             current.attr('style','');
  2133.     });
  2134. }
  2135.  
  2136.  
  2137.  
  2138.  
  2139.  
  2140. // -------------------------------------------------------------------------------------------
  2141. // makes sure that the fixed container height is removed once the layerslider is loaded, so it adapts to the screen resolution
  2142. // -------------------------------------------------------------------------------------------
  2143.  
  2144. $.fn.layer_slider_height_helper = function(options)
  2145. {
  2146.     return this.each(function()
  2147.     {
  2148.         var container   = $(this),
  2149.             first_div   = container.find('>div:first'),
  2150.             timeout     = false,
  2151.             counter     = 0,
  2152.             reset_size  = function()
  2153.             {
  2154.                 if(first_div.height() > 0 || counter > 5)
  2155.                 {
  2156.                     container.height('auto');
  2157.                 }
  2158.                 else
  2159.                 {
  2160.                     timeout = setTimeout(reset_size, 500);
  2161.                     counter++;
  2162.                 }
  2163.             };
  2164.  
  2165.         if(!first_div.length) return;
  2166.  
  2167.         timeout = setTimeout(reset_size, 0);
  2168.     });
  2169. }
  2170.  
  2171. // -------------------------------------------------------------------------------------------
  2172. // testimonial shortcode javascript
  2173. // -------------------------------------------------------------------------------------------
  2174.  
  2175. $.fn.avia_sc_testimonial = function(options)
  2176. {
  2177.     return this.each(function()
  2178.     {
  2179.         var container = $(this), elements = container.find('.avia-testimonial');
  2180.  
  2181.  
  2182.         //trigger displaying of thumbnails
  2183.         container.on('avia_start_animation', function()
  2184.         {
  2185.             elements.each(function(i)
  2186.             {
  2187.                 var element = $(this);
  2188.                 setTimeout(function(){ element.addClass('avia_start_animation') }, (i * 150));
  2189.             });
  2190.         });
  2191.     });
  2192. }
  2193.  
  2194.  
  2195. // -------------------------------------------------------------------------------------------
  2196. // Progress bar shortcode javascript
  2197. // -------------------------------------------------------------------------------------------
  2198.  
  2199. $.fn.avia_sc_progressbar = function(options)
  2200. {
  2201.     return this.each(function()
  2202.     {
  2203.         var container = $(this), elements = container.find('.avia-progress-bar');
  2204.  
  2205.  
  2206.         //trigger displaying of progress bar
  2207.         container.on('avia_start_animation', function()
  2208.         {
  2209.             elements.each(function(i)
  2210.             {
  2211.                 var element = $(this)
  2212.  
  2213.                 setTimeout(function()
  2214.                 {
  2215.                     element.find('.progress').addClass('avia_start_animation')
  2216.                     element.find('.progressbar-percent').avia_sc_animated_number(
  2217.                     {
  2218.                         instant_start:true, simple_up:true, start_timer: 10
  2219.                     });
  2220.  
  2221.                 }, (i * 250));
  2222.             });
  2223.         });
  2224.     });
  2225. }
  2226.  
  2227. // -------------------------------------------------------------------------------------------
  2228. // Iconlist shortcode javascript
  2229. // -------------------------------------------------------------------------------------------
  2230.  
  2231. $.fn.avia_sc_iconlist = function(options)
  2232. {
  2233.     return this.each(function()
  2234.     {
  2235.         var iconlist = $(this), elements = iconlist.find('>li');
  2236.  
  2237.  
  2238.         //trigger displaying of thumbnails
  2239.         iconlist.on('avia_start_animation', function()
  2240.         {
  2241.             elements.each(function(i)
  2242.             {
  2243.                 var element = $(this);
  2244.                 setTimeout(function(){ element.addClass('avia_start_animation') }, (i * 350));
  2245.             });
  2246.         });
  2247.     });
  2248. }
  2249.  
  2250.  
  2251. // -------------------------------------------------------------------------------------------
  2252. //  shortcode javascript for delayed animation even when non connected elements are used
  2253. // -------------------------------------------------------------------------------------------
  2254.  
  2255. $.fn.avia_sc_animation_delayed = function(options)
  2256. {
  2257.     var global_timer = 0,
  2258.         delay = options.delay || 50,
  2259.         max_timer = 10,
  2260.         new_max = setTimeout(function(){ max_timer = 20; }, 500);
  2261.  
  2262.     return this.each(function()
  2263.     {
  2264.         var elements = $(this);
  2265.  
  2266.         //trigger displaying of thumbnails
  2267.         elements.on('avia_start_animation', function()
  2268.         {
  2269.             var element = $(this);
  2270.  
  2271.             if(global_timer < max_timer) global_timer ++;
  2272.  
  2273.             setTimeout(function()
  2274.             {
  2275.                 element.addClass('avia_start_delayed_animation');
  2276.                 if(global_timer > 0) global_timer --;
  2277.  
  2278.             }, (global_timer * delay));
  2279.  
  2280.         });
  2281.     });
  2282. }
  2283.  
  2284. /*delayd animations when used within tab sections or similar elements. this way they get animated each new time a tab is shown*/
  2285. $.fn.avia_delayed_animation_in_container = function(options)
  2286. {
  2287.     return this.each(function()
  2288.     {
  2289.         var elements = $(this);
  2290.  
  2291.         elements.on('avia_start_animation_if_current_slide_is_active', function()
  2292.         {
  2293.             var current = $(this),
  2294.                 animate = current.find('.avia_start_animation_when_active');
  2295.  
  2296.                 animate.addClass('avia_start_animation').trigger('avia_start_animation');
  2297.         });
  2298.  
  2299.         elements.on('avia_remove_animation', function()
  2300.         {
  2301.             var current = $(this),
  2302.                 animate = current.find('.avia_start_animation_when_active, .avia_start_animation');
  2303.                 animate.removeClass('avia_start_animation avia_start_delayed_animation');
  2304.         });
  2305.     });
  2306. }
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312. // -------------------------------------------------------------------------------------------
  2313. // Section Height Helper
  2314. // -------------------------------------------------------------------------------------------
  2315.  
  2316. $.fn.avia_browser_height = function()
  2317. {
  2318.     if(!this.length) return;
  2319.  
  2320.     var win         = $(window),
  2321.         html_el     = $('html'),
  2322.         subtract    = $('#wpadminbar, #header.av_header_top:not(.html_header_transparency #header), #main>.title_container'),
  2323.         css_block   = $("<style type='text/css' id='av-browser-height'></style>").appendTo('head:first'),
  2324.         sidebar_menu= $('.html_header_sidebar #top #header_main'),
  2325.         full_slider = $('.html_header_sidebar .avia-fullscreen-slider.avia-builder-el-0.avia-builder-el-no-sibling').addClass('av-solo-full'),
  2326.         calc_height = function()
  2327.         {
  2328.             var css         = "",
  2329.                 wh100       = win.height(),
  2330.                 ww100       = win.width(),
  2331.                 wh100_mod   = wh100,
  2332.                 whCover     = (wh100 / 9) * 16,
  2333.                 wwCover     = (ww100 / 16) * 9,
  2334.                 wh75        = Math.round( wh100 * 0.75 ),
  2335.                 wh50        = Math.round( wh100 * 0.5  ),
  2336.                 wh25        = Math.round( wh100 * 0.25 ),
  2337.                 solo        = 0;
  2338.  
  2339.             if(sidebar_menu.length) solo = sidebar_menu.height();
  2340.  
  2341.             subtract.each(function(){ wh100_mod -= this.offsetHeight - 1; });
  2342.  
  2343.             var whCoverMod  = (wh100_mod / 9) * 16;
  2344.  
  2345.             //fade in of section content with minimum height once the height has been calculated
  2346.             css += ".avia-section.av-minimum-height .container{opacity: 1; }\n";
  2347.  
  2348.             //various section heights (100-25% as well as 100% - header/adminbar in case its the first builder element)
  2349.             css += ".av-minimum-height-100 .container, .avia-fullscreen-slider .avia-slideshow, #top.avia-blank .av-minimum-height-100 .container, .av-cell-min-height-100 > .flex_cell{height:"+wh100+"px;}\n";
  2350.             css += ".av-minimum-height-75 .container, .av-cell-min-height-75 > .flex_cell   {height:"+wh75+"px;}\n";
  2351.             css += ".av-minimum-height-50 .container, .av-cell-min-height-50 > .flex_cell   {height:"+wh50+"px;}\n";
  2352.             css += ".av-minimum-height-25 .container, .av-cell-min-height-25 > .flex_cell   {height:"+wh25+"px;}\n";
  2353.             css += ".avia-builder-el-0.av-minimum-height-100 .container, .avia-builder-el-0.avia-fullscreen-slider .avia-slideshow, .avia-builder-el-0.av-cell-min-height-100 > .flex_cell{height:"+wh100_mod+"px;}\n";
  2354.  
  2355.             css += "#top .av-solo-full .avia-slideshow {min-height:"+solo+"px;}\n";
  2356.  
  2357.             //fullscreen video calculations
  2358.             if(ww100/wh100 < 16/9)
  2359.             {
  2360.                 css += "#top .av-element-cover iframe, #top .av-element-cover embed, #top .av-element-cover object, #top .av-element-cover video{width:"+whCover+"px; left: -"+(whCover - ww100)/2+"px;}\n";
  2361.             }
  2362.             else
  2363.             {
  2364.                 css += "#top .av-element-cover iframe, #top .av-element-cover embed, #top .av-element-cover object, #top .av-element-cover video{height:"+wwCover+"px; top: -"+(wwCover - wh100)/2+"px;}\n";
  2365.             }
  2366.  
  2367.             if(ww100/wh100_mod < 16/9)
  2368.             {
  2369.                 css += "#top .avia-builder-el-0 .av-element-cover iframe, #top .avia-builder-el-0 .av-element-cover embed, #top .avia-builder-el-0 .av-element-cover object, #top .avia-builder-el-0 .av-element-cover video{width:"+whCoverMod+"px; left: -"+(whCoverMod - ww100)/2+"px;}\n";
  2370.             }
  2371.             else
  2372.             {
  2373.                 css += "#top .avia-builder-el-0 .av-element-cover iframe, #top .avia-builder-el-0 .av-element-cover embed, #top .avia-builder-el-0 .av-element-cover object, #top .avia-builder-el-0 .av-element-cover video{height:"+wwCover+"px; top: -"+(wwCover - wh100_mod)/2+"px;}\n";
  2374.             }
  2375.  
  2376.             //ie8 needs different insert method
  2377.             try{
  2378.                 css_block.text(css);
  2379.             }
  2380.             catch(err){
  2381.                 css_block.remove();
  2382.                 css_block = $("<style type='text/css' id='av-browser-height'>"+css+"</style>").appendTo('head:first');
  2383.             }
  2384.  
  2385.  
  2386.             setTimeout(function(){ win.trigger('av-height-change'); /*broadcast the height change*/ },100);
  2387.         };
  2388.  
  2389.     win.on( 'debouncedresize', calc_height);
  2390.     calc_height();
  2391. }
  2392.  
  2393. // -------------------------------------------------------------------------------------------
  2394. // Video Section helper
  2395. // -------------------------------------------------------------------------------------------
  2396.  
  2397. $.fn.avia_video_section = function()
  2398. {
  2399.     if(!this.length) return;
  2400.  
  2401.     var elements    = this.length, content = "",
  2402.         win         = $(window),
  2403.         css_block   = $("<style type='text/css' id='av-section-height'></style>").appendTo('head:first'),
  2404.         calc_height = function(section, counter)
  2405.         {
  2406.             if(counter === 0) { content = "";}
  2407.  
  2408.             var css         = "",
  2409.                 the_id      = '#' +section.attr('id'),
  2410.                 wh100       = section.height(),
  2411.                 ww100       = section.width(),
  2412.                 aspect      = section.data('sectionVideoRatio').split(':'),
  2413.                 video_w     = aspect[0],
  2414.                 video_h     = aspect[1],
  2415.                 whCover     = (wh100 / video_h ) * video_w,
  2416.                 wwCover     = (ww100 / video_w ) * video_h;
  2417.  
  2418.             //fullscreen video calculations
  2419.             if(ww100/wh100 < video_w/video_h)
  2420.             {
  2421.                 css += "#top "+the_id+" .av-section-video-bg iframe, #top "+the_id+" .av-section-video-bg embed, #top "+the_id+" .av-section-video-bg object, #top "+the_id+" .av-section-video-bg video{width:"+whCover+"px; left: -"+(whCover - ww100)/2+"px;}\n";
  2422.             }
  2423.             else
  2424.             {
  2425.                 css += "#top "+the_id+" .av-section-video-bg iframe, #top "+the_id+" .av-section-video-bg embed, #top "+the_id+" .av-section-video-bg object, #top "+the_id+" .av-section-video-bg video{height:"+wwCover+"px; top: -"+(wwCover - wh100)/2+"px;}\n";
  2426.             }
  2427.  
  2428.             content = content + css;
  2429.  
  2430.             if(elements == counter + 1)
  2431.             {
  2432.                 //ie8 needs different insert method
  2433.                 try{
  2434.                     css_block.text(content);
  2435.                 }
  2436.                 catch(err){
  2437.                     css_block.remove();
  2438.                     css_block = $("<style type='text/css' id='av-section-height'>"+content+"</style>").appendTo('head:first');
  2439.                 }
  2440.             }
  2441.         };
  2442.  
  2443.  
  2444.     return this.each(function(i)
  2445.     {
  2446.         var self = $(this);
  2447.  
  2448.         win.on( 'debouncedresize', function(){ calc_height(self, i); });
  2449.         calc_height(self, i);
  2450.     });
  2451.  
  2452. }
  2453.  
  2454.  
  2455.  
  2456.  
  2457.  
  2458.  
  2459.  
  2460.  
  2461. // -------------------------------------------------------------------------------------------
  2462. // Gallery shortcode javascript
  2463. // -------------------------------------------------------------------------------------------
  2464.  
  2465. $.fn.avia_sc_gallery = function(options)
  2466. {
  2467.     return this.each(function()
  2468.     {
  2469.         var gallery = $(this), images = gallery.find('img'), big_prev = gallery.find('.avia-gallery-big');
  2470.  
  2471.  
  2472.         //trigger displaying of thumbnails
  2473.         gallery.on('avia_start_animation', function()
  2474.         {
  2475.             images.each(function(i)
  2476.             {
  2477.                 var image = $(this);
  2478.                 setTimeout(function(){ image.addClass('avia_start_animation') }, (i * 110));
  2479.             });
  2480.         });
  2481.  
  2482.         if(gallery.hasClass('deactivate_avia_lazyload')) gallery.trigger('avia_start_animation');
  2483.  
  2484.         //trigger thumbnail hover and big prev image change
  2485.         if(big_prev.length)
  2486.         {
  2487.             gallery.on('mouseenter','.avia-gallery-thumb a', function()
  2488.             {
  2489.                 var _self = this;
  2490.  
  2491.                 big_prev.attr('data-onclick', _self.getAttribute("data-onclick"));
  2492.                 big_prev.height(big_prev.height());
  2493.                 big_prev.attr('href', _self.href)
  2494.  
  2495.                 var newImg      = _self.getAttribute("data-prev-img"),
  2496.                     oldImg      = big_prev.find('img'),
  2497.                     oldImgSrc   = oldImg.attr('src');
  2498.  
  2499.                 if(newImg != oldImgSrc)
  2500.                 {
  2501.                     var next_img = new Image();
  2502.                     next_img.src = newImg;
  2503.  
  2504.                     var $next = $(next_img);
  2505.  
  2506.                     if(big_prev.hasClass('avia-gallery-big-no-crop-thumb'))
  2507.                     {
  2508.                         $next.css({'height':big_prev.height(),'width':'auto'});
  2509.                     }
  2510.  
  2511.                     big_prev.stop().animate({opacity:0}, function()
  2512.                     {
  2513.                         $next.insertAfter(oldImg);
  2514.                         oldImg.remove();
  2515.                         big_prev.animate({opacity:1});
  2516.  
  2517.                         big_prev.attr('title',$(_self).attr('title'));
  2518.  
  2519.                     });
  2520.                 }
  2521.             });
  2522.  
  2523.             big_prev.on('click', function()
  2524.             {
  2525.                 var imagelink = gallery.find('.avia-gallery-thumb a').eq(this.getAttribute("data-onclick") - 1);
  2526.  
  2527.                 if(imagelink && !imagelink.hasClass('aviaopeninbrowser'))
  2528.                 {
  2529.                     imagelink.trigger('click');
  2530.                 }
  2531.                 else if(imagelink)
  2532.                 {
  2533.                     var imgurl = imagelink.attr("href");
  2534.  
  2535.                     if(imagelink.hasClass('aviablank') && imgurl != '' )
  2536.                     {
  2537.                         window.open(imgurl, '_blank');
  2538.                     }
  2539.                     else if( imgurl != '' )
  2540.                     {
  2541.                         window.open(imgurl, '_self');
  2542.                     }
  2543.                 }
  2544.                 return false;
  2545.             });
  2546.  
  2547.  
  2548.             $(window).on("debouncedresize", function()
  2549.             {
  2550.                 big_prev.height('auto');
  2551.             });
  2552.  
  2553.         }
  2554.     });
  2555. }
  2556.  
  2557. // -------------------------------------------------------------------------------------------
  2558. // Toggle shortcode javascript
  2559. // -------------------------------------------------------------------------------------------
  2560.  
  2561. $.fn.avia_sc_toggle = function(options)
  2562. {
  2563.     var defaults =
  2564.     {
  2565.         single: '.single_toggle',
  2566.         heading: '.toggler',
  2567.         content: '.toggle_wrap',
  2568.         sortContainer:'.taglist'
  2569.     };
  2570.  
  2571.     var win = $(window),
  2572.         options = $.extend(defaults, options);
  2573.  
  2574.     return this.each(function()
  2575.     {
  2576.         var container   = $(this).addClass('enable_toggles'),
  2577.             toggles     = $(options.single, container),
  2578.             heading     = $(options.heading, container),
  2579.             allContent  = $(options.content, container),
  2580.             sortLinks   = $(options.sortContainer + " a", container);
  2581.  
  2582.         heading.each(function(i)
  2583.         {
  2584.             var thisheading =  $(this), content = thisheading.next(options.content, container);
  2585.  
  2586.             function scroll_to_viewport()
  2587.             {
  2588.                 //check if toggle title is in viewport. if not scroll up
  2589.                 var el_offset = content.offset().top,
  2590.                     scoll_target = el_offset - 50 - parseInt($('html').css('margin-top'),10);
  2591.  
  2592.                 if(win.scrollTop() > el_offset)
  2593.                 {
  2594.                     $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target},200);
  2595.                 }
  2596.             }
  2597.  
  2598.             if(content.css('visibility') != "hidden")
  2599.             {
  2600.                 thisheading.addClass('activeTitle');
  2601.             }
  2602.  
  2603.             thisheading.on('click', function()
  2604.             {
  2605.                 if(content.css('visibility') != "hidden")
  2606.                 {
  2607.                     content.slideUp(200, function()
  2608.                     {
  2609.                         content.removeClass('active_tc').attr({style:''});
  2610.                         win.trigger('av-height-change');
  2611.                     });
  2612.                     thisheading.removeClass('activeTitle');
  2613.  
  2614.                 }
  2615.                 else
  2616.                 {
  2617.                     if(container.is('.toggle_close_all'))
  2618.                     {
  2619.                         allContent.not(content).slideUp(200, function()
  2620.                         {
  2621.                             $(this).removeClass('active_tc').attr({style:''});
  2622.                             scroll_to_viewport();
  2623.                         });
  2624.                         heading.removeClass('activeTitle');
  2625.                     }
  2626.                     content.addClass('active_tc').slideDown(200,
  2627.  
  2628.                     function()
  2629.                     {
  2630.                         if(!container.is('.toggle_close_all'))
  2631.                         {
  2632.                             scroll_to_viewport();
  2633.                         }
  2634.  
  2635.                         win.trigger('av-height-change');
  2636.                     }
  2637.  
  2638.                     );
  2639.                     thisheading.addClass('activeTitle');
  2640.                     location.replace(thisheading.data('fake-id'));
  2641.                 }
  2642.  
  2643.  
  2644.  
  2645.             });
  2646.         });
  2647.  
  2648.  
  2649.         sortLinks.click(function(e){
  2650.  
  2651.             e.preventDefault();
  2652.             var show = toggles.filter('[data-tags~="'+$(this).data('tag')+'"]'),
  2653.                 hide = toggles.not('[data-tags~="'+$(this).data('tag')+'"]');
  2654.  
  2655.                 sortLinks.removeClass('activeFilter');
  2656.                 $(this).addClass('activeFilter');
  2657.                 heading.filter('.activeTitle').trigger('click');
  2658.                 show.slideDown();
  2659.                 hide.slideUp();
  2660.         });
  2661.  
  2662.  
  2663.         function trigger_default_open(hash)
  2664.         {
  2665.             if(!hash && window.location.hash) hash = window.location.hash;
  2666.             if(!hash) return;
  2667.  
  2668.             var open = heading.filter('[data-fake-id="'+hash+'"]');
  2669.  
  2670.             if(open.length)
  2671.             {
  2672.                 if(!open.is('.activeTitle')) open.trigger('click');
  2673.                 window.scrollTo(0, container.offset().top - 70);
  2674.             }
  2675.         }
  2676.         trigger_default_open(false);
  2677.  
  2678.         $('a').on('click',function(){
  2679.             var hash = $(this).attr('href');
  2680.             if(typeof hash != "undefined" && hash)
  2681.             {
  2682.                 hash = hash.replace(/^.*?#/,'');
  2683.                 trigger_default_open('#'+hash);
  2684.             }
  2685.         });
  2686.  
  2687.     });
  2688. };
  2689.  
  2690.  
  2691.  
  2692.  
  2693. // -------------------------------------------------------------------------------------------
  2694. // Tab Shortcode
  2695. // -------------------------------------------------------------------------------------------
  2696.  
  2697. $.fn.avia_sc_tabs= function(options)
  2698. {
  2699.     var defaults =
  2700.     {
  2701.         heading: '.tab',
  2702.         content:'.tab_content',
  2703.         active:'active_tab',
  2704.         sidebar: false
  2705.     };
  2706.  
  2707.     var win = $(window),
  2708.         options = $.extend(defaults, options);
  2709.  
  2710.     return this.each(function()
  2711.     {
  2712.         var container   = $(this),
  2713.             tab_titles  = $('<div class="tab_titles"></div>').prependTo(container),
  2714.             tabs        = $(options.heading, container),
  2715.             content     = $(options.content, container),
  2716.             newtabs     = false,
  2717.             oldtabs     = false;
  2718.  
  2719.         newtabs = tabs.clone();
  2720.         oldtabs = tabs.addClass('fullsize-tab');
  2721.         tabs = newtabs;
  2722.  
  2723.         tabs.prependTo(tab_titles).each(function(i)
  2724.         {
  2725.             var tab = $(this), the_oldtab = false;
  2726.  
  2727.             if(newtabs) the_oldtab = oldtabs.filter(':eq('+i+')');
  2728.  
  2729.             tab.addClass('tab_counter_'+i).bind('click', function()
  2730.             {
  2731.                 open_content(tab, i, the_oldtab);
  2732.                 return false;
  2733.             });
  2734.  
  2735.             if(newtabs)
  2736.             {
  2737.                 the_oldtab.bind('click', function()
  2738.                 {
  2739.                     open_content(the_oldtab, i, tab);
  2740.                     return false;
  2741.                 });
  2742.             }
  2743.         });
  2744.  
  2745.         set_size();
  2746.         trigger_default_open(false);
  2747.         win.on("debouncedresize", set_size);
  2748.  
  2749.         $('a').on('click',function(){
  2750.             var hash = $(this).attr('href');
  2751.             if(typeof hash != "undefined" && hash)
  2752.             {
  2753.                 hash = hash.replace(/^.*?#/,'');
  2754.                 trigger_default_open('#'+hash);
  2755.             }
  2756.         });
  2757.  
  2758.         function set_size()
  2759.         {
  2760.             if(!options.sidebar) return;
  2761.             content.css({'min-height': tab_titles.outerHeight() + 1});
  2762.         }
  2763.  
  2764.         function open_content(tab, i, alternate_tab)
  2765.         {
  2766.             if(!tab.is('.'+options.active))
  2767.             {
  2768.                 $('.'+options.active, container).removeClass(options.active);
  2769.                 $('.'+options.active+'_content', container).removeClass(options.active+'_content');
  2770.  
  2771.                 tab.addClass(options.active);
  2772.  
  2773.                 var new_loc = tab.data('fake-id');
  2774.                 if(typeof new_loc == 'string') location.replace(new_loc);
  2775.  
  2776.                 if(alternate_tab) alternate_tab.addClass(options.active);
  2777.                 var active_c = content.filter(':eq('+i+')').addClass(options.active+'_content');
  2778.  
  2779.                 if(typeof click_container != 'undefined' && click_container.length)
  2780.                 {
  2781.                     sidebar_shadow.height(active_c.outerHeight());
  2782.                 }
  2783.  
  2784.                 //check if tab title is in viewport. if not scroll up
  2785.                 var el_offset = active_c.offset().top,
  2786.                     scoll_target = el_offset - 50 - parseInt($('html').css('margin-top'),10);
  2787.  
  2788.                 if(win.scrollTop() > el_offset)
  2789.                 {
  2790.                     $('html:not(:animated),body:not(:animated)').scrollTop(scoll_target);
  2791.                 }
  2792.             }
  2793.         }
  2794.  
  2795.         function trigger_default_open(hash)
  2796.         {
  2797.             if(!hash && window.location.hash) hash = window.location.hash;
  2798.                     if(!hash) return;
  2799.  
  2800.             var open = tabs.filter('[data-fake-id="'+hash+'"]');
  2801.  
  2802.             if(open.length)
  2803.             {
  2804.                 if(!open.is('.active_tab')) open.trigger('click');
  2805.                 window.scrollTo(0, container.offset().top - 70);
  2806.             }
  2807.         }
  2808.  
  2809.     });
  2810. };
  2811.  
  2812.  
  2813.  
  2814.  
  2815. // -------------------------------------------------------------------------------------------
  2816. // Tab Section
  2817. // -------------------------------------------------------------------------------------------
  2818.  
  2819. $.fn.avia_sc_tab_section= function()
  2820. {
  2821.     var win             = $(window),
  2822.         browserPrefix   = $.avia_utilities.supports('transition'),
  2823.         cssActive       = this.browserPrefix !== false ? true : false,
  2824.         isMobile        = $.avia_utilities.isMobile,
  2825.         transform3d     = document.documentElement.className.indexOf('avia_transform3d') !== -1 ? true : false,
  2826.         transition      = {};
  2827.  
  2828.     return this.each(function()
  2829.     {
  2830.         var container       = $(this),
  2831.             tabs            = container.find('.av-section-tab-title'),
  2832.             tab_wrap        = container.find('.av-tab-section-tab-title-container'),
  2833.             tab_nav         = container.find('.av_tab_navigation'),
  2834.             content_wrap    = container.find('.av-tab-section-inner-container'),
  2835.             single_tabs     = container.find('.av-animation-delay-container'), //for elements inside the tab that receive waypoint animation
  2836.             inner_content   = container.find('.av-layout-tab-inner'),
  2837.             sliding_active  = container.is('.av-tab-slide-transition'),
  2838.             flexible        = container.is('.av-tab-content-auto'),
  2839.             current_content = container.find('.__av_init_open'),
  2840.             min_width       = 0,
  2841.             change_tab      = function(e, prevent_hash)
  2842.             {
  2843.                 e.preventDefault();
  2844.  
  2845.                 var current_tab     = $(e.currentTarget),
  2846.                     current_arrow   = current_tab.find('.av-tab-arrow-container span'),
  2847.                     tab_nr          = current_tab.data('av-tab-section-title');
  2848.  
  2849.                     current_content = container.find('[data-av-tab-section-content="'+tab_nr+'"]');
  2850.  
  2851.                 var new_bg          = current_content.data('av-tab-bg-color'),
  2852.                     new_font        = current_content.data('av-tab-color'),
  2853.                     prev_container  = container.find('.av-active-tab-content').not('[data-av-tab-section-content="'+tab_nr+'"]');
  2854.  
  2855.                 tabs.attr('style','').removeClass('av-active-tab-title');
  2856.                 current_tab.addClass('av-active-tab-title');
  2857.                 current_content.addClass("av-active-tab-content");
  2858.  
  2859.                 if(new_bg !== "") current_arrow.css('background-color', new_bg);
  2860.                 if(new_font !== "") current_tab.css('color', new_font);
  2861.  
  2862.                 var new_pos = ((parseInt(tab_nr,10) - 1) * -100 );
  2863.                     if ($('body').hasClass('rtl')) {
  2864.                         new_pos = ((parseInt(tab_nr,10) - 1) * 100 );
  2865.                         }
  2866.  
  2867.                 if(cssActive)
  2868.                 {
  2869.                     //move the slides
  2870.                     new_pos = new_pos / tabs.length;
  2871.                     transition['transform']  = transform3d ? "translate3d(" + new_pos  + "%, 0, 0)" : "translate(" + new_pos + "%,0)"; //3d or 2d transform?
  2872.                     transition['left'] = "0%";
  2873.                     content_wrap.css(transition);
  2874.                 }
  2875.                 else
  2876.                 {
  2877.                     content_wrap.css('left',  new_pos + "%");
  2878.                 }
  2879.  
  2880.                 set_tab_titlte_pos();
  2881.                 set_slide_height();
  2882.  
  2883.                 if(!prevent_hash) location.hash = current_tab.attr('href');
  2884.  
  2885.                 setTimeout(function()
  2886.                 {
  2887.                     current_content.trigger('avia_start_animation_if_current_slide_is_active');
  2888.                     single_tabs.not(current_content).trigger('avia_remove_animation');
  2889.  
  2890.                 }, 600);
  2891.  
  2892.             },
  2893.             set_min_width = function()
  2894.             {
  2895.                 min_width = 0;
  2896.                 tabs.each(function()
  2897.                 {
  2898.                     min_width += $(this).outerWidth();
  2899.                 });
  2900.  
  2901.                 tab_wrap.css('min-width',min_width);
  2902.             },
  2903.  
  2904.             set_slide_height = function()
  2905.             {
  2906.                 if(current_content.length && flexible)
  2907.                 {
  2908.                     var old_height = inner_content.height();
  2909.                     inner_content.height('auto');
  2910.  
  2911.                     var height = current_content.find('.av-layout-tab-inner').height();
  2912.                     inner_content.height(old_height);
  2913.                     inner_content.height(height);
  2914.  
  2915.                     setTimeout(function() { win.trigger('av-height-change'); }, 600);
  2916.                 }
  2917.             },
  2918.  
  2919.             set_tab_titlte_pos = function()
  2920.             {
  2921.                 //scroll the tabs if there is not enough room to display them all
  2922.                 var current_tab = container.find('.av-active-tab-title'),
  2923.                     viewport    = container.width(),
  2924.                     left_pos    = viewport < min_width ? (current_tab.position().left * - 1) - (current_tab.outerWidth() / 2) + (viewport / 2): 0;
  2925.  
  2926.                 if(left_pos + min_width < viewport) left_pos = (min_width - viewport) * -1;
  2927.                 if(left_pos > 0) left_pos = 0;
  2928.  
  2929.                 tab_wrap.css('left',left_pos );
  2930.             },
  2931.             switch_to_next_prev = function(e)
  2932.             {
  2933.                 if(!isMobile) return;
  2934.  
  2935.                 var clicked         = $(e.currentTarget),
  2936.                     current_tab     = container.find('.av-active-tab-title');
  2937.  
  2938.                     if(clicked.is('.av_prev_tab_section'))
  2939.                     {
  2940.                         current_tab.prev('.av-section-tab-title').trigger('click');
  2941.                     }
  2942.                     else
  2943.                     {
  2944.                         current_tab.next('.av-section-tab-title').trigger('click');
  2945.                     }
  2946.             },
  2947.  
  2948.             get_init_open = function()
  2949.             {
  2950.                 if(!hash && window.location.hash) var hash = window.location.hash;
  2951.  
  2952.                 var open = tabs.filter('[href="'+hash+'"]');
  2953.  
  2954.                 if(open.length)
  2955.                 {
  2956.                     if(!open.is('.active_tab')) open.trigger('click');
  2957.                 }
  2958.                 else
  2959.                 {
  2960.                     //set correct color
  2961.                     container.find('.av-active-tab-title').trigger('click', true);
  2962.                 }
  2963.             };
  2964.  
  2965.         $.avia_utilities.preload({
  2966.  
  2967.             container: current_content ,
  2968.             single_callback:  function(){
  2969.  
  2970.                 tabs.on('click', change_tab);
  2971.                 tab_nav.on('click', switch_to_next_prev);
  2972.                 win.on('debouncedresize', set_tab_titlte_pos);
  2973.                 win.on('debouncedresize', set_slide_height);
  2974.  
  2975.                 set_min_width();
  2976.                 set_slide_height();
  2977.                 get_init_open();
  2978.             }
  2979.  
  2980.         });
  2981.  
  2982.  
  2983.  
  2984.         //force a click on page load to properly set the tab color
  2985.         container.find('.av-active-tab-title').trigger('click');
  2986.  
  2987.         content_wrap.avia_swipe_trigger({prev:'.av_prev_tab_section', next:'.av_next_tab_section'});
  2988.  
  2989.     });
  2990. };
  2991.  
  2992.  
  2993.  
  2994.  
  2995. // -------------------------------------------------------------------------------------------
  2996. // Horizontal Gallery
  2997. // -------------------------------------------------------------------------------------------
  2998.  
  2999. $.fn.avia_hor_gallery= function(options)
  3000. {
  3001.     var defaults =
  3002.         {
  3003.             slide_container : '.av-horizontal-gallery-inner', //element with max width
  3004.             slide_element   : '.av-horizontal-gallery-slider', //element that gets moved
  3005.             slide_content   : '.av-horizontal-gallery-wrap',
  3006.             active          : 'av-active-gal-item',             // must be a class string without the . in front
  3007.             prev            : '.av-horizontal-gallery-prev',
  3008.             next            : '.av-horizontal-gallery-next'
  3009.         };
  3010.  
  3011.     var options = $.extend(defaults, options);
  3012.  
  3013.     var win             = $(window),
  3014.         browserPrefix   = $.avia_utilities.supports('transition'),
  3015.         cssActive       = this.browserPrefix !== false ? true : false,
  3016.         isMobile        = $.avia_utilities.isMobile,
  3017.         transform3d     = document.documentElement.className.indexOf('avia_transform3d') !== -1 ? true : false,
  3018.         transition      = {};
  3019.  
  3020.     return this.each(function()
  3021.     {
  3022.         var container           = $(this),
  3023.             slide_container     = container.find(options.slide_container),
  3024.             slide_element       = container.find(options.slide_element),
  3025.             slide_content       = container.find(options.slide_content),
  3026.             prev                = container.find(options.prev),
  3027.             next                = container.find(options.next),
  3028.             imgs                = container.find('img'),
  3029.  
  3030.             all_elements_width  = 0,
  3031.             currentIndex        = false,
  3032.             initial             = container.data('av-initial'),
  3033.  
  3034.             set_up = function( init )
  3035.             {
  3036.                 var sl_height = (slide_container.width() / 100 ) * slide_container.data('av-height');
  3037.  
  3038.                 slide_container.css({'padding':0}).height(sl_height);
  3039.  
  3040.                 //fixes img distortion when resizing browser:
  3041.                 imgs.css('display','inline-block');
  3042.                 setTimeout(function(){ imgs.css('display','block'); }, 10);
  3043.  
  3044.                 //calculate the slidelement width based on the elements inside
  3045.                 all_elements_width = 0;
  3046.  
  3047.                 slide_content.each(function()
  3048.                 {
  3049.                     all_elements_width += $(this).outerWidth( true );
  3050.                 });
  3051.  
  3052.                 slide_element.css( 'min-width' , all_elements_width );
  3053.  
  3054.                 if(currentIndex !== false )
  3055.                 {
  3056.                     change_active(currentIndex);
  3057.                 }
  3058.             },
  3059.             change_active = function(index)
  3060.             {
  3061.                 //scroll the tabs if there is not enough room to display them all
  3062.                 var current     = slide_element.find(options.slide_content).eq(index),
  3063.                     viewport    = slide_container.width(),
  3064.                     modifier    = container.data('av-enlarge') > 1  && currentIndex == index ? container.data('av-enlarge') : 1,
  3065.                     outerWidth  = current.outerWidth( true ) * modifier,
  3066.                     margin_right= parseInt( current.css('margin-right') , 10 ) / 2,
  3067.                     left_pos    = viewport < all_elements_width ? (current.position().left * - 1) - (outerWidth / 2) + (viewport / 2): 0;
  3068.  
  3069.                 //center properly
  3070.                 left_pos = left_pos + margin_right;
  3071.  
  3072.                 //out of bounce right side
  3073.                 if(left_pos + all_elements_width < viewport) left_pos = (all_elements_width - viewport - parseInt(current.css('margin-right'),10) ) * -1;
  3074.  
  3075.                 //out of bounce left side
  3076.                 if(left_pos > 0) left_pos = 0;
  3077.  
  3078.                 //set pos
  3079.                 slide_element.css('left',left_pos );
  3080.  
  3081.                 slide_container.find("." +options.active).removeClass(options.active);
  3082.                 current.addClass(options.active);
  3083.                 currentIndex = index;
  3084.  
  3085.             };
  3086.  
  3087.  
  3088.          $.avia_utilities.preload({container: container , global_callback:  function()
  3089.          {
  3090.              // activate behavior
  3091.             set_up( 'init' );
  3092.             win.on('debouncedresize', set_up);
  3093.             if(initial) change_active(initial - 1);
  3094.  
  3095.             setTimeout(function(){
  3096.                 container.addClass('av-horizontal-gallery-animated');
  3097.             },10);
  3098.  
  3099.           }});
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.         //swipe on mobile
  3108.         slide_element.avia_swipe_trigger({prev:options.prev, next:options.next});
  3109.  
  3110.         //element click
  3111.         slide_content.on('click', function(e)
  3112.         {
  3113.             var current = $(this);
  3114.             var index = slide_content.index(current);
  3115.  
  3116.             if(currentIndex === index)
  3117.             {
  3118.                 if(container.data('av-enlarge') > 1 && !$(e.target).is('a') )
  3119.                 {
  3120.                     //slide_container.find("." +options.active).removeClass(options.active);
  3121.                     //currentIndex = false;
  3122.                 }
  3123.                 return;
  3124.             }
  3125.  
  3126.             change_active(index);
  3127.         });
  3128.  
  3129.         prev.on('click', function(e)
  3130.         {
  3131.             if(currentIndex === false) currentIndex = 1;
  3132.             var index = currentIndex - 1;
  3133.             if(index < 0) index = 0;
  3134.  
  3135.             change_active(index);
  3136.         });
  3137.  
  3138.         next.on('click', function(e)
  3139.         {
  3140.             if(currentIndex === false) currentIndex = -1;
  3141.             var index = currentIndex + 1;
  3142.             if(index > slide_content.length - 1) index = slide_content.length - 1;
  3143.  
  3144.             change_active(index);
  3145.         });
  3146.  
  3147.         //if its a desktop browser add arrow navigation, otherwise add touch nav
  3148.         if(!isMobile)
  3149.         {
  3150.             container.avia_keyboard_controls({ 37: options.prev, 39: options.next });
  3151.         }
  3152.         else
  3153.         {
  3154.             container.avia_swipe_trigger({next: options.next, prev: options.prev});
  3155.         }
  3156.  
  3157.  
  3158.  
  3159.     });
  3160. };
  3161.  
  3162. // -------------------------------------------------------------------------------------------
  3163. // Big Number animation shortcode javascript
  3164. // -------------------------------------------------------------------------------------------
  3165.  
  3166. (function($)
  3167. {
  3168.     // options.simple_up = dont prepend leading zeros, options.instant_start = trigger counting instantly, options.start_timer = delay when to start counting
  3169.     $.fn.avia_sc_animated_number = function(options)
  3170.     {
  3171.         if(!this.length) return;
  3172.         if(this.is('.avia_sc_animated_number_active')) return;
  3173.  
  3174.         this.addClass('avia_sc_animated_number_active');
  3175.  
  3176.         var skipStep = false,
  3177.             simple_upcount  = (options && options.simple_up) ? true : false,
  3178.             start_timer     = (options && options.start_timer) ? options.start_timer : 300,
  3179.         start_count = function(element, countTo, increment, current, fakeCountTo)
  3180.         {
  3181.  
  3182.  
  3183.             //calculate the new number
  3184.             var newCount = current + increment;
  3185.  
  3186.             //if the number is bigger than our final number set the number and finish
  3187.             if(newCount >= fakeCountTo)
  3188.             {
  3189.                 element.text(countTo); //exit
  3190.  
  3191.             }
  3192.             else
  3193.             {
  3194.                 var prepend = "", addZeros = countTo.toString().length - newCount.toString().length
  3195.  
  3196.                 //if the number has less digits than the final number some zeros where omitted. add them to the front
  3197.                 for(var i = addZeros; i > 0; i--){ prepend += "0"; }
  3198.  
  3199.                 if(simple_upcount) prepend = 0;
  3200.                 element.text(prepend + newCount);
  3201.  
  3202.                 window.requestAnimationFrame(function(){ start_count(element, countTo, increment, newCount, fakeCountTo) });
  3203.             }
  3204.         };
  3205.  
  3206.         return this.each(function()
  3207.         {
  3208.             var number_container = $(this), elements = number_container.find('.__av-single-number'), countTimer = number_container.data('timer') || 3000;
  3209.  
  3210.             //prepare elements
  3211.             elements.each(function(i)
  3212.             {
  3213.                 var element = $(this), text = element.text();
  3214.                 if(window.addEventListener) element.text( text.replace(/./g, "0")); /*https://github.com/AviaThemes/wp-themes/issues/812*/
  3215.             });
  3216.  
  3217.             //trigger number animation
  3218.             number_container.addClass('number_prepared').on('avia_start_animation', function()
  3219.             {
  3220.                 if(number_container.is('.avia_animation_done')) return;
  3221.                 number_container.addClass('avia_animation_done');
  3222.  
  3223.                 elements.each(function(i)
  3224.                 {
  3225.                     var element = $(this), countTo = element.data('number'), fakeCountTo = countTo, current = parseInt(element.text(),10), zeroOnly = /^0+$/.test(countTo), increment = 0;
  3226.  
  3227.                     //fallback for decimals like 00 or 000
  3228.                     if(zeroOnly && countTo !== 0) fakeCountTo = countTo.replace(/0/g, '9');
  3229.  
  3230.                     increment = Math.round( fakeCountTo * 32 / countTimer);
  3231.                     if(increment == 0 || increment % 10 == 0) increment += 1;
  3232.  
  3233.                     setTimeout(function(){ start_count(element, countTo, increment, current, fakeCountTo);}, start_timer);
  3234.                 });
  3235.             });
  3236.  
  3237.             if(options && options.instant_start == true)
  3238.             {
  3239.                 number_container.trigger('avia_start_animation');
  3240.             }
  3241.  
  3242.  
  3243.         });
  3244.     }
  3245. })(jQuery);
  3246.  
  3247.  
  3248.  
  3249.  
  3250. // -------------------------------------------------------------------------------------------
  3251. // contact form ajax
  3252. // -------------------------------------------------------------------------------------------
  3253.  
  3254. (function($)
  3255. {
  3256.     $.fn.avia_ajax_form = function(variables)
  3257.     {
  3258.         var defaults =
  3259.         {
  3260.             sendPath: 'send.php',
  3261.             responseContainer: '.ajaxresponse'
  3262.         };
  3263.  
  3264.         var options = $.extend(defaults, variables);
  3265.  
  3266.         return this.each(function()
  3267.         {
  3268.             var form = $(this),
  3269.                 form_sent = false,
  3270.                 send =
  3271.                 {
  3272.                     formElements: form.find('textarea, select, input[type=text], input[type=checkbox], input[type=hidden]'),
  3273.                     validationError:false,
  3274.                     button : form.find('input:submit'),
  3275.                     dataObj : {}
  3276.                 },
  3277.  
  3278.                 responseContainer = form.next(options.responseContainer+":eq(0)");
  3279.  
  3280.                 send.button.bind('click', checkElements);
  3281.  
  3282.  
  3283.                 //change type of email forms on mobile so the e-mail keyboard with @ sign is used
  3284.                 if($.avia_utilities.isMobile)
  3285.                 {
  3286.                     send.formElements.each(function(i)
  3287.                     {
  3288.                         var currentElement = $(this), is_email = currentElement.hasClass('is_email');
  3289.                         if(is_email) currentElement.attr('type','email');
  3290.                     });
  3291.                 }
  3292.  
  3293.  
  3294.             function checkElements( e )
  3295.             {
  3296.                 // reset validation var and send data
  3297.                 send.validationError = false;
  3298.                 send.datastring = 'ajax=true';
  3299.  
  3300.                 send.formElements.each(function(i)
  3301.                 {
  3302.                     var currentElement = $(this),
  3303.                         surroundingElement = currentElement.parent(),
  3304.                         value = currentElement.val(),
  3305.                         name = currentElement.attr('name'),
  3306.                         classes = currentElement.attr('class'),
  3307.                         nomatch = true;
  3308.  
  3309.                         if(currentElement.is(':checkbox'))
  3310.                         {
  3311.                             if(currentElement.is(':checked')) { value = true } else {value = ''}
  3312.                         }
  3313.  
  3314.                         send.dataObj[name] = encodeURIComponent(value);
  3315.  
  3316.                         if(classes && classes.match(/is_empty/))
  3317.                         {
  3318.                             if(value == '' || value == null)
  3319.                             {
  3320.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("error");
  3321.                                 send.validationError = true;
  3322.                             }
  3323.                             else
  3324.                             {
  3325.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("valid");
  3326.                             }
  3327.                             nomatch = false;
  3328.                         }
  3329.  
  3330.                         if(classes && classes.match(/is_email/))
  3331.                         {
  3332.                             if(!value.match(/^[\w|\.|\-]+@\w[\w|\.|\-]*\.[a-zA-Z]{2,20}$/))
  3333.                             {
  3334.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("error");
  3335.                                 send.validationError = true;
  3336.                             }
  3337.                             else
  3338.                             {
  3339.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("valid");
  3340.                             }
  3341.                             nomatch = false;
  3342.                         }
  3343.  
  3344.                         if(classes && classes.match(/is_phone/))
  3345.                         {
  3346.                             if(!value.match(/^(\d|\s|\-|\/|\(|\)|\[|\]|e|x|t|ension|\.|\+|\_|\,|\:|\;){3,}$/))
  3347.                             {
  3348.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("error");
  3349.                                 send.validationError = true;
  3350.                             }
  3351.                             else
  3352.                             {
  3353.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("valid");
  3354.                             }
  3355.                             nomatch = false;
  3356.                         }
  3357.  
  3358.                         if(classes && classes.match(/is_number/))
  3359.                         {
  3360.                             if(!($.isNumeric(value)) || value == "")
  3361.                             {
  3362.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("error");
  3363.                                 send.validationError = true;
  3364.                             }
  3365.                             else
  3366.                             {
  3367.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("valid");
  3368.                             }
  3369.                             nomatch = false;
  3370.                         }
  3371.  
  3372.                         if(classes && classes.match(/captcha/))
  3373.                         {
  3374.                             var verifier    = form.find("#" + name + "_verifier").val(),
  3375.                                 lastVer     = verifier.charAt(verifier.length-1),
  3376.                                 finalVer    = verifier.charAt(lastVer);
  3377.  
  3378.                             if(value != finalVer)
  3379.                             {
  3380.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("error");
  3381.                                 send.validationError = true;
  3382.                             }
  3383.                             else
  3384.                             {
  3385.                                 surroundingElement.removeClass("valid error ajax_alert").addClass("valid");
  3386.                             }
  3387.                             nomatch = false;
  3388.                         }
  3389.  
  3390.                         if(nomatch && value != '')
  3391.                         {
  3392.                             surroundingElement.removeClass("valid error ajax_alert").addClass("valid");
  3393.                         }
  3394.                 });
  3395.  
  3396.                 if(send.validationError == false)
  3397.                 {
  3398.                     if(form.data('av-custom-send'))
  3399.                     {
  3400.                         mailchimp_send();
  3401.                     }
  3402.                     else
  3403.                     {
  3404.                         send_ajax_form();
  3405.                     }
  3406.                 }
  3407.  
  3408.                 return false;
  3409.             }
  3410.  
  3411.  
  3412.             function send_ajax_form()
  3413.             {
  3414.                 if(form_sent){ return false; }
  3415.  
  3416.                 form_sent = true;
  3417.                 send.button.addClass('av-sending-button');
  3418.                 send.button.val(send.button.data('sending-label'));
  3419.  
  3420.                 var redirect_to = form.data('avia-redirect') || false,
  3421.                     action      = form.attr('action');
  3422.  
  3423.                 responseContainer.load(action+' '+options.responseContainer, send.dataObj, function()
  3424.                 {
  3425.                     if(redirect_to && action != redirect_to)
  3426.                     {
  3427.                         form.attr('action', redirect_to);
  3428.                         location.href = redirect_to;
  3429.                         // form.submit();
  3430.                     }
  3431.                     else
  3432.                     {
  3433.                         responseContainer.removeClass('hidden').css({display:"block"});
  3434.                         form.slideUp(400, function(){responseContainer.slideDown(400, function(){ $('body').trigger('av_resize_finished'); }); send.formElements.val('');});
  3435.                     }
  3436.                 });
  3437.             }
  3438.  
  3439.  
  3440.             function mailchimp_send()
  3441.             {
  3442.                 if(form_sent){ return false; }
  3443.  
  3444.                 form_sent = true;
  3445.  
  3446.                 var original_label = send.button.val();
  3447.  
  3448.                 send.button.addClass('av-sending-button');
  3449.                 send.button.val(send.button.data('sending-label'));
  3450.                 send.dataObj.ajax_mailchimp = true;
  3451.  
  3452.                 var redirect_to         = form.data('avia-redirect') || false,
  3453.                     action              = form.attr('action'),
  3454.                     error_msg_container = form.find('.av-form-error-container'),
  3455.                     form_id             = form.data('avia-form-id');
  3456.  
  3457.                 $.ajax({
  3458.                     url: action,
  3459.                     type: "POST",
  3460.                     data:send.dataObj,
  3461.                     beforeSend: function()
  3462.                     {
  3463.                         if(error_msg_container.length)
  3464.                         {
  3465.                             error_msg_container.slideUp(400, function()
  3466.                             {
  3467.                                 error_msg_container.remove();
  3468.                                 $('body').trigger('av_resize_finished');
  3469.                             });
  3470.                         }
  3471.                     },
  3472.                     success: function(responseText)
  3473.                     {
  3474.                         var response    = jQuery("<div>").append(jQuery.parseHTML(responseText)),
  3475.                             error       = response.find('.av-form-error-container');
  3476.  
  3477.                         if(error.length)
  3478.                         {
  3479.                             form_sent = false;
  3480.                             form.prepend(error);
  3481.                             error.css({display:"none"}).slideDown(400, function()
  3482.                             {
  3483.                                 $('body').trigger('av_resize_finished');
  3484.                             });
  3485.  
  3486.                             send.button.removeClass('av-sending-button');
  3487.                             send.button.val(original_label);
  3488.                         }
  3489.                         else
  3490.                         {
  3491.                             if(redirect_to && action != redirect_to)
  3492.                             {
  3493.                                 form.attr('action', redirect_to);
  3494.                                 location.href = redirect_to;
  3495.                                 // form.submit();
  3496.                             }
  3497.                             else
  3498.                             {
  3499.                                 var success_text = response.find(options.responseContainer + "_" + form_id);
  3500.  
  3501.                                 responseContainer.html(success_text).removeClass('hidden').css({display:"block"});
  3502.  
  3503.                                 form.slideUp(400, function()
  3504.                                 {
  3505.                                     responseContainer.slideDown(400, function()
  3506.                                     {
  3507.                                         $('body').trigger('av_resize_finished');
  3508.                                     });
  3509.  
  3510.                                 send.formElements.val('');
  3511.                             });
  3512.                             }
  3513.                         }
  3514.  
  3515.                     },
  3516.                     error: function()
  3517.                     {
  3518.  
  3519.                     },
  3520.                     complete: function()
  3521.                     {
  3522.  
  3523.                     }
  3524.                 });
  3525.  
  3526.             }
  3527.  
  3528.  
  3529.         });
  3530.     };
  3531. })(jQuery);
  3532.  
  3533.  
  3534.  
  3535.  
  3536.  
  3537.  
  3538.  
  3539.  
  3540.  
  3541.  
  3542.  
  3543.  
  3544. // -------------------------------------------------------------------------------------------
  3545. // Aviaccordion Slideshow
  3546. //
  3547. // accordion slider script
  3548. // -------------------------------------------------------------------------------------------
  3549.  
  3550.     $.AviaccordionSlider  =  function(options, slider)
  3551.     {
  3552.         this.$slider    = $( slider );
  3553.         this.$inner     = this.$slider.find('.aviaccordion-inner');
  3554.         this.$slides    = this.$inner.find('.aviaccordion-slide');
  3555.         this.$images    = this.$inner.find('.aviaccordion-image');
  3556.         this.$last      = this.$slides.filter(':last');
  3557.         this.$titles    = this.$slider.find('.aviaccordion-preview');
  3558.         this.$titlePos  = this.$slider.find('.aviaccordion-preview-title-pos');
  3559.         this.$titleWrap = this.$slider.find('.aviaccordion-preview-title-wrap');
  3560.         this.$win       = $( window );
  3561.  
  3562.         if($.avia_utilities.supported.transition === undefined)
  3563.         {
  3564.             $.avia_utilities.supported.transition = $.avia_utilities.supports('transition');
  3565.         }
  3566.  
  3567.         this.browserPrefix  = $.avia_utilities.supported.transition;
  3568.         this.cssActive      = this.browserPrefix !== false ? true : false;
  3569.         this.transform3d    = document.documentElement.className.indexOf('avia_transform3d') !== -1 ? true : false;
  3570.         this.isMobile       = $.avia_utilities.isMobile;
  3571.         this.property       = this.browserPrefix + 'transform',
  3572.         this.count          = this.$slides.length;
  3573.         this.open           = false;
  3574.         this.autoplay       = false;
  3575.         this.increaseTitle  = this.$slider.is(".aviaccordion-title-on-hover");
  3576.         // this.cssActive    = false; //testing no css3 browser
  3577.  
  3578.         this._init( options );
  3579.     }
  3580.  
  3581.     $.AviaccordionSlider.prototype =
  3582.     {
  3583.         _init: function( options )
  3584.         {
  3585.             var _self = this;
  3586.             _self.options = $.extend({}, options, this.$slider.data());
  3587.              $.avia_utilities.preload({container: this.$slider , single_callback:  function(){ _self._kickOff(); }});
  3588.         },
  3589.  
  3590.         _kickOff: function()
  3591.         {
  3592.             var _self = this;
  3593.  
  3594.             _self._calcMovement();
  3595.             _self._bindEvents();
  3596.             _self._showImages();
  3597.             _self._autoplay();
  3598.         },
  3599.  
  3600.         _autoplay: function()
  3601.         {
  3602.             var _self = this;
  3603.  
  3604.             if(_self.options.autoplay)
  3605.             {
  3606.                 _self.autoplay = setInterval(function()
  3607.                 {
  3608.                     _self.open = _self.open === false ? 0 : _self.open + 1;
  3609.                     if(_self.open >= _self.count) _self.open = 0;
  3610.                     _self._move({}, _self.open);
  3611.  
  3612.                 }, _self.options.interval * 1000)
  3613.             }
  3614.         },
  3615.  
  3616.         _showImages: function()
  3617.         {
  3618.             var _self = this, counter = 0, delay = 300, title_delay = this.count * delay;
  3619.  
  3620.             if(this.cssActive)
  3621.             {
  3622.                 setTimeout(function(){ _self.$slider.addClass('av-animation-active'); } , 10);
  3623.             }
  3624.  
  3625.             this.$images.each(function(i)
  3626.             {
  3627.                 var current = $(this), timer = delay * (i + 1);
  3628.  
  3629.                 setTimeout(function()
  3630.                 {
  3631.                     current.avia_animate({opacity:1}, 400, function()
  3632.                     {
  3633.                         current.css($.avia_utilities.supported.transition + "transform", "none");
  3634.                     });
  3635.                 },timer);
  3636.             });
  3637.  
  3638.             if(_self.increaseTitle) title_delay = 0;
  3639.  
  3640.             this.$titlePos.each(function(i)
  3641.             {
  3642.                 var current = $(this), new_timer = title_delay + 100 * (i + 1);
  3643.  
  3644.                 setTimeout(function()
  3645.                 {
  3646.                     current.avia_animate({opacity:1}, 200, function()
  3647.                     {
  3648.                         current.css($.avia_utilities.supported.transition + "transform", "none");
  3649.                     });
  3650.                 },new_timer);
  3651.             });
  3652.         },
  3653.  
  3654.         _bindEvents: function()
  3655.         {
  3656.             var trigger = this.isMobile ? "click" : "mouseenter";
  3657.  
  3658.             this.$slider.on(trigger,'.aviaccordion-slide', $.proxy( this._move, this));
  3659.             this.$slider.on('mouseleave','.aviaccordion-inner', $.proxy( this._move, this));
  3660.             this.$win.on('debouncedresize', $.proxy( this._calcMovement, this));
  3661.             this.$slider.on('av-prev av-next', $.proxy( this._moveTo, this));
  3662.  
  3663.             if(this.isMobile)
  3664.             {
  3665.                 this.$slider.avia_swipe_trigger({next: this.$slider, prev: this.$slider, event:{prev: 'av-prev', next: 'av-next'}});
  3666.             }
  3667.  
  3668.         },
  3669.  
  3670.         _titleHeight: function()
  3671.         {
  3672.             var th = 0;
  3673.  
  3674.             this.$titleWrap.css({'height':'auto'}).each(function()
  3675.             {
  3676.                 var new_h = $(this).outerHeight();
  3677.                 if( new_h > th) th = new_h;
  3678.  
  3679.             }).css({'height':th + 2});
  3680.  
  3681.         },
  3682.  
  3683.         _calcMovement: function(event, allow_repeat)
  3684.         {
  3685.             var _self           = this,
  3686.                 containerWidth  = this.$slider.width(),
  3687.                 defaultPos      = this.$last.data('av-left'),
  3688.                 imgWidth        = this.$images.filter(':last').width() || containerWidth,
  3689.                 imgWidthPercent = Math.floor((100 / containerWidth) * imgWidth),
  3690.                 allImageWidth   = imgWidthPercent * _self.count,
  3691.                 modifier        = 3, // 10 - _self.count,
  3692.                 tempMinLeft     = 100 - imgWidthPercent,
  3693.                 minLeft         = tempMinLeft > defaultPos / modifier ? tempMinLeft : 0,
  3694.                 oneLeft         = minLeft / (_self.count -1 ),
  3695.                 titleWidth      = imgWidth;
  3696.  
  3697.  
  3698.  
  3699.             if(allImageWidth < 110 && allow_repeat !== false)
  3700.             {
  3701.                 //set height if necessary
  3702.                 var slideHeight = this.$slider.height(),
  3703.                     maxHeight   = (slideHeight / allImageWidth) * 110 ;
  3704.  
  3705.                 this.$slider.css({'max-height': maxHeight});
  3706.                 _self._calcMovement(event, false);
  3707.                 return;
  3708.             }
  3709.  
  3710.             //backup so the minimized slides dont get too small
  3711.             if(oneLeft < 2) minLeft = 0;
  3712.  
  3713.             this.$slides.each(function(i)
  3714.             {
  3715.                 var current = $(this), newLeft = 0, newRight = 0, defaultLeft = current.data('av-left');
  3716.  
  3717.                 if( minLeft !== 0)
  3718.                 {
  3719.                     newLeft  = oneLeft * i;
  3720.                     newRight = imgWidthPercent + newLeft - oneLeft;
  3721.                 }
  3722.                 else
  3723.                 {
  3724.                     newLeft  = defaultLeft / Math.abs(modifier);
  3725.                     newRight = 100 - ((newLeft / i) * (_self.count - i));
  3726.                 }
  3727.  
  3728.                 if(i == 1 && _self.increaseTitle) { titleWidth = newRight + 1; }
  3729.  
  3730.                 if(_self.cssActive)
  3731.                 {
  3732.                     //if we are not animating based on the css left value but on css transform we need to subtract the left value
  3733.                     newLeft = newLeft - defaultLeft;
  3734.                     newRight = newRight - defaultLeft;
  3735.                     defaultLeft = 0;
  3736.                 }
  3737.  
  3738.                 current.data('av-calc-default', defaultLeft);
  3739.                 current.data('av-calc-left', newLeft);
  3740.                 current.data('av-calc-right', newRight);
  3741.  
  3742.             });
  3743.  
  3744.             if(_self.increaseTitle) { _self.$titles.css({width: titleWidth + "%"});}
  3745.         },
  3746.  
  3747.         _moveTo: function(event)
  3748.         {
  3749.             var direction   = event.type == "av-next" ? 1 : -1,
  3750.                 nextSlide   = this.open === false ? 0 : this.open + direction;
  3751.  
  3752.             if(nextSlide >= 0 && nextSlide < this.$slides.length) this._move(event, nextSlide);
  3753.         },
  3754.  
  3755.         _move: function(event, direct_open)
  3756.         {
  3757.             var _self  = this,
  3758.                 slide  = event.currentTarget,
  3759.                 itemNo = typeof direct_open != "undefined" ? direct_open : this.$slides.index(slide);
  3760.  
  3761.             this.open = itemNo;
  3762.  
  3763.             if(_self.autoplay && typeof slide != "undefined") { clearInterval(_self.autoplay); _self.autoplay = false; }
  3764.  
  3765.             this.$slides.removeClass('aviaccordion-active-slide').each(function(i)
  3766.             {
  3767.                 var current     = $(this),
  3768.                     dataSet     = current.data(),
  3769.                     trans_val   = i <= itemNo ? dataSet.avCalcLeft : dataSet.avCalcRight,
  3770.                     transition  = {},
  3771.                     reset       = event.type == 'mouseleave' ? 1 : 0,
  3772.                     active      = itemNo === i ? _self.$titleWrap.eq(i) : false;
  3773.  
  3774.                 if(active) current.addClass('aviaccordion-active-slide');
  3775.  
  3776.                 if(reset)
  3777.                 {
  3778.                     trans_val = dataSet.avCalcDefault;
  3779.                     this.open = false;
  3780.                 }
  3781.  
  3782.                 if(_self.cssActive) //do a css3 animation
  3783.                 {
  3784.                     //move the slides
  3785.                     transition[_self.property]  = _self.transform3d ? "translate3d(" + trans_val  + "%, 0, 0)" : "translate(" + trans_val + "%,0)"; //3d or 2d transform?
  3786.                     current.css(transition);
  3787.                 }
  3788.                 else
  3789.                 {
  3790.                     transition.left =  trans_val + "%";
  3791.                     current.stop().animate(transition, 700, 'easeOutQuint');
  3792.                 }
  3793.             });
  3794.         }
  3795.     };
  3796.  
  3797.  
  3798. $.fn.aviaccordion = function( options )
  3799. {
  3800.     return this.each(function()
  3801.     {
  3802.         var active = $.data( this, 'AviaccordionSlider' );
  3803.  
  3804.         if(!active)
  3805.         {
  3806.             //make sure that the function doesnt get aplied a second time
  3807.             $.data( this, 'AviaccordionSlider', 1 );
  3808.  
  3809.             //create the preparations for fullscreen slider
  3810.             new $.AviaccordionSlider( options, this );
  3811.         }
  3812.     });
  3813. }
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824.  
  3825. // -------------------------------------------------------------------------------------------
  3826. // Aviaccordion Slideshow
  3827. //
  3828. // accordion slider script
  3829. // -------------------------------------------------------------------------------------------
  3830.  
  3831.     $.AviaTextRotator  =  function(options, slider)
  3832.     {
  3833.         this.$win       = $( window );
  3834.         this.$slider    = $( slider );
  3835.         this.$inner     = this.$slider.find('.av-rotator-text');
  3836.         this.$slides    = this.$inner.find('.av-rotator-text-single');
  3837.         this.$current   = this.$slides.eq(0);
  3838.         this.open       = 0;
  3839.         this.count      = this.$slides.length;
  3840.  
  3841.         if($.avia_utilities.supported.transition === undefined)
  3842.         {
  3843.             $.avia_utilities.supported.transition = $.avia_utilities.supports('transition');
  3844.         }
  3845.  
  3846.         this.browserPrefix  = $.avia_utilities.supported.transition;
  3847.         this.cssActive      = this.browserPrefix !== false ? true : false;
  3848.         this.property       = this.browserPrefix + 'transform',
  3849.  
  3850.         //this.cssActive    = false; //testing no css3 browser
  3851.  
  3852.         this._init( options );
  3853.     }
  3854.  
  3855.     $.AviaTextRotator.prototype =
  3856.     {
  3857.         _init: function( options )
  3858.         {
  3859.             var _self = this;
  3860.  
  3861.             if(this.count <= 1) return;
  3862.  
  3863.             _self.options = $.extend({}, options, this.$slider.data());
  3864.             _self.$inner.addClass('av-rotation-active');
  3865.             //if(_self.options.fixwidth == 1) this.$inner.width(this.$current.width());
  3866.             _self._autoplay();
  3867.         },
  3868.  
  3869.         _autoplay: function()
  3870.         {
  3871.             var _self = this;
  3872.  
  3873.             _self.autoplay = setInterval(function()
  3874.             {
  3875.                 _self.open = _self.open === false ? 0 : _self.open + 1;
  3876.                 if(_self.open >= _self.count) _self.open = 0;
  3877.                 _self._move({}, _self.open);
  3878.  
  3879.             }, _self.options.interval * 1000)
  3880.         },
  3881.  
  3882.         _move: function(event)
  3883.         {
  3884.             var _self       = this,
  3885.                 modifier    = 30 * _self.options.animation,
  3886.                 fade_out    = {opacity:0},
  3887.                 fade_start  = {display:'inline-block', opacity:0},
  3888.                 fade_in     = {opacity:1};
  3889.  
  3890.             this.$next = _self.$slides.eq(this.open);
  3891.  
  3892.             if(this.cssActive)
  3893.             {
  3894.                 fade_out[_self.property]    = "translate(0px," + modifier +"px)";
  3895.                 fade_start[_self.property]  = "translate(0px," + (modifier * -1) +"px)";
  3896.                 fade_in[_self.property]     = "translate(0px,0px)";
  3897.             }
  3898.             else
  3899.             {
  3900.                 fade_out['top']     = modifier;
  3901.                 fade_start['top']   = (modifier * -1);
  3902.                 fade_in['top']      = 0;
  3903.             }
  3904.  
  3905.  
  3906.             _self.$current.avia_animate(fade_out, function()
  3907.             {
  3908.                 _self.$current.css({display:'none'});
  3909.                 _self.$next.css(fade_start).avia_animate(fade_in, function()
  3910.                 {
  3911.                     _self.$current = _self.$slides.eq(_self.open);
  3912.                 });
  3913.             });
  3914.         }
  3915.     };
  3916.  
  3917.  
  3918. $.fn.avia_textrotator = function( options )
  3919. {
  3920.     return this.each(function()
  3921.     {
  3922.         var active = $.data( this, 'AviaTextRotator' );
  3923.  
  3924.         if(!active)
  3925.         {
  3926.             //make sure that the function doesnt get aplied a second time
  3927.             $.data( this, 'AviaTextRotator', 1 );
  3928.  
  3929.             //create the preparations for fullscreen slider
  3930.             new $.AviaTextRotator( options, this );
  3931.         }
  3932.     });
  3933. }
  3934.  
  3935.  
  3936.  
  3937.  
  3938.  
  3939.  
  3940.  
  3941.  
  3942.  
  3943.  
  3944.  
  3945.  
  3946.  
  3947.  
  3948.  
  3949. // -------------------------------------------------------------------------------------------
  3950. // HELPER FUNCTIONS
  3951. // -------------------------------------------------------------------------------------------
  3952.  
  3953.  
  3954. //waipoint script when something comes into viewport
  3955.  $.fn.avia_waypoints = function(options_passed)
  3956.     {
  3957.         if(! $('html').is('.avia_transform')) return;
  3958.  
  3959.         var defaults = { offset: 'bottom-in-view' , triggerOnce: true},
  3960.             options  = $.extend({}, defaults, options_passed),
  3961.             isMobile = $.avia_utilities.isMobile;
  3962.  
  3963.         return this.each(function()
  3964.         {
  3965.             var element = $(this);
  3966.  
  3967.             setTimeout(function()
  3968.             {
  3969.                 if(isMobile)
  3970.                 {
  3971.                     element.addClass('avia_start_animation').trigger('avia_start_animation');
  3972.                 }
  3973.                 else
  3974.                 {
  3975.                     element.waypoint(function(direction)
  3976.                     {
  3977.                         var current     = $(this.element),
  3978.                             parent      = current.parents('.av-animation-delay-container:eq(0)');
  3979.  
  3980.                         if(parent.length)
  3981.                         {
  3982.                             current.addClass('avia_start_animation_when_active').trigger('avia_start_animation_when_active');
  3983.                         }
  3984.  
  3985.                         if(!parent.length || (parent.length && parent.is('.__av_init_open')))
  3986.                         {
  3987.                             current.addClass('avia_start_animation').trigger('avia_start_animation');
  3988.                         }
  3989.  
  3990.  
  3991.  
  3992.                     }, options );
  3993.                 }
  3994.             },100)
  3995.  
  3996.         });
  3997.     };
  3998.  
  3999.  
  4000.  
  4001.  
  4002.  
  4003.  
  4004.  
  4005. // window resize script
  4006. var $event = $.event, $special, resizeTimeout;
  4007.  
  4008. $special = $event.special.debouncedresize = {
  4009.     setup: function() {
  4010.         $( this ).on( "resize", $special.handler );
  4011.     },
  4012.     teardown: function() {
  4013.         $( this ).off( "resize", $special.handler );
  4014.     },
  4015.     handler: function( event, execAsap ) {
  4016.         // Save the context
  4017.         var context = this,
  4018.             args = arguments,
  4019.             dispatch = function() {
  4020.                 // set correct event type
  4021.                 event.type = "debouncedresize";
  4022.                 $event.dispatch.apply( context, args );
  4023.             };
  4024.  
  4025.         if ( resizeTimeout ) {
  4026.             clearTimeout( resizeTimeout );
  4027.         }
  4028.  
  4029.         execAsap ?
  4030.             dispatch() :
  4031.             resizeTimeout = setTimeout( dispatch, $special.threshold );
  4032.     },
  4033.     threshold: 150
  4034. };
  4035.  
  4036.  
  4037.  
  4038.  
  4039.  
  4040. $.easing['jswing'] = $.easing['swing'];
  4041.  
  4042. $.extend( $.easing,
  4043. {
  4044.     def: 'easeOutQuad',
  4045.     swing: function (x, t, b, c, d) { return $.easing[$.easing.def](x, t, b, c, d); },
  4046.     easeInQuad: function (x, t, b, c, d) { return c*(t/=d)*t + b; },
  4047.     easeOutQuad: function (x, t, b, c, d) { return -c *(t/=d)*(t-2) + b; },
  4048.     easeInOutQuad: function (x, t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t + b; return -c/2 * ((--t)*(t-2) - 1) + b; },
  4049.     easeInCubic: function (x, t, b, c, d) { return c*(t/=d)*t*t + b; },
  4050.     easeOutCubic: function (x, t, b, c, d) { return c*((t=t/d-1)*t*t + 1) + b; },
  4051.     easeInOutCubic: function (x, t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t*t + b; return c/2*((t-=2)*t*t + 2) + b; },
  4052.     easeInQuart: function (x, t, b, c, d) { return c*(t/=d)*t*t*t + b;  },
  4053.     easeOutQuart: function (x, t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; },
  4054.     easeInOutQuart: function (x, t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t*t*t + b; return -c/2 * ((t-=2)*t*t*t - 2) + b;  },
  4055.     easeInQuint: function (x, t, b, c, d) { return c*(t/=d)*t*t*t*t + b;    },
  4056.     easeOutQuint: function (x, t, b, c, d) { return c*((t=t/d-1)*t*t*t*t + 1) + b;  },
  4057.     easeInOutQuint: function (x, t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; return c/2*((t-=2)*t*t*t*t + 2) + b; },
  4058.     easeInSine: function (x, t, b, c, d) {  return -c * Math.cos(t/d * (Math.PI/2)) + c + b;    },
  4059.     easeOutSine: function (x, t, b, c, d) { return c * Math.sin(t/d * (Math.PI/2)) + b; },
  4060.     easeInOutSine: function (x, t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;    },
  4061.     easeInExpo: function (x, t, b, c, d) { return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; },
  4062.     easeOutExpo: function (x, t, b, c, d) { return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;    },
  4063.     easeInOutExpo: function (x, t, b, c, d) {
  4064.         if (t==0) return b;
  4065.         if (t==d) return b+c;
  4066.         if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
  4067.         return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
  4068.     },
  4069.     easeInCirc: function (x, t, b, c, d) { return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;   },
  4070.     easeOutCirc: function (x, t, b, c, d) {return c * Math.sqrt(1 - (t=t/d-1)*t) + b;   },
  4071.     easeInOutCirc: function (x, t, b, c, d) { if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; },
  4072.     easeInElastic: function (x, t, b, c, d) {
  4073.         var s=1.70158;var p=0;var a=c;
  4074.         if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
  4075.         if (a < Math.abs(c)) { a=c; var s=p/4; }
  4076.         else var s = p/(2*Math.PI) * Math.asin (c/a);
  4077.         return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  4078.     },
  4079.     easeOutElastic: function (x, t, b, c, d) {
  4080.         var s=1.70158;var p=0;var a=c;
  4081.         if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
  4082.         if (a < Math.abs(c)) { a=c; var s=p/4; }
  4083.         else var s = p/(2*Math.PI) * Math.asin (c/a);
  4084.         return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
  4085.     },
  4086.     easeInOutElastic: function (x, t, b, c, d) {
  4087.         var s=1.70158;var p=0;var a=c;
  4088.         if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
  4089.         if (a < Math.abs(c)) { a=c; var s=p/4; }
  4090.         else var s = p/(2*Math.PI) * Math.asin (c/a);
  4091.         if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  4092.         return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
  4093.     },
  4094.     easeInBack: function (x, t, b, c, d, s) {
  4095.         if (s == undefined) s = 1.70158;
  4096.         return c*(t/=d)*t*((s+1)*t - s) + b;
  4097.     },
  4098.     easeOutBack: function (x, t, b, c, d, s) {
  4099.         if (s == undefined) s = 1.70158;
  4100.         return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
  4101.     },
  4102.     easeInOutBack: function (x, t, b, c, d, s) {
  4103.         if (s == undefined) s = 1.70158;
  4104.         if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
  4105.         return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
  4106.     },
  4107.     easeInBounce: function (x, t, b, c, d) {
  4108.         return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
  4109.     },
  4110.     easeOutBounce: function (x, t, b, c, d) {
  4111.         if ((t/=d) < (1/2.75)) {
  4112.             return c*(7.5625*t*t) + b;
  4113.         } else if (t < (2/2.75)) {
  4114.             return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
  4115.         } else if (t < (2.5/2.75)) {
  4116.             return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
  4117.         } else {
  4118.             return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
  4119.         }
  4120.     },
  4121.     easeInOutBounce: function (x, t, b, c, d) {
  4122.         if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
  4123.         return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
  4124.     }
  4125. });
  4126.  
  4127. })( jQuery );
  4128.  
  4129.  
  4130.  
  4131. /*utility functions*/
  4132.  
  4133.  
  4134. (function($)
  4135. {
  4136.     "use strict";
  4137.  
  4138.     $.avia_utilities = $.avia_utilities || {};
  4139.  
  4140.     /************************************************************************
  4141.     gloabl loading function
  4142.     *************************************************************************/
  4143.     $.avia_utilities.loading = function(attach_to, delay){
  4144.  
  4145.         var loader = {
  4146.  
  4147.             active: false,
  4148.  
  4149.             show: function()
  4150.             {
  4151.                 if(loader.active === false)
  4152.                 {
  4153.                     loader.active = true;
  4154.                     loader.loading_item.css({display:'block', opacity:0});
  4155.                 }
  4156.  
  4157.                 loader.loading_item.stop().animate({opacity:1});
  4158.             },
  4159.  
  4160.             hide: function()
  4161.             {
  4162.                 if(typeof delay === 'undefined'){ delay = 600; }
  4163.  
  4164.                 loader.loading_item.stop().delay( delay ).animate({opacity:0}, function()
  4165.                 {
  4166.                     loader.loading_item.css({display:'none'});
  4167.                     loader.active = false;
  4168.                 });
  4169.             },
  4170.  
  4171.             attach: function()
  4172.             {
  4173.                 if(typeof attach_to === 'undefined'){ attach_to = 'body';}
  4174.  
  4175.                 loader.loading_item = $('<div class="avia_loading_icon"><div class="av-siteloader"></div></div>').css({display:"none"}).appendTo(attach_to);
  4176.             }
  4177.         }
  4178.  
  4179.         loader.attach();
  4180.         return loader;
  4181.     };
  4182.  
  4183.     /************************************************************************
  4184.     gloabl play/pause visualizer function
  4185.     *************************************************************************/
  4186.     $.avia_utilities.playpause = function(attach_to, delay){
  4187.  
  4188.         var pp = {
  4189.  
  4190.             active: false,
  4191.             to1: "",
  4192.             to2: "",
  4193.             set: function(status)
  4194.             {
  4195.                 pp.loading_item.removeClass('av-play av-pause');
  4196.                 pp.to1 = setTimeout(function(){ pp.loading_item.addClass('av-' + status); },10);
  4197.                 pp.to2 = setTimeout(function(){ pp.loading_item.removeClass('av-' + status); },1500);
  4198.             },
  4199.  
  4200.             attach: function()
  4201.             {
  4202.                 if(typeof attach_to === 'undefined'){ attach_to = 'body';}
  4203.  
  4204.                 pp.loading_item = $('<div class="avia_playpause_icon"></div>').css({display:"none"}).appendTo(attach_to);
  4205.             }
  4206.         }
  4207.  
  4208.         pp.attach();
  4209.         return pp;
  4210.     };
  4211.  
  4212.  
  4213.  
  4214.     /************************************************************************
  4215.     preload images, as soon as all are loaded trigger a special load ready event
  4216.     *************************************************************************/
  4217.     $.avia_utilities.preload = function(options_passed)
  4218.     {
  4219.         new $.AviaPreloader(options_passed);
  4220.     }
  4221.  
  4222.     $.AviaPreloader  =  function(options)
  4223.     {
  4224.         this.win        = $(window);
  4225.         this.defaults   =
  4226.         {
  4227.             container:          'body',
  4228.             maxLoops:           10,
  4229.             trigger_single:     true,
  4230.             single_callback:    function(){},
  4231.             global_callback:    function(){}
  4232.  
  4233.         };
  4234.         this.options    = $.extend({}, this.defaults, options);
  4235.         this.preload_images = 0;
  4236.  
  4237.         this.load_images();
  4238.     }
  4239.  
  4240.     $.AviaPreloader.prototype  =
  4241.     {
  4242.         load_images: function()
  4243.         {
  4244.             var _self = this;
  4245.  
  4246.             if(typeof _self.options.container === 'string'){ _self.options.container = $(_self.options.container); }
  4247.  
  4248.             _self.options.container.each(function()
  4249.             {
  4250.                 var container       = $(this);
  4251.  
  4252.                 container.images    = container.find('img');
  4253.                 container.allImages = container.images;
  4254.  
  4255.                 _self.preload_images += container.images.length;
  4256.                 setTimeout(function(){ _self.checkImage(container); }, 10);
  4257.             });
  4258.         },
  4259.  
  4260.         checkImage: function(container)
  4261.         {
  4262.             var _self = this;
  4263.  
  4264.             container.images.each(function()
  4265.             {
  4266.                 if(this.complete === true)
  4267.                 {
  4268.                     container.images = container.images.not(this);
  4269.                     _self.preload_images -= 1;
  4270.                 }
  4271.             });
  4272.  
  4273.             if(container.images.length && _self.options.maxLoops >= 0)
  4274.             {
  4275.                 _self.options.maxLoops-=1;
  4276.                 setTimeout(function(){ _self.checkImage(container); }, 500);
  4277.             }
  4278.             else
  4279.             {
  4280.                 _self.preload_images = _self.preload_images - container.images.length;
  4281.                 _self.trigger_loaded(container);
  4282.             }
  4283.         },
  4284.  
  4285.         trigger_loaded: function(container)
  4286.         {
  4287.             var _self = this;
  4288.  
  4289.             if(_self.options.trigger_single !== false)
  4290.             {
  4291.                 _self.win.trigger('avia_images_loaded_single', [container]);
  4292.                 _self.options.single_callback.call(container);
  4293.             }
  4294.  
  4295.             if(_self.preload_images === 0)
  4296.             {
  4297.                 _self.win.trigger('avia_images_loaded');
  4298.                 _self.options.global_callback.call();
  4299.             }
  4300.  
  4301.         }
  4302.     }
  4303.  
  4304.  
  4305.     /************************************************************************
  4306.     CSS Easing transformation table
  4307.     *************************************************************************/
  4308.     /*
  4309.     Easing transform table from jquery.animate-enhanced plugin
  4310.     http://github.com/benbarnett/jQuery-Animate-Enhanced
  4311.     */
  4312.     $.avia_utilities.css_easings = {
  4313.             linear:         'linear',
  4314.             swing:          'ease-in-out',
  4315.             bounce:         'cubic-bezier(0.0, 0.35, .5, 1.3)',
  4316.             easeInQuad:     'cubic-bezier(0.550, 0.085, 0.680, 0.530)' ,
  4317.             easeInCubic:    'cubic-bezier(0.550, 0.055, 0.675, 0.190)' ,
  4318.             easeInQuart:    'cubic-bezier(0.895, 0.030, 0.685, 0.220)' ,
  4319.             easeInQuint:    'cubic-bezier(0.755, 0.050, 0.855, 0.060)' ,
  4320.             easeInSine:     'cubic-bezier(0.470, 0.000, 0.745, 0.715)' ,
  4321.             easeInExpo:     'cubic-bezier(0.950, 0.050, 0.795, 0.035)' ,
  4322.             easeInCirc:     'cubic-bezier(0.600, 0.040, 0.980, 0.335)' ,
  4323.             easeInBack:     'cubic-bezier(0.600, -0.280, 0.735, 0.04)' ,
  4324.             easeOutQuad:    'cubic-bezier(0.250, 0.460, 0.450, 0.940)' ,
  4325.             easeOutCubic:   'cubic-bezier(0.215, 0.610, 0.355, 1.000)' ,
  4326.             easeOutQuart:   'cubic-bezier(0.165, 0.840, 0.440, 1.000)' ,
  4327.             easeOutQuint:   'cubic-bezier(0.230, 1.000, 0.320, 1.000)' ,
  4328.             easeOutSine:    'cubic-bezier(0.390, 0.575, 0.565, 1.000)' ,
  4329.             easeOutExpo:    'cubic-bezier(0.190, 1.000, 0.220, 1.000)' ,
  4330.             easeOutCirc:    'cubic-bezier(0.075, 0.820, 0.165, 1.000)' ,
  4331.             easeOutBack:    'cubic-bezier(0.175, 0.885, 0.320, 1.275)' ,
  4332.             easeInOutQuad:  'cubic-bezier(0.455, 0.030, 0.515, 0.955)' ,
  4333.             easeInOutCubic: 'cubic-bezier(0.645, 0.045, 0.355, 1.000)' ,
  4334.             easeInOutQuart: 'cubic-bezier(0.770, 0.000, 0.175, 1.000)' ,
  4335.             easeInOutQuint: 'cubic-bezier(0.860, 0.000, 0.070, 1.000)' ,
  4336.             easeInOutSine:  'cubic-bezier(0.445, 0.050, 0.550, 0.950)' ,
  4337.             easeInOutExpo:  'cubic-bezier(1.000, 0.000, 0.000, 1.000)' ,
  4338.             easeInOutCirc:  'cubic-bezier(0.785, 0.135, 0.150, 0.860)' ,
  4339.             easeInOutBack:  'cubic-bezier(0.680, -0.550, 0.265, 1.55)' ,
  4340.             easeInOutBounce:'cubic-bezier(0.580, -0.365, 0.490, 1.365)',
  4341.             easeOutBounce:  'cubic-bezier(0.760, 0.085, 0.490, 1.365)'
  4342.         };
  4343.  
  4344.     /************************************************************************
  4345.     check if a css feature is supported and save it to the supported array
  4346.     *************************************************************************/
  4347.     $.avia_utilities.supported  = {};
  4348.     $.avia_utilities.supports   = (function()
  4349.     {
  4350.         var div     = document.createElement('div'),
  4351.             vendors = ['Khtml', 'Ms','Moz','Webkit'];  // vendors   = ['Khtml', 'Ms','Moz','Webkit','O'];
  4352.  
  4353.         return function(prop, vendor_overwrite)
  4354.         {
  4355.             if ( div.style[prop] !== undefined  ) { return ""; }
  4356.             if (vendor_overwrite !== undefined) { vendors = vendor_overwrite; }
  4357.  
  4358.             prop = prop.replace(/^[a-z]/, function(val)
  4359.             {
  4360.                 return val.toUpperCase();
  4361.             });
  4362.  
  4363.             var len = vendors.length;
  4364.             while(len--)
  4365.             {
  4366.                 if ( div.style[vendors[len] + prop] !== undefined )
  4367.                 {
  4368.                     return "-" + vendors[len].toLowerCase() + "-";
  4369.                 }
  4370.             }
  4371.  
  4372.             return false;
  4373.         };
  4374.  
  4375.     }());
  4376.  
  4377.     /************************************************************************
  4378.     animation function
  4379.     *************************************************************************/
  4380.     $.fn.avia_animate = function(prop, speed, easing, callback)
  4381.     {
  4382.         if(typeof speed === 'function') {callback = speed; speed = false; }
  4383.         if(typeof easing === 'function'){callback = easing; easing = false;}
  4384.         if(typeof speed === 'string'){easing = speed; speed = false;}
  4385.  
  4386.         if(callback === undefined || callback === false){ callback = function(){}; }
  4387.         if(easing === undefined || easing === false)    { easing = 'easeInQuad'; }
  4388.         if(speed === undefined || speed === false)      { speed = 400; }
  4389.  
  4390.         if($.avia_utilities.supported.transition === undefined)
  4391.         {
  4392.             $.avia_utilities.supported.transition = $.avia_utilities.supports('transition');
  4393.         }
  4394.  
  4395.  
  4396.  
  4397.         if($.avia_utilities.supported.transition !== false )
  4398.         {
  4399.             var prefix      = $.avia_utilities.supported.transition + 'transition',
  4400.                 cssRule     = {},
  4401.                 cssProp     = {},
  4402.                 thisStyle   = document.body.style,
  4403.                 end         = (thisStyle.WebkitTransition !== undefined) ? 'webkitTransitionEnd' : (thisStyle.OTransition !== undefined) ? 'oTransitionEnd' : 'transitionend';
  4404.  
  4405.             //translate easing into css easing
  4406.             easing = $.avia_utilities.css_easings[easing];
  4407.  
  4408.             //create css transformation rule
  4409.             cssRule[prefix] =  'all '+(speed/1000)+'s '+easing;
  4410.             //add namespace to the transition end trigger
  4411.             end = end + ".avia_animate";
  4412.  
  4413.             //since jquery 1.10 the items passed need to be {} and not [] so make sure they are converted properly
  4414.             for (var rule in prop)
  4415.             {
  4416.                 if (prop.hasOwnProperty(rule)) { cssProp[rule] = prop[rule]; }
  4417.             }
  4418.             prop = cssProp;
  4419.  
  4420.  
  4421.  
  4422.             this.each(function()
  4423.             {
  4424.                 var element = $(this), css_difference = false, rule, current_css;
  4425.  
  4426.                 for (rule in prop)
  4427.                 {
  4428.                     if (prop.hasOwnProperty(rule))
  4429.                     {
  4430.                         current_css = element.css(rule);
  4431.  
  4432.                         if(prop[rule] != current_css && prop[rule] != current_css.replace(/px|%/g,""))
  4433.                         {
  4434.                             css_difference = true;
  4435.                             break;
  4436.                         }
  4437.                     }
  4438.                 }
  4439.  
  4440.                 if(css_difference)
  4441.                 {
  4442.                     //if no transform property is set set a 3d translate to enable hardware acceleration
  4443.                     if(!($.avia_utilities.supported.transition+"transform" in prop))
  4444.                     {
  4445.                         prop[$.avia_utilities.supported.transition+"transform"] = "translateZ(0)";
  4446.                     }
  4447.  
  4448.                     var endTriggered = false;
  4449.  
  4450.                     element.on(end,  function(event)
  4451.                     {
  4452.                         if(event.target != event.currentTarget) return false;
  4453.  
  4454.                         if(endTriggered == true) return false;
  4455.                         endTriggered = true;
  4456.  
  4457.                         cssRule[prefix] = "none";
  4458.  
  4459.                         element.off(end);
  4460.                         element.css(cssRule);
  4461.                         setTimeout(function(){ callback.call(element); });
  4462.                     });
  4463.  
  4464.  
  4465.                     //desktop safari fallback if we are in another tab to trigger the end event
  4466.                     setTimeout(function(){
  4467.                         if(!endTriggered && !avia_is_mobile && $('html').is('.avia-safari') ) {
  4468.                             element.trigger(end);
  4469.                             $.avia_utilities.log('Safari Fallback '+end+' trigger');
  4470.                         }
  4471.                     }, speed + 100);
  4472.  
  4473.                     setTimeout(function(){ element.css(cssRule);},10);
  4474.                     setTimeout(function(){ element.css(prop);   },20);
  4475.                 }
  4476.                 else
  4477.                 {
  4478.                     setTimeout(function(){ callback.call(element); });
  4479.                 }
  4480.  
  4481.             });
  4482.         }
  4483.         else // if css animation is not available use default JS animation
  4484.         {
  4485.             this.animate(prop, speed, easing, callback);
  4486.         }
  4487.  
  4488.         return this;
  4489.     };
  4490.  
  4491. })( jQuery );
  4492.  
  4493.  
  4494. /* ======================================================================================================================================================
  4495. Avia Slideshow
  4496. ====================================================================================================================================================== */
  4497.  
  4498. (function($)
  4499. {
  4500.     "use strict";
  4501.  
  4502.     $.AviaSlider  =  function(options, slider)
  4503.     {
  4504.         var self = this;
  4505.  
  4506.         this.$win    = $( window );
  4507.  
  4508.         this.$slider = $( slider );
  4509.  
  4510.         this.isMobile = $.avia_utilities.isMobile;
  4511.  
  4512.         this._prepareSlides(options);
  4513.  
  4514.         //default preload images then init slideshow
  4515.         $.avia_utilities.preload({container: this.$slider , single_callback:  function(){ self._init( options ); }});
  4516.     }
  4517.  
  4518.     $.AviaSlider.defaults  = {
  4519.  
  4520.         //interval between autorotation switches
  4521.         interval:5,
  4522.  
  4523.         //autorotation active or not
  4524.         autoplay:false,
  4525.  
  4526.         //set if the loop will stop at the last/first slide or if the slides will loop infinite
  4527.         //set to false for infinite loop, "last" to stop at the last slide or "first" to stop at the first slide
  4528.         stopinfiniteloop: false,
  4529.  
  4530.         //fade or slide animation
  4531.         animation:'slide',
  4532.  
  4533.         //transition speed when switching slide
  4534.         transitionSpeed:900,
  4535.  
  4536.         //easing method for the transition
  4537.         easing:'easeInOutQuart',
  4538.  
  4539.         //slide wrapper
  4540.         wrapElement: '>ul',
  4541.  
  4542.         //slide element
  4543.         slideElement: '>li',
  4544.  
  4545.         //pause if mouse cursor is above item
  4546.         hoverpause: false,
  4547.  
  4548.         //attach images as background
  4549.         bg_slider: false,
  4550.  
  4551.         //delay of miliseconds to wait before showing the next slide
  4552.         show_slide_delay: 0,
  4553.  
  4554.         //if slider animation is set to "fade" the fullfade property sets the crossfade behaviour
  4555.         fullfade: false
  4556.  
  4557.     };
  4558.  
  4559.     $.AviaSlider.prototype =
  4560.     {
  4561.         _init: function( options )
  4562.         {
  4563.             // set slider options
  4564.             this.options = this._setOptions(options);
  4565.  
  4566.             //slidewrap
  4567.             this.$sliderUl  = this.$slider.find(this.options.wrapElement);
  4568.  
  4569.             // slide elements
  4570.             this.$slides = this.$sliderUl.find(this.options.slideElement);
  4571.  
  4572.             // goto dots
  4573.             this.gotoButtons = this.$slider.find('.avia-slideshow-dots a');
  4574.  
  4575.             //perma caption
  4576.             this.permaCaption =  this.$slider.find('>.av-slideshow-caption');
  4577.  
  4578.             // slide count
  4579.             this.itemsCount = this.$slides.length;
  4580.  
  4581.             // current image index
  4582.             this.current = 0;
  4583.  
  4584.             //loop count
  4585.             this.loopCount = 0;
  4586.  
  4587.             // control if the slicebox is animating
  4588.             this.isAnimating = false;
  4589.  
  4590.             // css browser prefix like -webkit-, -moz-
  4591.             this.browserPrefix = $.avia_utilities.supports('transition');
  4592.  
  4593.             // css3 animation?
  4594.             this.cssActive = this.browserPrefix !== false ? true : false;
  4595.  
  4596.             // css3D animation?
  4597.             this.css3DActive = document.documentElement.className.indexOf('avia_transform3d') !== -1 ? true : false;
  4598.  
  4599.             //store the aviaVideoApi object for the current slide if available
  4600.             this.video  = false;
  4601.  
  4602.             //if we have a bg slider no images were preloaded yet. in that case start preloading and attaching images
  4603.             if(this.options.bg_slider == true)
  4604.             {
  4605.                 //create array that holds all image urls to preload
  4606.                 this.imageUrls = [];
  4607.  
  4608.                 //create a preloader icon to indicate loading
  4609.                 this.loader = $.avia_utilities.loading(this.$slider);
  4610.  
  4611.                 //preload the images ony by one
  4612.                 this._bgPreloadImages();
  4613.  
  4614.             }
  4615.             else //if it was a default slider all images are already loaded and we can start showing the slider
  4616.             {
  4617.                 //kickoff the slider: bind functions, show first slide, if active start the autorotation timer
  4618.                 this._kickOff();
  4619.             }
  4620.         },
  4621.  
  4622.         //set the slider options by first merging the efault options and the passed options, then checking the slider element if any data attributes overwrite the option set
  4623.         _setOptions: function(options)
  4624.         {
  4625.             var newOptions  = $.extend( true, {}, $.AviaSlider.defaults, options ),
  4626.                 htmlData    = this.$slider.data(),
  4627.                 i           = "";
  4628.  
  4629.             //overwritte passed option set with any data properties on the html element
  4630.             for (i in htmlData)
  4631.             {
  4632.                 if (htmlData.hasOwnProperty(i))
  4633.                 {
  4634.                     if(typeof htmlData[i] === "string" || typeof htmlData[i] === "number" || typeof htmlData[i] === "boolean")
  4635.                     {
  4636.                         newOptions[i] = htmlData[i];
  4637.                     }
  4638.                 }
  4639.             }
  4640.  
  4641.             return newOptions;
  4642.         },
  4643.  
  4644.         _prepareSlides: function(options)
  4645.         {
  4646.             //if its a mobile device find all video slides that need to be altered
  4647.             if(this.isMobile)
  4648.             {
  4649.                 var alter = this.$slider.find('.av-mobile-fallback-image');
  4650.                 alter.each(function()
  4651.                 {
  4652.                     var current  = $(this).removeClass('av-video-slide').data({'avia_video_events': true, 'video-ratio':0}),
  4653.                         fallback = current.data('mobile-img');
  4654.  
  4655.                     current.find('.av-click-overlay, .mejs-mediaelement, .mejs-container').remove();
  4656.  
  4657.                     if(!fallback)
  4658.                     {
  4659.                         var appendTo = current.find('.avia-slide-wrap');
  4660.                         $('<p class="av-fallback-message"><span>Please set a mobile device fallback image for this video in your wordpress backend</span></p>').appendTo(appendTo);
  4661.                     }
  4662.  
  4663.                     if(options && options.bg_slider)
  4664.                     {
  4665.                         current.data('img-url', fallback);
  4666.                     }
  4667.                     else
  4668.                     {
  4669.                         var image = $('<img src="'+fallback+'" alt="" title="" />');
  4670.                         current.find('.avia-slide-wrap').append(image);
  4671.                     }
  4672.  
  4673.                 });
  4674.             }
  4675.  
  4676.         },
  4677.  
  4678.         //start preloading the background images
  4679.         _bgPreloadImages : function(callback)
  4680.         {
  4681.             this._getImageURLS();
  4682.  
  4683.             this._preloadSingle(0, function()
  4684.             {
  4685.                 this._kickOff();
  4686.                 this._preloadNext(1);
  4687.             });
  4688.         },
  4689.  
  4690.         //if we are using a background image slider, fetch the images from a data attribute and preload them one by one
  4691.         _getImageURLS: function()
  4692.         {
  4693.             var _self = this;
  4694.  
  4695.             //collect url strings of the images to preload
  4696.             this.$slides.each(function(i)
  4697.             {
  4698.                 _self.imageUrls[i] = [];
  4699.                 _self.imageUrls[i]['url'] = $(this).data("img-url");
  4700.  
  4701.                 //if no image is passed we can set the slide to loaded
  4702.                 if(typeof _self.imageUrls[i]['url'] == 'string')
  4703.                 {
  4704.                     _self.imageUrls[i]['status'] = false;
  4705.                 }
  4706.                 else
  4707.                 {
  4708.                     _self.imageUrls[i]['status'] = true;
  4709.                 }
  4710.             });
  4711.         },
  4712.  
  4713.  
  4714.         _preloadSingle: function(key, callback)
  4715.         {
  4716.             var _self       = this,
  4717.                 objImage    = new Image();
  4718.  
  4719.             if(typeof _self.imageUrls[key]['url'] == 'string')
  4720.             {
  4721.                 $(objImage).bind('load error', function()
  4722.                 {
  4723.                     _self.imageUrls[key]['status'] = true;
  4724.                     _self.$slides.eq(key).css('background-image','url(' + _self.imageUrls[key]['url'] + ')');
  4725.                     if(typeof callback == 'function') callback.apply( _self, [objImage, key] );
  4726.                 });
  4727.  
  4728.                 if(_self.imageUrls[key]['url'] != "")
  4729.                 {
  4730.                     objImage.src = _self.imageUrls[key]['url'];
  4731.                 }
  4732.                 else
  4733.                 {
  4734.                     $(objImage).trigger('error');
  4735.                 }
  4736.             }
  4737.             else
  4738.             {
  4739.                 if(typeof callback == 'function') callback.apply( _self, [objImage, key] );
  4740.             }
  4741.         },
  4742.  
  4743.         _preloadNext: function(key)
  4744.         {
  4745.             if(typeof this.imageUrls[key] != "undefined")
  4746.             {
  4747.                 this._preloadSingle(key, function()
  4748.                 {
  4749.                     this._preloadNext(key + 1);
  4750.                 });
  4751.             }
  4752.         },
  4753.  
  4754.  
  4755.         //bind click events of slide controlls to the public functions
  4756.         _bindEvents: function()
  4757.         {
  4758.             var self = this,
  4759.                 win  = $( window );
  4760.  
  4761.             this.$slider.on('click','.next-slide', $.proxy( this.next, this) );
  4762.             this.$slider.on('click','.prev-slide', $.proxy( this.previous, this) );
  4763.             this.$slider.on('click','.goto-slide', $.proxy( this.go2, this) );
  4764.  
  4765.             if(this.options.hoverpause)
  4766.             {
  4767.                 this.$slider.on('mouseenter', $.proxy( this.pause, this) );
  4768.                 this.$slider.on('mouseleave', $.proxy( this.resume, this) );
  4769.             }
  4770.  
  4771.             if(this.options.stopinfiniteloop && this.options.autoplay)
  4772.             {
  4773.                 if(this.options.stopinfiniteloop == 'last')
  4774.                 {
  4775.                     this.$slider.on('avia_slider_last_slide', $.proxy(this._stopSlideshow, this) );
  4776.                 }
  4777.                 else if(this.options.stopinfiniteloop == 'first')
  4778.                 {
  4779.                     this.$slider.on('avia_slider_first_slide', $.proxy(this._stopSlideshow, this) );
  4780.                 }
  4781.             }
  4782.  
  4783.             win.on( 'debouncedresize.aviaSlider',  $.proxy( this._setSize, this) );
  4784.  
  4785.             //if its a desktop browser add arrow navigation, otherwise add touch nav
  4786.             if(!this.isMobile)
  4787.             {
  4788.                 this.$slider.avia_keyboard_controls();
  4789.             }
  4790.             else
  4791.             {
  4792.                 this.$slider.avia_swipe_trigger();
  4793.             }
  4794.  
  4795.             self._attach_video_events();
  4796.         },
  4797.  
  4798.         //kickoff the slider by binding all functions to slides and buttons, show the first slide and start autoplay
  4799.         _kickOff: function()
  4800.         {
  4801.             var self            = this,
  4802.                 first_slide     = self.$slides.eq(0),
  4803.                 video           = first_slide.data('video-ratio');
  4804.  
  4805.             // bind events to to the controll buttons
  4806.             self._bindEvents();
  4807.  
  4808.             this.$slider.removeClass('av-default-height-applied');
  4809.  
  4810.             //show the first slide. if its a video set the correct size, otherwise make sure to remove the % padding
  4811.             if(video)
  4812.             {
  4813.                 self._setSize(true);
  4814.             }
  4815.             else
  4816.             {
  4817.                 if(this.options.keep_pading != true)
  4818.                 {
  4819.                     self.$sliderUl.css('padding',0);
  4820.                     self.$win.trigger('av-height-change');
  4821.                 }
  4822.             }
  4823.  
  4824.             self._setCenter();
  4825.             first_slide.css({visibility:'visible', opacity:0}).avia_animate({opacity:1}, function()
  4826.             {
  4827.                 var current = $(this).addClass('active-slide');
  4828.  
  4829.                 if(self.permaCaption.length)
  4830.                 {
  4831.                     self.permaCaption.addClass('active-slide');
  4832.                 }
  4833.             });
  4834.  
  4835.  
  4836.  
  4837.             // start autoplay if active
  4838.             if( self.options.autoplay )
  4839.             {
  4840.                 self._startSlideshow();
  4841.             }
  4842.  
  4843.         },
  4844.  
  4845.         //calculate which slide should be displayed next and call the executing transition function
  4846.         _navigate : function( dir, pos ) {
  4847.  
  4848.             if( this.isAnimating || this.itemsCount < 2 || !this.$slider.is(":visible") )
  4849.             {
  4850.                 return false;
  4851.             }
  4852.  
  4853.             this.isAnimating = true;
  4854.  
  4855.             // current item's index
  4856.             this.prev = this.current;
  4857.  
  4858.             // if position is passed
  4859.             if( pos !== undefined )
  4860.             {
  4861.                 this.current = pos;
  4862.                 dir = this.current > this.prev ? 'next' : 'prev';
  4863.             }
  4864.             // if not check the boundaries
  4865.             else if( dir === 'next' )
  4866.             {
  4867.                 this.current = this.current < this.itemsCount - 1 ? this.current + 1 : 0;
  4868.  
  4869.                 if( this.current === 0 && this.options.autoplay_stopper == 1 && this.options.autoplay )
  4870.                 {
  4871.                     this.isAnimating = false;
  4872.                     this.current = this.prev;
  4873.                     this._stopSlideshow();
  4874.                     return false;
  4875.                 }
  4876.             }
  4877.             else if( dir === 'prev' )
  4878.             {
  4879.                 this.current = this.current > 0 ? this.current - 1 : this.itemsCount - 1;
  4880.             }
  4881.  
  4882.             //set goto button
  4883.             this.gotoButtons.removeClass('active').eq(this.current).addClass('active');
  4884.  
  4885.             //set slideshow size
  4886.             this._setSize();
  4887.  
  4888.             //if we are using a background slider make sure that the image is loaded. if not preload it, then show the slide
  4889.             if(this.options.bg_slider == true)
  4890.             {
  4891.                 if(this.imageUrls[this.current]['status'] == true )
  4892.                 {
  4893.                     this['_' + this.options.animation].call(this, dir);
  4894.                 }
  4895.                 else
  4896.                 {
  4897.                     this.loader.show();
  4898.                     this._preloadSingle(this.current, function()
  4899.                     {
  4900.                         this['_' + this.options.animation].call(this, dir);
  4901.                         this.loader.hide();
  4902.                     });
  4903.                 }
  4904.             }
  4905.             else //no background loader -> images are already loaded
  4906.             {
  4907.                 //call the executing function. for example _slide, or _fade. since the function call is absed on a var we can easily extend the slider with new animations
  4908.                 this['_' + this.options.animation].call(this, dir);
  4909.             }
  4910.  
  4911.             if(this.current == 0)
  4912.             {
  4913.                 this.loopCount++;
  4914.                 this.$slider.trigger('avia_slider_first_slide');
  4915.             }
  4916.             else if(this.current == this.itemsCount - 1)
  4917.             {
  4918.                 this.$slider.trigger('avia_slider_last_slide');
  4919.             }
  4920.             else
  4921.             {
  4922.                 this.$slider.trigger('avia_slider_navigate_slide');
  4923.             }
  4924.         },
  4925.  
  4926.         //if the next slide has a different height than the current change the slideshow height
  4927.         _setSize: function(instant)
  4928.         {
  4929.             //if images are attached as bg images the slider has a fixed height
  4930.             if(this.options.bg_slider == true) return;
  4931.  
  4932.             var self            = this,
  4933.                 slide           = this.$slides.eq(this.current),
  4934.                 img             = slide.find('img'),
  4935.                 current         = Math.floor(this.$sliderUl.height()),
  4936.                 ratio           = slide.data('video-ratio'),
  4937.                 setTo           = ratio ? this.$sliderUl.width() / ratio : Math.floor(slide.height()),
  4938.                 video_height    = slide.data('video-height'), //forced video height %. needs to be set only once
  4939.                 video_toppos    = slide.data('video-toppos'); //forced video top position
  4940.  
  4941.                 this.$sliderUl.height(current).css('padding',0); //make sure to set the slideheight to an actual value
  4942.  
  4943.                 if(setTo != current)
  4944.                 {
  4945.                     if(instant == true)
  4946.                     {
  4947.                         this.$sliderUl.css({height:setTo});
  4948.                         this.$win.trigger('av-height-change');
  4949.                     }
  4950.                     else
  4951.                     {
  4952.                         this.$sliderUl.avia_animate({height:setTo}, function()
  4953.                         {
  4954.                             self.$win.trigger('av-height-change');
  4955.                         });
  4956.                     }
  4957.                 }
  4958.  
  4959.                 this._setCenter();
  4960.  
  4961.                 if(video_height && video_height!= "set")
  4962.                 {
  4963.                     slide.find('iframe, embed, video, object, .av_youtube_frame').css({height: video_height + '%', top: video_toppos + '%'});
  4964.                     slide.data('video-height','set');
  4965.                 }
  4966.         },
  4967.  
  4968.         _setCenter: function()
  4969.         {
  4970.             //if the image has a min width and is larger than the slider center it
  4971.             //positon img based on caption. right caption->left pos, left caption -> right pos
  4972.             var slide       = this.$slides.eq(this.current),
  4973.                 img         = slide.find('img'),
  4974.                 min_width   = parseInt(img.css('min-width'),10),
  4975.                 slide_width = slide.width(),
  4976.                 caption     = slide.find('.av-slideshow-caption'),
  4977.                 css_left    = ((slide_width - min_width) / 2);
  4978.  
  4979.             if(caption.length)
  4980.             {
  4981.                 if(caption.is('.caption_left'))
  4982.                 {
  4983.                     css_left = ((slide_width - min_width) / 1.5);
  4984.                 }
  4985.                 else if(caption.is('.caption_right'))
  4986.                 {
  4987.                     css_left = ((slide_width - min_width) / 2.5);
  4988.                 }
  4989.             }
  4990.  
  4991.             if(slide_width >= min_width)
  4992.             {
  4993.                 css_left = 0;
  4994.             }
  4995.  
  4996.             img.css({left:css_left});
  4997.         },
  4998.  
  4999.         _slide: function(dir)
  5000.         {
  5001.             var dynamic         = false, //todo: pass by option if a slider is dynamic
  5002.                 modifier        = dynamic == true ? 2 : 1,
  5003.                 sliderWidth     = this.$slider.width(),
  5004.                 direction       = dir === 'next' ? -1 : 1,
  5005.                 property        = this.browserPrefix + 'transform',
  5006.                 reset           = {}, transition = {},  transition2 = {},
  5007.                 trans_val       = ( sliderWidth * direction * -1),
  5008.                 trans_val2      = ( sliderWidth * direction) / modifier;
  5009.  
  5010.             //do a css3 animation
  5011.             if(this.cssActive)
  5012.             {
  5013.                 property  = this.browserPrefix + 'transform';
  5014.  
  5015.                 //do a translate 3d transformation if available, since it uses hardware acceleration
  5016.                 if(this.css3DActive)
  5017.                 {
  5018.                     reset[property]  = "translate3d(" + trans_val + "px, 0, 0)";
  5019.                     transition[property]  = "translate3d(" + trans_val2 + "px, 0, 0)";
  5020.                     transition2[property] = "translate3d(0,0,0)";
  5021.                 }
  5022.                 else //do a 2d transform. still faster than a position "left" change
  5023.                 {
  5024.                     reset[property]  = "translate(" + trans_val + "px,0)";
  5025.                     transition[property]  = "translate(" + trans_val2 + "px,0)";
  5026.                     transition2[property] = "translate(0,0)";                   }
  5027.             }
  5028.             else
  5029.             {
  5030.                 reset.left = trans_val;
  5031.                 transition.left = trans_val2;
  5032.                 transition2.left = 0;
  5033.             }
  5034.  
  5035.             if(dynamic)
  5036.             {
  5037.                 transition['z-index']  = "1";
  5038.                 transition2['z-index']  = "2";
  5039.             }
  5040.  
  5041.             this._slide_animate(reset, transition, transition2);
  5042.         },
  5043.  
  5044.         _slide_up: function(dir)
  5045.         {
  5046.             var dynamic         = true, //todo: pass by option if a slider is dynamic
  5047.                 modifier        = dynamic == true ? 2 : 1,
  5048.                 sliderHeight    = this.$slider.height(),
  5049.                 direction       = dir === 'next' ? -1 : 1,
  5050.                 property        = this.browserPrefix + 'transform',
  5051.                 reset           = {}, transition = {},  transition2 = {},
  5052.                 trans_val       = ( sliderHeight * direction * -1),
  5053.                 trans_val2      = ( sliderHeight * direction) / modifier;
  5054.  
  5055.             //do a css3 animation
  5056.             if(this.cssActive)
  5057.             {
  5058.                 property  = this.browserPrefix + 'transform';
  5059.  
  5060.                 //do a translate 3d transformation if available, since it uses hardware acceleration
  5061.                 if(this.css3DActive)
  5062.                 {
  5063.                     reset[property]  = "translate3d( 0," + trans_val + "px, 0)";
  5064.                     transition[property]  = "translate3d( 0," + trans_val2 + "px, 0)";
  5065.                     transition2[property] = "translate3d(0,0,0)";
  5066.                 }
  5067.                 else //do a 2d transform. still faster than a position "left" change
  5068.                 {
  5069.                     reset[property]  = "translate( 0," + trans_val + "px)";
  5070.                     transition[property]  = "translate( 0," + trans_val2 + "px)";
  5071.                     transition2[property] = "translate(0,0)";                   }
  5072.             }
  5073.             else
  5074.             {
  5075.                 reset.top = trans_val;
  5076.                 transition.top = trans_val2;
  5077.                 transition2.top = 0;
  5078.             }
  5079.  
  5080.             if(dynamic)
  5081.             {
  5082.                 transition['z-index']  = "1";
  5083.                 transition2['z-index']  = "2";
  5084.             }
  5085.             this._slide_animate(reset, transition, transition2);
  5086.         },
  5087.  
  5088.  
  5089.         //slide animation: do a slide transition by css3 transform if possible. if not simply do a position left transition
  5090.         _slide_animate: function( reset , transition , transition2 )
  5091.         {
  5092.  
  5093.             var self            = this,
  5094.                 displaySlide    = this.$slides.eq(this.current),
  5095.                 hideSlide       = this.$slides.eq(this.prev);
  5096.  
  5097.                 hideSlide.trigger('pause');
  5098.                 if( !displaySlide.data('disableAutoplay') ) displaySlide.trigger('play');
  5099.  
  5100.                 displaySlide.css({visibility:'visible', zIndex:4, opacity:1, left:0, top:0});
  5101.                 displaySlide.css(reset);
  5102.  
  5103.                 hideSlide.avia_animate(transition, this.options.transitionSpeed, this.options.easing);
  5104.  
  5105.                 var after_slide = function()
  5106.                 {
  5107.                     self.isAnimating = false;
  5108.                     displaySlide.addClass('active-slide');
  5109.                     hideSlide.css({visibility:'hidden'}).removeClass('active-slide');
  5110.                     self.$slider.trigger('avia-transition-done');
  5111.                 }
  5112.  
  5113.                 if(self.options.show_slide_delay > 0)
  5114.                 {
  5115.                     setTimeout(function() { displaySlide.avia_animate(transition2, self.options.transitionSpeed, self.options.easing, after_slide); },self.options.show_slide_delay);
  5116.                 }
  5117.                 else
  5118.                 {
  5119.                     displaySlide.avia_animate(transition2, self.options.transitionSpeed, self.options.easing, after_slide);
  5120.                 }
  5121.  
  5122.         },
  5123.  
  5124.         //simple fade transition of the slideshow
  5125.         _fade: function()
  5126.         {
  5127.             var self            = this,
  5128.                 displaySlide    = this.$slides.eq(this.current),
  5129.                 hideSlide       = this.$slides.eq(this.prev),
  5130.                 properties      = {visibility:'visible', zIndex:3, opacity:0},
  5131.                 fadeCallback    = function()
  5132.                 {
  5133.                     self.isAnimating = false;
  5134.                     displaySlide.addClass('active-slide');
  5135.                     hideSlide.css({visibility:'hidden', zIndex:2}).removeClass('active-slide');
  5136.                     self.$slider.trigger('avia-transition-done');
  5137.  
  5138.                 };
  5139.  
  5140.             hideSlide.trigger('pause');
  5141.             if( !displaySlide.data('disableAutoplay') ) displaySlide.trigger('play');
  5142.  
  5143.             if(self.options.fullfade == true)
  5144.             {
  5145.                 hideSlide.avia_animate({opacity:0}, 200, 'linear', function()
  5146.                 {
  5147.                     displaySlide.css(properties).avia_animate({opacity:1}, self.options.transitionSpeed, 'linear',fadeCallback);
  5148.                 });
  5149.             }
  5150.             else
  5151.             {
  5152.                 displaySlide.css(properties).avia_animate({opacity:1}, self.options.transitionSpeed/2, 'linear', function()
  5153.                 {
  5154.                     hideSlide.avia_animate({opacity:0}, 200, 'linear', fadeCallback);
  5155.                 });
  5156.             }
  5157.  
  5158.         },
  5159.  
  5160.  
  5161.         /************************************************************************
  5162.         Video functions
  5163.         *************************************************************************/
  5164.  
  5165.         //bind events to the video that tell the slider to autorotate once a video has been played
  5166.         _attach_video_events: function()
  5167.         {
  5168.             var self = this, $html = $('html');
  5169.  
  5170.             self.$slides.each(function(i)
  5171.             {
  5172.                 var currentSlide    = $(this),
  5173.                     caption         = currentSlide.find('.caption_fullwidth, .av-click-overlay'),
  5174.                     mejs            = currentSlide.find('.mejs-mediaelement');
  5175.  
  5176.                 if(currentSlide.data('avia_video_events') != true)
  5177.                 {
  5178.                     currentSlide.data('avia_video_events', true);
  5179.  
  5180.                     currentSlide.on('av-video-events-bound', { slide: currentSlide, wrap: mejs , iteration: i , self: self }, onReady);
  5181.  
  5182.                     currentSlide.on('av-video-ended', { slide: currentSlide , self: self}, onFinish);
  5183.  
  5184.                     currentSlide.on('av-video-play-executed', function(){ setTimeout(function(){  self.pause() }, 100); });
  5185.  
  5186.                     caption.on('click', { slide: currentSlide }, toggle);
  5187.  
  5188.                     // also if the player was loaded before the _bindEvents function was bound trigger it manually
  5189.                     if(currentSlide.is('.av-video-events-bound')) currentSlide.trigger('av-video-events-bound');
  5190.                 }
  5191.             });
  5192.  
  5193.  
  5194.             //helper functions
  5195.             function onReady( event )
  5196.             {
  5197.                 //autostart for first slide
  5198.                 if(event.data.iteration === 0)
  5199.                 {
  5200.                     event.data.wrap.css('opacity',0);
  5201.                     if(!event.data.self.isMobile && !event.data.slide.data('disableAutoplay')) { event.data.slide.trigger('play'); } 
  5202.                     setTimeout(function(){ event.data.wrap.avia_animate({opacity:1}, 400); }, 50);
  5203.                 }
  5204.                 else if ($html.is('.avia-msie') && !event.data.slide.is('.av-video-service-html5'))
  5205.                 {
  5206.                     /*
  5207.                     * Internet Explorer fires the ready event for external videos once they become visible
  5208.                     * as oposed to other browsers which always fire immediately.
  5209.                     */
  5210.                     if( !event.data.slide.data('disableAutoplay') ) event.data.slide.trigger('play');
  5211.                 }
  5212.  
  5213.             }
  5214.  
  5215.  
  5216.  
  5217.  
  5218.             function onFinish( event )
  5219.             {
  5220.                 //if the video is not looped resume the slideshow
  5221.                 if(!event.data.slide.is('.av-single-slide') && !event.data.slide.is('.av-loop-video'))
  5222.                 {
  5223.                     event.data.slide.trigger('reset');
  5224.                     self._navigate( 'next' );
  5225.                     self.resume();
  5226.                 }
  5227.  
  5228.                 //safari 8 workaround for self hosted videos which wont loop by default
  5229.                 if(event.data.slide.is('.av-loop-video') && event.data.slide.is('.av-video-service-html5'))
  5230.                 {
  5231.                     if($html.is('.avia-safari-8'))
  5232.                     {
  5233.                         setTimeout(function(){ event.data.slide.trigger('play'); },1);
  5234.                     }
  5235.                 }
  5236.             }
  5237.  
  5238.             function toggle( event )
  5239.             {
  5240.                 if(event.target.tagName != "A")
  5241.                 {
  5242.                     event.data.slide.trigger('toggle');
  5243.                 }
  5244.             }
  5245.  
  5246.         },
  5247.  
  5248.  
  5249.  
  5250.         /************************************************************************
  5251.         Slideshow control functions
  5252.         *************************************************************************/
  5253.  
  5254.         _timer: function(callback, delay, first)
  5255.         {
  5256.             var self = this, start, remaining = delay;
  5257.  
  5258.             self.timerId = 0;
  5259.  
  5260.             this.pause = function() {
  5261.                 window.clearTimeout(self.timerId);
  5262.                 remaining -= new Date() - start;
  5263.             };
  5264.  
  5265.             this.resume = function() {
  5266.                 start = new Date();
  5267.                 self.timerId = window.setTimeout(callback, remaining);
  5268.             };
  5269.  
  5270.             this.destroy = function()
  5271.             {
  5272.                 window.clearTimeout(self.timerId);
  5273.             };
  5274.  
  5275.             this.resume(true);
  5276.         },
  5277.  
  5278.         //start autorotation
  5279.         _startSlideshow: function()
  5280.         {
  5281.             var self = this;
  5282.  
  5283.             this.isPlaying = true;
  5284.  
  5285.             this.slideshow = new this._timer( function()
  5286.             {
  5287.                 /*
  5288.                 var videoApi = self.$slides.eq(self.current).data('aviaVideoApi')
  5289.                 if(!videoApi){}
  5290.                 */
  5291.  
  5292.                 self._navigate( 'next' );
  5293.  
  5294.                 if ( self.options.autoplay )
  5295.                 {
  5296.                     self._startSlideshow();
  5297.                 }
  5298.  
  5299.             }, (this.options.interval * 1000));
  5300.         },
  5301.  
  5302.         //stop autorotation
  5303.         _stopSlideshow: function()
  5304.         {
  5305.             if ( this.options.autoplay ) {
  5306.  
  5307.                 this.slideshow.destroy();
  5308.                 this.isPlaying = false;
  5309.                 this.options.autoplay = false;
  5310.             }
  5311.         },
  5312.  
  5313.         // public method: shows next image
  5314.         next : function(e)
  5315.         {
  5316.             e.preventDefault();
  5317.             this._stopSlideshow();
  5318.             this._navigate( 'next' );
  5319.         },
  5320.  
  5321.         // public method: shows previous image
  5322.         previous : function(e)
  5323.         {
  5324.             e.preventDefault();
  5325.             this._stopSlideshow();
  5326.             this._navigate( 'prev' );
  5327.         },
  5328.  
  5329.         // public method: goes to a specific image
  5330.         go2 : function( pos )
  5331.         {
  5332.             //if we didnt pass a number directly lets asume someone clicked on a link that triggered the goto transition
  5333.             if(isNaN(pos))
  5334.             {
  5335.                 //in that case prevent the default link behavior and set the slide number to the links hash
  5336.                 pos.preventDefault();
  5337.                 pos = pos.currentTarget.hash.replace('#','');
  5338.             }
  5339.  
  5340.             pos -= 1;
  5341.  
  5342.             if( pos === this.current || pos >= this.itemsCount || pos < 0 )
  5343.             {
  5344.                 return false;
  5345.             }
  5346.  
  5347.             this._stopSlideshow();
  5348.             this._navigate( false, pos );
  5349.  
  5350.         },
  5351.  
  5352.         // public method: starts the slideshow
  5353.         // any call to next(), previous() or goto() will stop the slideshow autoplay
  5354.         play : function()
  5355.         {
  5356.             if( !this.isPlaying )
  5357.             {
  5358.                 this.isPlaying = true;
  5359.  
  5360.                 this._navigate( 'next' );
  5361.                 this.options.autoplay = true;
  5362.                 this._startSlideshow();
  5363.             }
  5364.  
  5365.         },
  5366.  
  5367.         // public methos: pauses the slideshow
  5368.         pause : function()
  5369.         {
  5370.             if( this.isPlaying )
  5371.             {
  5372.                 this.slideshow.pause();
  5373.             }
  5374.         },
  5375.  
  5376.         // publiccmethos: resumes the slideshow
  5377.         resume : function()
  5378.         {
  5379.             if( this.isPlaying )
  5380.             {
  5381.                 this.slideshow.resume();
  5382.             }
  5383.         },
  5384.  
  5385.         // public methos: destroys the instance
  5386.         destroy : function( callback )
  5387.         {
  5388.             this.slideshow.destroy( callback );
  5389.         }
  5390.  
  5391.     }
  5392.  
  5393.     //simple wrapper to call the slideshow. makes sure that the slide data is not applied twice
  5394.     $.fn.aviaSlider = function( options )
  5395.     {
  5396.         return this.each(function()
  5397.         {
  5398.             var self = $.data( this, 'aviaSlider' );
  5399.  
  5400.             if(!self)
  5401.             {
  5402.                 self = $.data( this, 'aviaSlider', new $.AviaSlider( options, this ) );
  5403.             }
  5404.         });
  5405.     }
  5406.  
  5407.  
  5408.  
  5409. })( jQuery );
  5410.  
  5411.  
  5412.  
  5413.  
  5414. // -------------------------------------------------------------------------------------------
  5415. // keyboard controls
  5416. // -------------------------------------------------------------------------------------------
  5417.  
  5418. (function($)
  5419. {
  5420.     "use strict";
  5421.  
  5422.     /************************************************************************
  5423.     keyboard arrow nav
  5424.     *************************************************************************/
  5425.     $.fn.avia_keyboard_controls = function(options_passed)
  5426.     {
  5427.         var defaults    =
  5428.         {
  5429.             37: '.prev-slide',  // prev
  5430.             39: '.next-slide'   // next
  5431.         },
  5432.  
  5433.         methods     = {
  5434.  
  5435.             mousebind: function(slider)
  5436.             {
  5437.                 slider.hover(
  5438.                     function(){  slider.mouseover   = true;  },
  5439.                     function(){  slider.mouseover   = false; }
  5440.                 );
  5441.             },
  5442.  
  5443.             keybind: function(slider)
  5444.             {
  5445.                 $(document).keydown(function(e)
  5446.                 {
  5447.                     if(slider.mouseover && typeof slider.options[e.keyCode] !== 'undefined')
  5448.                     {
  5449.                         var item;
  5450.  
  5451.                         if(typeof slider.options[e.keyCode] === 'string')
  5452.                         {
  5453.                             item = slider.find(slider.options[e.keyCode]);
  5454.                         }
  5455.                         else
  5456.                         {
  5457.                             item = slider.options[e.keyCode];
  5458.                         }
  5459.  
  5460.                         if(item.length)
  5461.                         {
  5462.                             item.trigger('click', ['keypress']);
  5463.                             return false;
  5464.                         }
  5465.                     }
  5466.                 });
  5467.             }
  5468.         };
  5469.  
  5470.  
  5471.         return this.each(function()
  5472.         {
  5473.             var slider          = $(this);
  5474.             slider.options      = $.extend({}, defaults, options_passed);
  5475.             slider.mouseover    = false;
  5476.  
  5477.             methods.mousebind(slider);
  5478.             methods.keybind(slider);
  5479.  
  5480.         });
  5481.     };
  5482.  
  5483.  
  5484.     /************************************************************************
  5485.     swipe nav
  5486.     *************************************************************************/
  5487.     $.fn.avia_swipe_trigger = function(passed_options)
  5488.     {
  5489.         var win     = $(window),
  5490.         isMobile    = $.avia_utilities.isMobile,
  5491.         defaults    =
  5492.         {
  5493.             prev: '.prev-slide',
  5494.             next: '.next-slide',
  5495.             event: {
  5496.                 prev: 'click',
  5497.                 next: 'click'
  5498.             }
  5499.         },
  5500.  
  5501.         methods = {
  5502.  
  5503.             activate_touch_control: function(slider)
  5504.             {
  5505.                 var i, differenceX, differenceY;
  5506.  
  5507.                 slider.touchPos = {};
  5508.                 slider.hasMoved = false;
  5509.  
  5510.                 slider.on('touchstart', function(event)
  5511.                 {
  5512.                     slider.touchPos.X = event.originalEvent.touches[0].clientX;
  5513.                     slider.touchPos.Y = event.originalEvent.touches[0].clientY;
  5514.                 });
  5515.  
  5516.                 slider.on('touchend', function(event)
  5517.                 {
  5518.                     slider.touchPos = {};
  5519.                     if(slider.hasMoved) { event.preventDefault(); }
  5520.                     slider.hasMoved = false;
  5521.                 });
  5522.  
  5523.                 slider.on('touchmove', function(event)
  5524.                 {
  5525.                     if(!slider.touchPos.X)
  5526.                     {
  5527.                         slider.touchPos.X = event.originalEvent.touches[0].clientX;
  5528.                         slider.touchPos.Y = event.originalEvent.touches[0].clientY;
  5529.                     }
  5530.                     else
  5531.                     {
  5532.                         differenceX = event.originalEvent.touches[0].clientX - slider.touchPos.X;
  5533.                         differenceY = event.originalEvent.touches[0].clientY - slider.touchPos.Y;
  5534.  
  5535.                         //check if user is scrolling the window or moving the slider
  5536.                         if(Math.abs(differenceX) > Math.abs(differenceY))
  5537.                         {
  5538.                             event.preventDefault();
  5539.  
  5540.                             if(slider.touchPos !== event.originalEvent.touches[0].clientX)
  5541.                             {
  5542.                                 if(Math.abs(differenceX) > 50)
  5543.                                 {
  5544.                                     i = differenceX > 0 ? 'prev' : 'next';
  5545.  
  5546.                                     if(typeof slider.options[i] === 'string')
  5547.                                     {
  5548.                                         slider.find(slider.options[i]).trigger(slider.options.event[i], ['swipe']);
  5549.                                     }
  5550.                                     else
  5551.                                     {
  5552.                                         slider.options[i].trigger(slider.options.event[i], ['swipe']);
  5553.                                     }
  5554.  
  5555.                                     slider.hasMoved = true;
  5556.                                     slider.touchPos = {};
  5557.                                     return false;
  5558.                                 }
  5559.                             }
  5560.                         }
  5561.                     }
  5562.                 });
  5563.             }
  5564.         };
  5565.  
  5566.         return this.each(function()
  5567.         {
  5568.             if(isMobile)
  5569.             {
  5570.                 var slider  = $(this);
  5571.  
  5572.                 slider.options  = $.extend({}, defaults, passed_options);
  5573.  
  5574.                 methods.activate_touch_control(slider);
  5575.             }
  5576.         });
  5577.     };
  5578.  
  5579.  
  5580.  
  5581.  
  5582.  
  5583.  
  5584.  
  5585.  
  5586.  
  5587.  
  5588.  
  5589.  
  5590.  
  5591. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement