(function (factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    define(['jquery'], function ($) {
      return factory($);
    });
  } else if (typeof module === 'object' && typeof module.exports === 'object') {
    // Node-like environment
    module.exports = factory(require('jquery'));
  } else {
    // Browser globals
    factory(window.jQuery);
  }
}(function(jQuery) {
  "use strict";

  function uaMatch( ua ) {
    // If an UA is not provided, default to the current browser UA.
    if ( ua === undefined ) {
      ua = window.navigator.userAgent;
    }
    ua = ua.toLowerCase();

    var match = /(edge)\/([\w.]+)/.exec( ua ) ||
        /(opr)[\/]([\w.]+)/.exec( ua ) ||
        /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
        /(iemobile)[\/]([\w.]+)/.exec( ua ) ||
        /(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
        /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
        /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
        /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
        /(msie) ([\w.]+)/.exec( ua ) ||
        ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) ||
        ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
        [];

    var platform_match = /(ipad)/.exec( ua ) ||
        /(ipod)/.exec( ua ) ||
        /(windows phone)/.exec( ua ) ||
        /(iphone)/.exec( ua ) ||
        /(kindle)/.exec( ua ) ||
        /(silk)/.exec( ua ) ||
        /(android)/.exec( ua ) ||
        /(win)/.exec( ua ) ||
        /(mac)/.exec( ua ) ||
        /(linux)/.exec( ua ) ||
        /(cros)/.exec( ua ) ||
        /(playbook)/.exec( ua ) ||
        /(bb)/.exec( ua ) ||
        /(blackberry)/.exec( ua ) ||
        [];

    var browser = {},
        matched = {
          browser: match[ 5 ] || match[ 3 ] || match[ 1 ] || "",
          version: match[ 2 ] || match[ 4 ] || "0",
          versionNumber: match[ 4 ] || match[ 2 ] || "0",
          platform: platform_match[ 0 ] || ""
        };

    if ( matched.browser ) {
      browser[ matched.browser ] = true;
      browser.version = matched.version;
      browser.versionNumber = parseInt(matched.versionNumber, 10);
    }

    if ( matched.platform ) {
      browser[ matched.platform ] = true;
    }

    // These are all considered mobile platforms, meaning they run a mobile browser
    if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone ||
      browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) {
      browser.mobile = true;
    }

    // These are all considered desktop platforms, meaning they run a desktop browser
    if ( browser.cros || browser.mac || browser.linux || browser.win ) {
      browser.desktop = true;
    }

    // Chrome, Opera 15+ and Safari are webkit based browsers
    if ( browser.chrome || browser.opr || browser.safari ) {
      browser.webkit = true;
    }

    // IE11 has a new token so we will assign it msie to avoid breaking changes
    if ( browser.rv || browser.iemobile) {
      var ie = "msie";

      matched.browser = ie;
      browser[ie] = true;
    }

    // Edge is officially known as Microsoft Edge, so rewrite the key to match
    if ( browser.edge ) {
      delete browser.edge;
      var msedge = "msedge";

      matched.browser = msedge;
      browser[msedge] = true;
    }

    // Blackberry browsers are marked as Safari on BlackBerry
    if ( browser.safari && browser.blackberry ) {
      var blackberry = "blackberry";

      matched.browser = blackberry;
      browser[blackberry] = true;
    }

    // Playbook browsers are marked as Safari on Playbook
    if ( browser.safari && browser.playbook ) {
      var playbook = "playbook";

      matched.browser = playbook;
      browser[playbook] = true;
    }

    // BB10 is a newer OS version of BlackBerry
    if ( browser.bb ) {
      var bb = "blackberry";

      matched.browser = bb;
      browser[bb] = true;
    }

    // Opera 15+ are identified as opr
    if ( browser.opr ) {
      var opera = "opera";

      matched.browser = opera;
      browser[opera] = true;
    }

    // Stock Android browsers are marked as Safari on Android.
    if ( browser.safari && browser.android ) {
      var android = "android";

      matched.browser = android;
      browser[android] = true;
    }

    // Kindle browsers are marked as Safari on Kindle
    if ( browser.safari && browser.kindle ) {
      var kindle = "kindle";

      matched.browser = kindle;
      browser[kindle] = true;
    }

     // Kindle Silk browsers are marked as Safari on Kindle
    if ( browser.safari && browser.silk ) {
      var silk = "silk";

      matched.browser = silk;
      browser[silk] = true;
    }

    // Assign the name and platform variable
    browser.name = matched.browser;
    browser.platform = matched.platform;

    return browser;
  }

  // Run the matching process, also assign the function to the returned object
  // for manual, jQuery-free use if desired
  window.jQBrowser = uaMatch( window.navigator.userAgent );
  window.jQBrowser.uaMatch = uaMatch;

  // Only assign to jQuery.browser if jQuery is loaded
  if ( jQuery ) {
    jQuery.browser = window.jQBrowser;
  }

  

  return window.jQBrowser;
}));


/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
  def: 'easeOutQuad',
  swing: function (x, t, b, c, d) {
    //alert(jQuery.easing.default);
    return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
  },
  easeInQuad: function (x, t, b, c, d) {
    return c*(t/=d)*t + b;
  },
  easeOutQuad: function (x, t, b, c, d) {
    return -c *(t/=d)*(t-2) + b;
  },
  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;
  },
  easeInCubic: function (x, t, b, c, d) {
    return c*(t/=d)*t*t + b;
  },
  easeOutCubic: function (x, t, b, c, d) {
    return c*((t=t/d-1)*t*t + 1) + b;
  },
  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;
  },
  easeInQuart: function (x, t, b, c, d) {
    return c*(t/=d)*t*t*t + b;
  },
  easeOutQuart: function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
  },
  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;
  },
  easeInQuint: function (x, t, b, c, d) {
    return c*(t/=d)*t*t*t*t + b;
  },
  easeOutQuint: function (x, t, b, c, d) {
    return c*((t=t/d-1)*t*t*t*t + 1) + b;
  },
  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;
  },
  easeInSine: function (x, t, b, c, d) {
    return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
  },
  easeOutSine: function (x, t, b, c, d) {
    return c * Math.sin(t/d * (Math.PI/2)) + b;
  },
  easeInOutSine: function (x, t, b, c, d) {
    return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
  },
  easeInExpo: function (x, t, b, c, d) {
    return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
  },
  easeOutExpo: function (x, t, b, c, d) {
    return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
  },
  easeInOutExpo: function (x, t, b, c, d) {
    if (t==0) return b;
    if (t==d) return b+c;
    if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
    return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
  },
  easeInCirc: function (x, t, b, c, d) {
    return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
  },
  easeOutCirc: function (x, t, b, c, d) {
    return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
  },
  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;
  },
  easeInElastic: function (x, t, b, c, d) {
    var s=1.70158;var p=0;var a=c;
    if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
    if (a < Math.abs(c)) { a=c; var s=p/4; }
    else var s = p/(2*Math.PI) * Math.asin (c/a);
    return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  },
  easeOutElastic: function (x, t, b, c, d) {
    var s=1.70158;var p=0;var a=c;
    if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
    if (a < Math.abs(c)) { a=c; var s=p/4; }
    else var s = p/(2*Math.PI) * Math.asin (c/a);
    return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
  },
  easeInOutElastic: function (x, t, b, c, d) {
    var s=1.70158;var p=0;var a=c;
    if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
    if (a < Math.abs(c)) { a=c; var s=p/4; }
    else var s = p/(2*Math.PI) * Math.asin (c/a);
    if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
    return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
  },
  easeInBack: function (x, t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    return c*(t/=d)*t*((s+1)*t - s) + b;
  },
  easeOutBack: function (x, t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
  },
  easeInOutBack: function (x, t, b, c, d, s) {
    if (s == undefined) s = 1.70158; 
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
  },
  easeInBounce: function (x, t, b, c, d) {
    return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
  },
  easeOutBounce: function (x, t, b, c, d) {
    if ((t/=d) < (1/2.75)) {
      return c*(7.5625*t*t) + b;
    } else if (t < (2/2.75)) {
      return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
    } else if (t < (2.5/2.75)) {
      return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
    } else {
      return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
    }
  },
  easeInOutBounce: function (x, t, b, c, d) {
    if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
    return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
  }
});


(function($, window, document) {


  	var device_data = jQBrowser.uaMatch();

  	window.config = {
  		os : {
  			name            : device_data.platform
  		},
      device:{
        desktop         : device_data.desktop,
        mobile          : device_data.mobile           // value : true or unefined
      }, 
  		browser : {
  			name 			      : device_data.name,
  			version		      : device_data.versionNumber,
        version_full    : device_data.version
  		},
      win : {
        scroll:{
          enabled       : true,
          prevent       : false,
          project_down            : 0,
          project_up              : 0,
          project_prevent         : false,
          project_prevent_time    : 700,
          project_prevent_fx_time : 700,
          up            : 0,
          down          : 0,
          x             : 0,
          y             : 0 
        }                        
      },
  		block : {
  			footer: {
  				stick: {
  					active:true			
  				}
  			}
  		},
      plugin : {
        slide_to:{
          speed         : 750,
          easing        : 'easeInOutCubic' // linear or easings.net
        }
      },
      grid : {

          xxs           : 0,
          xs            : 400,
          sm            : 500,
          md            : 700,
          lg            : 900,
          xl            : 1200,
          xxl           : 1300,
          xxxl          : 1500,
          vl            : 1700,
          xvl           : 1900,
          xxvl          : 2200,
          xxxvl         : 2500,
          kl            : 3000,
          xkl           : 3400,
          xxkl          : 3700,
          xxxkl         : 4000,

          xxs_max       : 399,
          xs_max        : 499,
          sm_max        : 699,
          md_max        : 899,
          lg_max        : 1199,
          xl_max        : 1299,
          xxl_max       : 1499,
          xxxl_max      : 1699,
          vl_max        : 1899,
          xvl_max       : 2199,
          xxvl_max      : 2499,
          xxxvl_max     : 2999,
          kl_max        : 3399,
          xkl_max       : 3699,
          xxkl_max      : 3999

      }
  		
  	}; // end of config



    window.device_test = function(){
      /*console.log('--------------------------------------------------------------------');
      console.log('config.os.name                        :'+config.os.name);
      console.log('config.os.desktop                     :'+config.os.desktop);
      console.log('config.browser.name                   :'+config.browser.name);
      console.log('config.browser.version_full           :'+config.browser.version_full);
      console.log('config.browser.version                :'+config.browser.version);
      console.log('--------------------------------------------------------------------');*/

      $('body').attr('data-browser-name',config.browser.name);
      $('body').attr('data-browser-version-full',config.browser.version_full);
      $('body').attr('data-browser-version',config.browser.version);
    }; 


  	
    window.calc = function(){
        

        var win_height        = $(window).height();
        var doc_height        = $(document).height();
        var win_width         = Math.max( $(window).width(), window.innerWidth);
        var header_height     = $("header").outerHeight();
        var container_height  = $(".maincontainer").outerHeight();
        var footer_height     = $("footer").outerHeight();
        
        $('#p_slider_w4').css({'height':win_height+'px','width':win_width+'px'});
        $('.p_slider').css({'height':win_height+'px','width':win_width+'px'});


        if ( $('.section_slide_preview').length ){
            var preview_box             = $('.section_slide_preview .ct_c');
            var preview_box_w           = preview_box.outerWidth();
            var preview_box_h           = preview_box.outerHeight();
            var preview_box_inner       = $('.preview_p_slide_box_m_m_inner');
            var preview_box_inner_w     = preview_box_inner.outerWidth();
            var preview_box_inner_h     = preview_box_inner.outerHeight();
            var preview_scale           = Math.min( preview_box_w / preview_box_inner_w, preview_box_h / preview_box_inner_h );

            $('body').attr('data-preview-scale',preview_scale);

            $('.preview_p_slide_box_m').each(function(){
                  var slide_preview_height = preview_scale*600;
                  if ( win_height > (slide_preview_height + header_height + footer_height) ){
                      $(this).css('height', win_height-header_height-footer_height-2 + 'px');
                  }
                  else {
                      $(this).css('height', preview_scale*600 + 'px');
                  };
          });

        };


        $('.maincontainer').each(function(){
            if ( $(this).find('.preview_p_slide_box_m_m_inner').length ){
                /*var slide_preview_height = ($('body').attr('data-preview-scale')*600);
                if ( win_height > (slide_preview_height + header_height + footer_height) ){
                    $(this).css('height', win_height-header_height-footer_height-2 + 'px');
                };*/
            }else{
                $(this).css('height', win_height - $(this).parent().find('header').outerHeight() - $(this).parent().find('footer').outerHeight() - 2 + 'px');
            }; 
        });


        if ( config.browser.name == "msie" || config.browser.name == "msedge" ){
            $('.slimscroll_w5').each(function(){
                    if ( $('#wrapper').outerHeight() > win_height ){
                        $('.ct_ct_a').css({'height':$('#wrapper').outerHeight()+'px'});
                        var slimscroll_w5_height = $(this).parent().parent().innerHeight();
                        $(this).css({'height': slimscroll_w5_height + 'px'});
                    }else{
                        $('.ct_ct_a').css({'height':win_height+'px'});
                        var slimscroll_w5_height = $(this).parent().parent().innerHeight();
                        $(this).css({'height': slimscroll_w5_height + 'px'});
                    };
            });
        };


    };  


    window.widgets = function(){

        $('.widget_btn').on('click',function(){

            var data_widget = $(this).attr('data-widget');

            $('.widget_btn:not([data-widget="'+data_widget+'"])').removeClass('active');
            $('.widget_box:not([data-widget="'+data_widget+'"])').removeClass('active');
            $('.widget_box:not([data-widget="'+data_widget+'"])').slideUp({ duration:  500, easing: 'easeInOutCubic' });

            //console.log('data_widget : '+data_widget);

            if( $('.widget_btn[data-widget="'+data_widget+'"]').hasClass('active') ){

                $('.widget_btn[data-widget="'+data_widget+'"]').removeClass('active');
                $('.widget_box[data-widget="'+data_widget+'"]').removeClass('active');
                $('.widget_box[data-widget="'+data_widget+'"]').slideUp({ duration:  500, easing: 'easeInOutCubic' });
            
            }else{

                $('.widget_btn[data-widget="'+data_widget+'"]').addClass('active');
                $('.widget_box[data-widget="'+data_widget+'"]').addClass('active');
                $('.widget_box[data-widget="'+data_widget+'"]').slideDown({ duration:  500, easing: 'easeInOutCubic' });

            };

        });

    };


    window.s_width = function(){

        var s_width_1 = 0;
        
        if ( $('.s_width_1').length ){
            $('.s_width_1').css({'min-width':'10px'});

            setTimeout(function(){

              $('.s_width_1').each(function(index, el) {

                //console.log('index: '+$(this).index()+' outer width '+$(this).outerWidth());

                if ( ($(this).outerWidth()) > s_width_1){
                  s_width_1 = ($(this).outerWidth());
                };
              });

              $('.s_width_1').css({'min-width':s_width_1+'px'});
            },310);
        };

        var s_width_2 = 0;
        
        if ( $('.s_width_2').length ){
            $('.s_width_2').css({'min-width':'10px'});

            setTimeout(function(){

              $('.s_width_2').each(function(index, el) {

                //console.log('index: '+$(this).index()+' outer width '+$(this).outerWidth());

                if ( ($(this).outerWidth()) > s_width_2){
                  s_width_2 = ($(this).outerWidth());
                };
              });

              $('.s_width_2').css({'min-width':s_width_2+'px'});
            },310);
        };

    };

    window.s_height = function(){

      var s_height_table = 0;
      
      if ( $('.s_height_table').length ){
          $('.s_height_table').css({'height':'10px'});

          setTimeout(function(){

            $('.s_height_table').each(function(index, el) {

              //console.log('index: '+$(this).index()+' outer width '+$(this).outerWidth());

              if ( ($(this).outerHeight()) > s_height_table){
                s_height_table = ($(this).outerHeight());
              };
            });

            $('.s_height_table').css({'height':s_height_table+'px'});
          },310);
      };

    };



    window.event_toggle = function(){

        if ( $('.btn_event_toggle').length ){


            $('.event_box_top').on('click',function(){

                if ( $(this).parent().hasClass('hide_desc') ){
                    $(this).parent().removeClass('hide_desc');
                } else {
                    $(this).parent().addClass('hide_desc');
                };

            });      


            $('.btn_event_toggle').on('click',function(){

                if ( $(this).hasClass('hide') ){
                    $('.btn_event_toggle').removeClass('hide');
                    $('.event_box').removeClass('hide_desc');
                } else {
                    $('.btn_event_toggle').addClass('hide');
                    $('.event_box').addClass('hide_desc');
                };

            });          

        };

    };



    window.comment_rate = function(){

        if ( $('.comment_rate_wrapper').length ){


            var rate_hover = '';
            var rate_active = '';

            $('.comment_rate_wrapper .rate').on('mouseenter',function(){

                rate_hover = $(this).index();
                $(this).parent().attr('data-rate-hover',rate_hover);

            }).on('mouseleave',function(){

                $(this).parent().attr('data-rate-hover','');

            }).on('click',function(){

                rate_active = $(this).index();
                $(this).parent().attr('data-rate-active',rate_active);

            });

        };

    };


    window.scrollpage = function(step, speed, easing) {
          
          var $document = $(document),
              $window = $(window),
              $body = $('html, body'),
              option = easing || 'default',
              root =  $(window).scrollTop(), //pageYOffset, //0,  fix Chrome
              scroll = false,
              scrollY,
              scrollX,
              view;
              
          if (window.navigator.msPointerEnabled)
          
              return false;
              
          $window.on('mousewheel DOMMouseScroll', function(e) {
              
              var deltaY = e.originalEvent.wheelDeltaY,
                  detail = e.originalEvent.detail;
                  scrollY = $document.height() > $window.height();
                  scrollX = $document.width() > $window.width();
                  scroll = true;
              
              if (scrollY) {
                  
                  view = $window.height();
                      
                  if (deltaY < 0 || detail > 0)
                      root = (root + view) >= $document.height() ? root : root += step;
                  
                  if (deltaY > 0 || detail < 0)
                      root = root <= 0 ? 0 : root -= step;
                  
                  $body.stop().animate({
              
                      scrollTop: root
                  
                  }, speed, option, function() {
              
                      scroll = false;
                  
                  });
              }
              
              if (scrollX) {
                  
                  view = $window.width();
                      
                  if (deltaY < 0 || detail > 0)
                      root = (root + view) >= $document.width() ? root : root += step;
                  if (deltaY > 0 || detail < 0)
                      root = root <= 0 ? 0 : root -= step;
            
                  $body.stop().animate({
                      scrollLeft: root
                  }, speed, option, function() {
                      scroll = false;
                  });
              }
              
              return false;
              
          }).on('scroll', function() {
              
              if (scrollY && !scroll) root = $window.scrollTop();
              if (scrollX && !scroll) root = $window.scrollLeft();
              
          }).on('resize', function() {
              
              if (scrollY && !scroll) view = $window.height();
              if (scrollX && !scroll) view = $window.width();
              
          });       
    };
      

    $.easing.default = function (x,t,b,c,d) {
    
        return -c * ((t=t/d-1)*t*t*t - 1) + b;
    };


    window.window_height = function(){

        var win_height        = $(window).height();
        var win_width         = Math.max( $(window).width(), window.innerWidth);
        $('.fn_window_height').css('height', win_height + 'px');   
      
    };  


    window.window_height_relative = function(){

        var win_height          = $(window).height();
        var doc_height          = $(document).height();
        var win_height_relative = Math.max( win_height, doc_height);
        $('.fn_window_height_relative').css('height', win_height_relative + 'px');   

    };  


    window.min_height_16x9 = function(){

        $('.min_height_16x9').each(function(){
            var e_width       = $(this).outerWidth();
            var e_min_height  = Math.round((e_width/16)*9);
            $(this).css('min-height', e_min_height + 'px');  
        });

    }; 


    window.height_16x9 = function(){

        $('.height_16x9').each(function(){
            var e_width       = $(this).outerWidth();
            var e_height      = Math.round((e_width/16)*9);
            $(this).css('height', e_height + 'px');  
        });

    }; 


    window.height_15x10 = function(){

        $('.height_15x10').each(function(){
            var e_width       = $(this).outerWidth();
            var e_height      = Math.round((e_width/16)*9);
            $(this).css('height', e_height + 'px');  
        });

    };  


    window.project_part_slider_box = function(){

        $('.project_part_slider_box').each(function(){
            var e_width       = $(this).outerWidth();
            var e_height      = Math.round((e_width/15)*10);
            $(this).css('height', e_height + 'px');  
            $(this).find('img').css({'max-height':(e_height-2) + 'px'});
        });

        $('.project_part_slider_thumb').each(function(){
            var et_width       = $(this).outerWidth();
            var et_height      = Math.round((et_width/15)*10);
            $(this).css('height', et_height + 'px');  
            $(this).find('img').css({'max-height':(et_height-2) + 'px'});
        });

    };  


    window.slide_to = function(){

        $('*[data-slide-to]').on('click',function(){

            if( $('html[data-page-scroll]').length ){
              $('html').attr("data-page-scroll","enabled");
              $('html').attr("data-page-scroll-down","2");
              $(".section_featured_info .ct_ct").animate({opacity:0},400,"easeInOutCubic", function() {});
              $(".section_featured_info .section_featured_info_ov").animate({opacity:0.2},400,"easeInOutCubic", function() {});
            };

            // avaliable html attributes : data-slide-to-easing="linear" data-slide-to-speed="4000"

            var slide_to        = $(this).attr('data-slide-to');
            var slide_to_speed  = 0;
            var slide_to_easing = 0;
            var win_width       = Math.max( $(window).width(), window.innerWidth);
            var header_height   = $("header").outerHeight();
           

            if ( $(this).is("[data-slide-to-speed]") ){
              slide_to_speed = parseInt($(this).attr("data-slide-to-speed"));
            } else {
              slide_to_speed = config.plugin.slide_to.speed;
            };
            //console.log('attr speed: '+slide_to_speed);


            if ( $(this).is("[data-slide-to-easing]") ){
              slide_to_easing = $(this).attr("data-slide-to-easing");
            } else {
              slide_to_easing = config.plugin.slide_to.easing;
            };
            //console.log('attr easing: '+slide_to_easing);


            if( win_width < 1220 ){
                
                  $('html, body').animate({
                      scrollTop: $(slide_to).offset().top
                  }, slide_to_speed, slide_to_easing);

            } else {
               
                  if ( $('header .section_nav').outerHeight()>80 ){

                      $('html, body').animate({
                          scrollTop: ($(slide_to).offset().top)-header_height+30
                      }, slide_to_speed, slide_to_easing);

                  }else{

                      $('html, body').animate({
                          scrollTop: ($(slide_to).offset().top)-header_height
                      }, slide_to_speed, slide_to_easing);

                  };
            };

        });

    };  


    window.p_slider = function(){

          /*$('.p_slider').slick({
            autoplay:false,
            autoplaySpeed:2000,
            slidesToScroll:1,
            slidesToShow:1,
            infinite:false
            //centerMode: false,
            //centerPadding: '60px',
          });*/

    };
  


    window.waterfall_slider = function(){

          $('.waterfall_slider').slick({
            autoplay:false,
            autoplaySpeed:2000,
            slidesToScroll:1,
            slidesToShow:1,
            infinite:false,
            vertical: true
            //centerMode: false,
            //centerPadding: '60px',
          });

    };
  


    window.waterfall_autoplay = function(){

          var running         = true ;
          var scrolled        = 0 ;
          var scroll_in_px    = 200 ;
          var scroll_interval = 2000 ; //in ms
         
          var interval = setInterval(function() {
              if (!running) {
                  // not running, do nothing
              } else {
                  
                    scrolled = $('.waterfall_box_ww .waterfall_box').scrollTop() + scroll_in_px;
                    
                    $('.waterfall_box_ww .waterfall_box').animate({
                          scrollTop:  scrolled

                    },600,'easeInOutCubic',function(){});

                    //console.log('autoplay '+scrolled);

              }
          }, 2000)


          $('body').on('mouseenter','.waterfall_box_ww .waterfall_box',function(){
            //console.log('stop');
            running = false;
          });

          $('body').on('mouseleave','.waterfall_box_ww .waterfall_box',function(){
            //console.log('start');
            running = true;
          });

          
    };
  


    window.link_fx = function(e) {

        $('a:not(.external,[href^="#"])').on('click', function(e){
          
              e.preventDefault();

              var link_url = $(this).attr('href');
              $('body').removeClass('ready');

              setTimeout(function(){
                window.location = link_url;
              },550);

        });

    };
  

    window.rtab_nav = function(e) {

        if ( $('.rtab_nav').length ){
            
            var rtab_nav_outer_width    = $('.rtab_nav').parent().outerWidth();
            var rtab_nav_inner_width    = $('.rtab_nav').outerWidth();
            var active_bg_extra_margin  = (rtab_nav_outer_width-rtab_nav_inner_width)/2;
            //console.log('active_bg_extra_margin'+active_bg_extra_margin);
            var active_bg_left  = $('.rtab_nav .rtab_link.active').position().left;
            var active_bg_width = $('.rtab_nav .rtab_link.active').width();
            $('.rtab_nav .active_bg').css({'width':active_bg_width+'px','left':(active_bg_left+active_bg_extra_margin)+'px'});

            $('body').on('click','.rtab_link:not(.disabled)', function(e){

            // $('.rtab_link:not(.disabled)').on('click', function(e){

                  var rtab_id = $(this).attr('data-rtab-link');
                  $('.rtab_link').removeClass('active');
                  $('.rtab_ct').removeClass('active');

                  $('.rtab_link[data-rtab-link="'+rtab_id+'"]').addClass('active');
                  $('.rtab_ct[data-rtab-ct="'+rtab_id+'"]').addClass('active');

                  var active_bg_left  = $('.rtab_nav .rtab_link.active').position().left;
                  var active_bg_width = $('.rtab_nav .rtab_link.active').width();
                  $('.rtab_nav .active_bg').css({'width':active_bg_width+'px','left':(active_bg_left+active_bg_extra_margin)+'px'});
            
            });
        
        };

    };
    

    window.dtab_nav = function(e) {

        if ( $('.dtab_nav').length ){

            $('.dtab_link').on('click', function(e){

                  var dtab_id = $(this).attr('data-dtab-link');
                  $('.dtab_link').removeClass('active');
                  $('.dtab_ct').removeClass('active');

                  $('.dtab_link[data-dtab-link="'+dtab_id+'"]').addClass('active');
                  $('.dtab_ct[data-dtab-ct="'+dtab_id+'"]').addClass('active');
            
            });
        
        };

    };


    window.full_screen_change = function(e) {

        var fullscreenElement = document.fullscreenElement || document.mozFullScreenElement ||
        document.webkitFullscreenElement || document.msFullscreenElement;

        if (fullscreenElement != null) {
              //console.info("Went full screen");
              $('body').attr('data-fullscreen','true');
              slide_scale();
              setTimeout(function(){ // msiefix
                slide_scale();
              },500);
          } else {
              //console.info("Exited full screen");      
              $('body').attr('data-fullscreen','false');        
          }

    };


    window.full_screen_toggle = function(e) {

        var elem = e || document.documentElement;
        if (!document.fullscreenElement && !document.mozFullScreenElement &&
          !document.webkitFullscreenElement && !document.msFullscreenElement) {
          if (elem.requestFullscreen) {
            elem.requestFullscreen();
          } else if (elem.msRequestFullscreen) {
            elem.msRequestFullscreen();
          } else if (elem.mozRequestFullScreen) {
            elem.mozRequestFullScreen();
          } else if (elem.webkitRequestFullscreen) {
            elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
          }
          //$('body').attr('data-fullscreen','true');
        } else {
          if (document.exitFullscreen) {
            document.exitFullscreen();
          } else if (document.msExitFullscreen) {
            document.msExitFullscreen();
          } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
          } else if (document.webkitExitFullscreen) {
            document.webkitExitFullscreen();
          }
          //$('body').attr('data-fullscreen','false');
        }

    }


    window.full_screen = function(e) {

        document.addEventListener("fullscreenchange", full_screen_change);
        document.addEventListener("webkitfullscreenchange", full_screen_change);
        document.addEventListener("mozfullscreenchange", full_screen_change);
        document.addEventListener("MSFullscreenChange", full_screen_change);

        $('.nav_icons .icon.fullscreen').on('click', function(e){
          full_screen_toggle();
        });
        $('.p_slider_settings .fullscreen_btn').on('click', function(e){
          full_screen_toggle();
          return false;
        });
    };


    window.slidetab_nav = function(e) {

        if ( $('.nav_icons').length ){
            $('.nav_icons .icon:not(.autosave)').on('click', function(e){

                  if ($(this).attr("data-slidetab")) {
                        var slidetab_id = $(this).attr('data-slidetab');

                        $('.nav_icons .icon').removeClass('active');
                        $('.main_tab').removeClass('active');

                        $(this).addClass('active');
                        $('.main_tab[data-slidetab="'+slidetab_id+'"]').addClass('active');

                        $('.container .container_inner_w').css('height','0px');
                        $('.container .container_inner_w').each(function(){
                          var parent_height = $(this).parent().outerHeight();
                          $(this).css('height',parent_height+'px');
                        });

                        calc();
                        slide_scale();

                  };
            });
        };

    };
    

    window.nav_icons = function(e) {

        var nav_icon_z_index = 2000;

        $('.nav_icons .icon_ct').on('click', function(e){

                  nav_icon_z_index++;

                  if ( $(this).parent().hasClass('active') ){

                      $(this).parent().removeClass('active');
                      $(this).parent().find('.icon_nav_w').animate({
                          top: 72,
                          opacity: 0
                        },
                        300,'easeInOutCubic',function() {
                          $(this).parent().find('.icon_nav_w').css({'display':'none'});
                          $(this).parent().removeClass('active');
                        });

                  }else{

                      $(this).parent().parent().find('.icon.active:not(.current) .icon_nav_w').animate({
                          top: 72,
                          opacity: 0
                        },
                        300,'easeInOutCubic',function() {
                          $(this).parent().parent().find('.icon.active:not(.current) .icon_nav_w').css({'display':'none'});
                          $(this).parent().parent().find('.icon.active:not(.current) .icon_nav_w').removeClass('active');
                        });

                          $(this).parent().parent().find('.icon.active:not(.current)').removeClass('active');

                      $(this).parent().addClass('current');
                      $(this).parent().addClass('active');
                      $(this).parent().find('.icon_nav_w').css({'display':'block','z-index':nav_icon_z_index}).attr('data-layer',nav_icon_z_index).animate({
                          top: 41,
                          opacity: 1
                        },
                        300,'easeInOutCubic',function() {
                            $(this).parent().removeClass('current');
                        });
                  };

        
        });


        $(document).click(function(e) {
            var target = e.target; 
            if ( !jQuery(target).is('.nav_icons .icon *')  ) {

                  //console.log('target : '+target);

                  $('header .icon .icon_nav_w').animate({
                    top: 72,
                    opacity: 0
                  },
                  300,'easeInOutCubic',function() {
                    $('header .icon .icon_nav_w').css({'display':'none'}).removeClass('active');
                  });
                  // $('header .icon').removeClass('active').removeClass('current');


            }
        });

    };


    window.slides_sortable = function(e) {

        /*if ( $('.wrapper_ct_l .slides').length ){

            $('.wrapper_ct_l .slides').sortable(
            {
                tolerance: 'pointer',
                forcePlaceholderSize: true,
                opacity: 0.8,
                placeholder: 'placeholder',
                //forcePlaceholderSize: true,
            })
            .disableSelection();
        };*/


        $('.wrapper_ct_l .slide').on('click',function(){
            $('.wrapper_ct_l .slide').removeClass('selected');
            $(this).addClass('selected');
        });
        $('.wrapper_ct_l .slide').on('mouseout',function(){
            $('.wrapper_ct_l .slide').removeClass('selected');
        });

    };


    window.df_sortable_options = function(e) {

        /*if ( $('.df .sortable_options:not(.disabled)').length) {
            $('.df .sortable_options:not(.disabled)').sortable(
            {
                tolerance: 'pointer',
                forcePlaceholderSize: true,
                opacity: 0.8,
                placeholder: 'placeholder',
                //forcePlaceholderSize: true,

            })
            .disableSelection();
        };*/

    };


    window.df_rotate_deg = function(e) {

            /*$('.df_result .rotate_deg_icon').on('click',function(){

                var current_img = $(this).parent().find('.rotate_deg.active');
                var first_img   = $(this).parent().find('.rotate_deg:eq(0)');

                if ( current_img.next().length ){
                  // console.log('not last');
                  current_img.removeClass('active');
                  $(current_img).next().addClass('active');
                }else{
                  // console.log('last');
                  current_img.removeClass('active');
                  first_img.addClass('active');
                };

            });*/

    };


    window.ct_scroll = function(e) {

            $('.slimscroll_w4[data-scroll-position="left"]').each(function(){
                  $(this).slimscroll({
                    height:'100%',
                    distance:'2px',
                    position:'left',
                    disableFadeOut:true,
                    allowPageScroll:false
                });
            });

            $('.slimscroll_w4[data-scroll-position="right"]').each(function(){
                  $(this).slimscroll({
                    height:'100%',
                    distance:'2px',
                    position:'right',
                    disableFadeOut:true,
                    allowPageScroll:false
                });
            });

    };


    window.tooltips = function(e) {

        $('.df_title').tooltip({selector: "[data-toggle=tooltip]",container: "body"});
        $('.presentations_table .icon').tooltip({selector: "[data-toggle=tooltip]",container: "body"});

    };


    window.data_max_length = function(e) {


      $('.fn_data_max_length').each(function(e){

          var field_current_length  = $(this).val().length;
          var field_max_length      = $(this).attr('data-max-length');
          var field_new_length      = $(this).val().length;
          var field_left;          
          var field_left_e          = $(this).parent().find('.input-group-addon-max-length');    
          var field_left_label      = $(this).parent().parent().parent().find('.data-length-value');     

          if ( field_max_length >= field_new_length ){
                field_left = field_max_length-field_new_length;
                field_left_e.text(field_left); 
                field_left_label.text(field_left); 
          }else {
             $(this).val( $(this).val().substring(0,field_max_length) );
          };

      });


      $('.fn_data_max_length').on('keyup change input paste',function(e){

          var field_current_length  = $(this).val().length;
          var field_max_length      = $(this).attr('data-max-length');
          var field_new_length      = $(this).val().length;
          var field_left;          
          var field_left_e          = $(this).parent().find('.input-group-addon-max-length');        
          var field_left_label      = $(this).parent().parent().parent().find('.data-length-value');        

          if ( field_max_length >= field_new_length ){
                field_left = field_max_length-field_new_length;
                field_left_e.text(field_left); 
                field_left_label.text(field_left); 
          }else {
             $(this).val( $(this).val().substring(0,field_max_length) );
          };

      });


      $('.modal').each(function(e){
          $(this).on('show.bs.modal', function() {
                data_max_length();
          });
      });


    };


    window.slide = function(e) {


        $('.p_slider_settings nav .iarrow').on('click',function(){
        
            var sub = $(this).parent().next('ul');
            
            if ( sub.hasClass('active') ){
                sub.slideUp('350');
                sub.removeClass('active');
            }else{
                sub.stop(true,false).slideDown('350');
                sub.addClass('active');
            };

        });


        $('.p_slider_icons .icon').on('click',function(){
        
            var layer = $(this).attr('data-layer');
            
            if ( $(this).hasClass('active') ){
                
                $(this).removeClass('active');
                $('.p_slider_icons .icon').removeClass('active');
                $('.p_slider_layer').removeClass('active');

                $('.p_slider_settings').animate({left:-300},500,'easeInOutCubic',function() { $('.p_slider_settings').css({'display':'none'}); });
                $('.p_slider_info').animate({opacity:0},500,'easeInOutCubic',function() { $('.p_slider_info').css({'display':'none'}); });

            }else{
                
                $('.p_slider_icons .icon').removeClass('active');
                $('.p_slider_layer').removeClass('active');
                $(this).addClass('active');
                $('.'+layer).addClass('active');

                if ( layer == 'p_slider_info'){
                  $('.p_slider_info').stop(true,false).css({'display':'block'}).animate({opacity:1},500,'easeInOutCubic',function() {});
                  $('.p_slider_settings').animate({left:-300},500,'easeInOutCubic',function() { $('.p_slider_settings').css({'display':'none'}); });
                };
                if ( layer == 'p_slider_settings'){
                  $('.p_slider_settings').stop(true,false).css({'display':'block'}).animate({left:0},500,'easeInOutCubic',function() {});
                  $('.p_slider_info').animate({opacity:0},500,'easeInOutCubic',function() { $('.p_slider_info').css({'display':'none'}) });
                };

            };

        });



        $(document).click(function(e) {
            var target = e.target; 
            if ( !jQuery(target).is('.p_slider_settings') && !jQuery(target).is('.p_slider_settings *') && !jQuery(target).is('.p_slider_icons .icon.settings') && !jQuery(target).is('.p_slider_icons .icon.settings *')  ) {

                $('.p_slider_icons .icon.settings').removeClass('active');
                $('.p_slider_settings.p_slider_layer').removeClass('active');

                $('.p_slider_settings').stop(true,false).animate({left:-300},500,'easeInOutCubic',function() { $('.p_slider_settings').css({'display':'none'}); });
                
            }
        });
        


    };


    window.slide_scale = function(e) {

        //var proportion        = 10/6;
        //var proportion_basic  = 1000/600;

        var box             = $('body');
        var box_w           = box.outerWidth();
        var box_h           = box.outerHeight();
        var box_inner       = $('.p_slide_box_m_m_inner');
        var box_inner_w     = box_inner.outerWidth();
        var box_inner_h     = box_inner.outerHeight();
        var scale           = Math.min( box_w / box_inner_w, box_h / box_inner_h );

        box_inner.css({   transform: "translate(-50%, -50%) " + "scale(" + scale + ")"  });
        $('.p_slider_info_box').css({   transform: "translate(-50%, -50%) " + "scale(" + scale + ")"  });


        var preview_box             = $('.section_slide_preview .ct_c');
        var preview_box_w           = preview_box.outerWidth();
        var preview_box_h           = preview_box.outerHeight();
        var preview_box_inner       = $('.preview_p_slide_box_m_m_inner');
        var preview_box_inner_w     = preview_box_inner.outerWidth();
        var preview_box_inner_h     = preview_box_inner.outerHeight();
        var preview_scale           = Math.min( preview_box_w / preview_box_inner_w, preview_box_h / preview_box_inner_h );

        preview_box_inner.css({   transform: "translate(-50%, -50%) " + "scale(" + preview_scale + ")"  });


       // var viewBoxX;
       // var viewBoxY;
        
        if ( preview_box.length ){
          $('body').attr('data-preview-scale',preview_scale);
          //viewBoxX = 600 * preview_scale;
          //viewBoxY = 300 * preview_scale;
        } else {
          $('body').attr('data-preview-scale',scale);
          //viewBoxX = 600 * scale;
          //viewBoxY = 300 * scale;
        };

        calc();

        //$('.chart svg').attr('viewBox','0 0 '+viewBoxX+' '+viewBoxY);

    };


    window.hidden_image = function(e) {
    

        $('.hidden_image_button').on('click',function(){
            if( $(this).hasClass('active') ){

              $('body').removeClass('hidden_image_displayed');
              $(this).removeClass('active');
              $(this).parent().prev('.hidden_image').removeClass('active');

            }
            else{

              $('body').addClass('hidden_image_displayed');
              $(this).addClass('active');
              $(this).parent().prev('.hidden_image').addClass('active');

            };
        });


    };



    window.user_calc = function(){
        

        var win_height        = $(window).height();
        var doc_height        = $(document).height();
        var win_width         = Math.max( $(window).width(), window.innerWidth);
        var header_height     = $("header").outerHeight();
        var container_height  = $(".maincontainer").outerHeight();
        var footer_height     = $("footer").outerHeight();
        
        $('#p_slider_w4').css({'height':win_height+'px','width':win_width+'px'});
        $('.p_slider').css({'height':win_height+'px','width':win_width+'px'});


        if ( $('.section_slide_preview').length ){
            var preview_box             = $('.section_slide_preview .ct_c');
            var preview_box_w           = preview_box.outerWidth();
            var preview_box_h           = preview_box.outerHeight();
            var preview_box_inner       = $('.preview_p_slide_box_m_m_inner');
            var preview_box_inner_w     = preview_box_inner.outerWidth();
            var preview_box_inner_h     = preview_box_inner.outerHeight();
            var preview_scale           = Math.min( preview_box_w / preview_box_inner_w, preview_box_h / preview_box_inner_h );

            $('body').attr('data-preview-scale',preview_scale);

            $('.preview_p_slide_box_m').each(function(){
                  var slide_preview_height = preview_scale*600;
                  if ( win_height > (slide_preview_height + header_height + footer_height) ){
                      $(this).css('height', win_height-header_height-footer_height-2 + 'px');
                  }
                  else {
                      $(this).css('height', preview_scale*600 + 'px');
                  };
          });

        };

    };



  	$(document).ready(function() {

      		device_test();
          
          widgets();
          window_height();
          window_height_relative();
          
          rtab_nav();
          dtab_nav();
          slidetab_nav();
          slides_sortable();
          df_sortable_options();
          df_rotate_deg();
          tooltips();
          ct_scroll();
          nav_icons();
          data_max_length();
          slide();
          slide_scale();
          full_screen();
          p_slider();
          waterfall_slider();
          waterfall_autoplay();
          hidden_image();

          //if ( config.browser.name != "mozilla" && config.browser.name != "msie" && config.os.mobile != true ){ scrollpage(100,800); };
          //console.log(config.browser.name);

          slide_to();
          height_16x9();

          //section_featured_info();
          
          
          //if ( $('.parallaxa_bg').length ){ parallaxa_bg(); };
      		calc(); 


          setTimeout(function(){
            $('body').addClass('ready');
             calc();
             slide_scale();
          },100);

          link_fx();
  	});		



  	$(window).resize(function(){
  		
          height_16x9();
          window_height();
          window_height_relative();
          project_part_slider_box();
          slide_scale(); //slide_preview_inner_scale();

      		if ( config.block.footer.stick.active == true ) { calc(); }
          
          clearTimeout(window.resizedFinished);
          window.resizedFinished = setTimeout(function(){
              //console.log('Resized finished.');
              project_part_slider_box();

          }, 500);


          

  	});



    $(window).scroll(function(){ 

          var max_scroll = 20;
          var current_position = $(window).scrollTop();
          var doc_height = $(document).height();
          var win_height = $(window).height();
          var scroll_percent = current_position / (doc_height - win_height);
          var scroll_percent_rounded = Math.round(scroll_percent*100);
          
          if(current_position > max_scroll) {
              $("body").addClass('scrolled');
          }
          else {
              $("body").removeClass('scrolled');
          };

          $('.page_position_value').stop(true,false).css({'width':scroll_percent_rounded+'%'});


    });


}(window.jQuery, window, document));
