Advertisement
Guest User

shortcodes.js

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