Advertisement
Guest User

Untitled

a guest
Nov 25th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     var lastTime = 0;
  3.     var vendors = ['ms', 'moz', 'webkit', 'o'];
  4.     for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
  5.         window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
  6.         window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
  7.                                    || window[vendors[x]+'CancelRequestAnimationFrame'];
  8.     }
  9.  
  10.     if (!window.requestAnimationFrame)
  11.         window.requestAnimationFrame = function(callback, element) {
  12.             var currTime = new Date().getTime();
  13.             var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  14.             var id = window.setTimeout(function() { callback(currTime + timeToCall); },
  15.               timeToCall);
  16.             lastTime = currTime + timeToCall;
  17.             return id;
  18.         };
  19.  
  20.     if (!window.cancelAnimationFrame)
  21.         window.cancelAnimationFrame = function(id) {
  22.             clearTimeout(id);
  23.         };
  24. }());
  25.  
  26.  
  27.  
  28. jQuery(document).ready(function($){
  29.  
  30. var $shapes = [];
  31. var $selector = ($('.nectar-box-roll').length > 0) ? '.nectar-box-roll .shape': '.nectar-particles .shape';
  32.  
  33. function initSetup() {
  34.  
  35.   if($selector.length == 0) return false;
  36.  
  37.   $($selector).each(function(i){
  38.     $shapes[i] = {
  39.          shape: $(this).attr('data-src'),
  40.          colorMapping: ($(this).attr('data-color-mapping').length > 0) ? $(this).attr('data-color-mapping') : 'original',
  41.          color: ($(this).attr('data-color').length > 0) ? $(this).attr('data-color') : '#fefefe',
  42.          backgroundColor: ($(this).attr('data-bg-color').length > 0) ? $(this).attr('data-bg-color') : 'transparent',
  43.          colorAlpha: ($(this).attr('data-alpha').length > 0) ? $(this).attr('data-alpha') : 'original',
  44.          density: ($(this).attr('data-density').length > 0) ? parseInt($(this).attr('data-density')) : 13,
  45.          densityOriginal: ($(this).attr('data-density').length > 0) ? parseInt($(this).attr('data-density')) : 13,
  46.          maxParticleSize: ($(this).attr('data-max-size').length > 0) ? parseInt($(this).attr('data-max-size')) : 3,
  47.          maxParticleSizeOriginal : ($(this).attr('data-max-size').length > 0) ? parseInt($(this).attr('data-max-size')) : 3
  48.     };
  49.     $(this).remove();
  50.   });
  51. }
  52. initSetup();
  53.  
  54. var Nodes = {
  55.  
  56.     // Settings
  57.     canvasID: null,
  58.  
  59.     drawDistance: 28,
  60.     maxLineThickness: 4,
  61.     reactionSensitivity: 3,
  62.     lineThickness: 1,
  63.  
  64.     points: [],
  65.     mouse: {x: window.innerWidth * 2, y: window.innerHeight * 2, down: false},
  66.  
  67.     animation: null,
  68.     randomMovement: false,
  69.     impulsX: Math.random() * 600 - 300,
  70.     impulsY: -Math.random() * 300,
  71.     imgsToDraw: $shapes,
  72.     timeoutHolder: null,
  73.     totalImgCount: 0,
  74.     loaded: false,
  75.     loadedCount: 0,
  76.     canvas: null,
  77.     context: null,
  78.  
  79.     imageInput: null,
  80.     bgImage: [],
  81.     onMobile: false,
  82.     explodeChance: true,
  83.     currentShapeIndex: 0,
  84.     currentSequenceIndex: 0,
  85.     prevShapeIndex: 0,
  86.     sequenceActive: false,
  87.     decMultiplier: 0.02,
  88.     bgCanvas: null,
  89.     bgContext: null,
  90.     bgContextPixelData: null,
  91.     disableExplosion: $('#page-header-bg .nectar-particles').attr('data-disable-explosion'),
  92.     rotateTimer: parseInt($('#page-header-bg .nectar-particles').attr('data-rotation-timing')),
  93.     regularAnimation: true, //determines when fps should be lowered during boxroll for better performance
  94.     textPosition: $('#page-header-bg').attr('data-alignment-v'),
  95.     textPositionH: $('#page-header-bg').attr('data-alignment'),
  96.     fps: 43, //only used when box roll is animating (starts to dec from here)
  97.     fpsDec: 0.13,
  98.     now: 0,
  99.     then: Date.now(),
  100.     elapsed: 0,
  101.     init: function (canvasID) {
  102.  
  103.         // Set up the visual canvas
  104.         this.canvas = $(canvasID)[0];
  105.         this.context = canvas.getContext('2d');
  106.         this.context.globalCompositeOperation = "lighter";
  107.         this.canvas.width = ($(canvasID).parents('.nectar-box-roll').length > 0) ? window.innerWidth : $(canvasID).parents('.nectar-particles').width();
  108.         this.canvas.height = ($(canvasID).parents('.nectar-box-roll').length > 0) ? window.innerHeight : $(canvasID).parents('.nectar-particles').height();
  109.         this.canvas.style.display = 'block'
  110.  
  111.         this.canvasID = canvasID;
  112.  
  113.         //set initial bg color
  114.         Nodes.canvasBgColor();
  115.  
  116.         //set mobile state
  117.         if (this.canvas.width <= 690) this.onMobile = true;
  118.  
  119.         /*this.canvas.addEventListener('mousemove', this.mouseMove, false);
  120.         this.canvas.addEventListener('mouseout',  this.mouseOut,  false);
  121.         var overlaidContent = $('.overlaid-content')[0];
  122.         overlaidContent.addEventListener('mousemove', this.mouseMove, false);
  123.         overlaidContent.addEventListener('mouseout', this.mouseOut, false);
  124.         */
  125.  
  126.         //default autorotate
  127.         if ($('#page-header-bg .nectar-particles').attr('data-rotation-timing').length < 1) Nodes.rotateTimer = 5500;
  128.  
  129.         if ($(canvasID).parents('.nectar-box-roll').length > 0) {
  130.             $('body').on('mousemove', function (e) {
  131.                 if (Nodes.regularAnimation == true) {
  132.                     Nodes.mouse.x = e.clientX;
  133.                     Nodes.mouse.y = e.clientY;
  134.  
  135.                 }
  136.             });
  137.             //$('body').on('mouseout',function(){
  138.             //  Nodes.mouse.x = 1000;
  139.             //  Nodes.mouse.y = -1000;
  140.             //  Nodes.mouse.down = false;
  141.             //});
  142.         } else {
  143.             $(canvasID).parents('.nectar-particles').on('mousemove', function (e) {
  144.                 Nodes.mouse.x = e.clientX - $(this).offset().left;
  145.                 Nodes.mouse.y = e.clientY - $(this).offset().top + $(window).scrollTop();
  146.             });
  147.             $(canvasID).parents('.nectar-particles').on('mouseout', function () {
  148.                 Nodes.mouse.x = 1000;
  149.                 Nodes.mouse.y = -1000;
  150.                 Nodes.mouse.down = false;
  151.             });
  152.         }
  153.  
  154.  
  155.         //for non fullscreen mobile
  156.         if ($('#page-header-bg:not(.fullscreen-header)').length > 0 && $(window).width() < 1000) {
  157.             $(window).load(function () {
  158.                 setTimeout(function () {
  159.  
  160.                     Nodes.canvas.width = ($(canvasID).parents('.nectar-box-roll').length > 0) ? window.innerWidth : $(canvasID).parents('.nectar-particles').width();
  161.                     Nodes.canvas.height = ($(canvasID).parents('.nectar-box-roll').length > 0) ? window.innerHeight : $(canvasID).parents('.nectar-particles').height();
  162.                     Nodes.onWindowResize();
  163.  
  164.                 }, 50);
  165.  
  166.             });
  167.         }
  168.  
  169.  
  170.         window.onresize = function (event) {
  171.             if (typeof(event.isTrigger) !== 'undefined') return false;
  172.  
  173.             Nodes.canvas.width = ($(canvasID).parents('.nectar-box-roll').length > 0) ? window.innerWidth : $(canvasID).parents('.nectar-particles').width();
  174.             Nodes.canvas.height = ($(canvasID).parents('.nectar-box-roll').length > 0) ? window.innerHeight : $(canvasID).parents('.nectar-particles').height();
  175.             Nodes.onWindowResize();
  176.         }
  177.  
  178.         //count shapes
  179.         var j = 0;
  180.         for (var i = 0; i < Nodes.imgsToDraw.length; i++) {
  181.  
  182.             //check for sequenced
  183.             if (typeof Nodes.imgsToDraw[i].shape === 'object') {
  184.  
  185.                 for (j = 0; j < Nodes.imgsToDraw[i].shape.length; j++) {
  186.                     this.totalImgCount++;
  187.                 }
  188.             } else {
  189.                 this.totalImgCount++;
  190.             }
  191.  
  192.         }
  193.  
  194.         //start loading the shapes
  195.         var j = 0;
  196.         for (var i = 0; i < Nodes.imgsToDraw.length; i++) {
  197.  
  198.             //check for sequenced
  199.             if (typeof Nodes.imgsToDraw[i].shape === 'object') {
  200.  
  201.                 for (j = 0; j < Nodes.imgsToDraw[i].shape.length; j++) {
  202.                     this.loadData(Nodes.imgsToDraw[i].shape[j], i, j, true);
  203.                 }
  204.             } else {
  205.                 this.loadData(Nodes.imgsToDraw[i].shape, i, null, false);
  206.             }
  207.  
  208.         }
  209.     },
  210.  
  211.     preparePoints: function (index, index2, resize) {
  212.  
  213.         // Clear the current points
  214.         if (!jQuery.isArray(this.bgImage[index])) {
  215.             this.points[index] = [];
  216.         } else {
  217.             if (typeof this.points[index] !== 'object') this.points[index] = {};
  218.             this.points[index][index2] = [];
  219.         }
  220.  
  221.         var width, height, i, j;
  222.  
  223.         var colors = this.bgContextPixelData.data;
  224.  
  225.         for (i = 0; i < this.canvas.height; i += this.imgsToDraw[index].density) {
  226.  
  227.             for (j = 0; j < this.canvas.width; j += this.imgsToDraw[index].density) {
  228.  
  229.                 var pixelPosition = (j + i * this.bgContextPixelData.width) * 4;
  230.  
  231.                 // Dont use whiteish pixels
  232.                 if (colors[pixelPosition] > 200 && (colors[pixelPosition + 1]) > 200 && (colors[pixelPosition + 2]) > 200 || colors[pixelPosition + 3] === 0) {
  233.                     continue;
  234.                 }
  235.  
  236.                 //first shape while loading
  237.                 if (index == 0) {
  238.                     var rndNumX = (Math.random() > 0.5) ? Math.random() * window.innerWidth : Math.random() * -window.innerWidth;
  239.                     var rndNumY = (Math.random() > 0.5) ? Math.random() * window.innerHeight : Math.random() * -window.innerHeight;
  240.                     var xPos = Math.random() * (window.innerWidth * 2) + rndNumX;
  241.                     var yPos = Math.random() * (window.innerHeight * 2) + rndNumY;
  242.  
  243.                 }
  244.  
  245.                 //all others
  246.                 else {
  247.  
  248.                     //sequenced
  249.                     /*if(!jQuery.isArray(this.points[index]) && typeof this.points[index] === 'object') {
  250.  
  251.                         //inside sequenced
  252.                         if(index2 == 0) {
  253.                             var prevIndex = (index == this.points[index].length) ? 0 : index-1;
  254.  
  255.                             var xPos = this.points[prevIndex][Math.floor(Math.random()*this.points[prevIndex].length)].originalX;
  256.                                var yPos = this.points[prevIndex][Math.floor(Math.random()*this.points[prevIndex].length)].originalY;
  257.                         } else {
  258.                             var prevIndex = (index2 == this.points[index].length) ? 0 : index2-1;
  259.  
  260.                             var xPos = this.points[index][prevIndex][Math.floor(Math.random()*this.points[index][prevIndex].length)].originalX;
  261.                                var yPos = this.points[index][prevIndex][Math.floor(Math.random()*this.points[index][prevIndex].length)].originalY;
  262.                         }
  263.  
  264.  
  265.                     } */
  266.  
  267.                     //regular
  268.                     //else {
  269.  
  270.                     //going back into sequenced
  271.                     var prevIndex = (index == this.points.length) ? 0 : index - 1;
  272.                     if (!jQuery.isArray(this.points[prevIndex]) && typeof this.points[prevIndex] === 'object') {
  273.                         var prevIndex2 = (index2 == this.points[prevIndex].length) ? 0 : index2 - 1;
  274.                         var mathRnd = Math.random();
  275.                         var xPos = this.points[prevIndex][prevIndex2][Math.floor(mathRnd * this.points[prevIndex][prevIndex2].length)].originalX;
  276.                         var yPos = this.points[prevIndex][prevIndex2][Math.floor(mathRnd * this.points[prevIndex][prevIndex2].length)].originalY;
  277.                     } else {
  278.                         var mathRnd = Math.random();
  279.                         var xPos = this.points[prevIndex][Math.floor(mathRnd * this.points[prevIndex].length)].originalX;
  280.                         var yPos = this.points[prevIndex][Math.floor(mathRnd * this.points[prevIndex].length)].originalY;
  281.                     }
  282.                     //}
  283.  
  284.                 }
  285.  
  286.                 //when user resizes screen
  287.                 if (resize == true && Nodes.randomMovement == false && $(Nodes.canvasID).attr('data-loaded') == 'true') {
  288.                     xPos = j + this.ran(-7, 7);
  289.                     yPos = i + this.ran(-7, 7);
  290.                 } else if (resize == true && Nodes.randomMovement == true && $(Nodes.canvasID).attr('data-loaded') == 'true') {
  291.                     xPos = Math.random() * (window.innerWidth);
  292.                     yPos = Math.random() * (window.innerHeight);
  293.                 }
  294.  
  295.  
  296.                 //alpha mapping
  297.                 switch (this.imgsToDraw[index].colorAlpha) {
  298.                     case 'original':
  299.                         alpha = 1;
  300.                         break;
  301.                     case 'random':
  302.                         var alpha = Math.random() + 0.3;
  303.                         //if(alpha < 0.2) alpha = 0.2;
  304.                         if (alpha > 1) alpha = 1;
  305.                         break;
  306.                 }
  307.  
  308.                 //color mapping
  309.                 switch (this.imgsToDraw[index].colorMapping) {
  310.                     case 'original':
  311.                         var r = colors[pixelPosition];
  312.                         var g = colors[pixelPosition + 1];
  313.                         var b = colors[pixelPosition + 2]
  314.                         var color = 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')';
  315.                         break;
  316.  
  317.                     case 'solid':
  318.                         hex = this.imgsToDraw[index].color.replace('#', '');
  319.                         var r = parseInt(hex.substring(0, 2), 16);
  320.                         var g = parseInt(hex.substring(2, 4), 16);
  321.                         var b = parseInt(hex.substring(4, 6), 16);
  322.                         var color = 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')';
  323.                         break;
  324.  
  325.                     case 'random':
  326.                         var r = Math.floor(Math.random() * 255);
  327.                         var g = Math.floor(Math.random() * 255);
  328.                         var b = Math.floor(Math.random() * 255);
  329.                         var color = 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')';
  330.                         break;
  331.                 }
  332.  
  333.  
  334.                 var flashChance = (Math.random() < 0.5) ? true : false;
  335.                 var rndNum = Math.random();
  336.  
  337.                 if (!jQuery.isArray(this.bgImage[index])) {
  338.  
  339.                     this.points[index].push({
  340.                         x: xPos,
  341.                         y: yPos,
  342.                         originalX: j,
  343.                         originalY: i,
  344.                         toX: Math.random() * (window.innerWidth),
  345.                         toY: Math.random() * (window.innerHeight),
  346.                         r: r,
  347.                         g: g,
  348.                         b: b,
  349.                         a: alpha,
  350.                         hiddenDuringTrans: false,
  351.                         originalAlpha: alpha,
  352.                         color: color,
  353.                         baseRadius: Math.ceil(rndNum * this.imgsToDraw[index].maxParticleSize),
  354.                         baseRadiusOriginal: Math.ceil(rndNum * this.imgsToDraw[index].maxParticleSize),
  355.                         randomPosX: Math.random() * 6,
  356.                         randomPosY: Math.random() * 6,
  357.                         shrinking: false,
  358.                         shrinkDelay: Math.random() * 100,
  359.                         flashSize: flashChance,
  360.                         used: false, //used already when seeking points in explosion
  361.                         duplicate: false, // duplicate point in explosion to fade in during shape trans
  362.                         randomNum: rndNum
  363.                     });
  364.  
  365.                     if (this.points[index].baseRadius < 1) {
  366.                         this.points[index].baseRadius = 1;
  367.                         this.points[index].baseRadiusOriginal = 1;
  368.                     }
  369.                 } else {
  370.  
  371.                     this.points[index][index2].push({
  372.                         x: j,
  373.                         y: i,
  374.                         originalX: j,
  375.                         originalY: i,
  376.                         seqX: j,
  377.                         seqY: i,
  378.                         sequenceUsed: false,
  379.                         toX: Math.random() * (window.innerWidth),
  380.                         toY: Math.random() * (window.innerHeight),
  381.                         color: color,
  382.                         baseRadius: Math.ceil(rndNum * 3),
  383.                         baseRadiusOriginal: Math.ceil(rndNum * 3),
  384.                         shrinking: false,
  385.                         shrinkDelay: Math.random() * 100,
  386.                         flashSize: flashChance,
  387.                         randomNum: rndNum
  388.                     });
  389.                 }
  390.  
  391.             }
  392.         }
  393.  
  394.         //hide particles for trans
  395.         for (var u = 0; u < this.points[index].length; u++) {
  396.  
  397.             var randomNum = Nodes.ran(0, this.points[index].length);
  398.             if (window.innerWidth < 690) {
  399.                 var divider = (this.points[index].length > 200) ? 8 : 5;
  400.                 if (this.points[index].length > 150 && randomNum > Math.floor(this.points[index].length / divider)) {
  401.                     this.points[index][u].hiddenDuringTrans = true;
  402.                 }
  403.             } else {
  404.  
  405.                 if (this.points[index].length > 800) {
  406.                     var divider = 6;
  407.                 } else if (this.points[index].length <= 800 && this.points[index].length > 600) {
  408.                     var divider = 4.5;
  409.                 } else if (this.points[index].length <= 600 && this.points[index].length > 400) {
  410.                     var divider = 3.5;
  411.                 }
  412.                 else if (this.points[index].length <= 400) {
  413.                     var divider = 1.5;
  414.                 }
  415.  
  416.                 if (this.points[index].length > 350 && randomNum > Math.floor(this.points[index].length / divider)) {
  417.                     this.points[index][u].hiddenDuringTrans = true;
  418.                 }
  419.             }
  420.  
  421.         }
  422.  
  423.  
  424.         //initiate
  425.         if (index == Nodes.imgsToDraw.length - 1) {
  426.  
  427.             Nodes.draw();
  428.  
  429.             //start the rotate timer
  430.             if (resize == false) Nodes.particlesRotate(false);
  431.  
  432.  
  433.         }
  434.  
  435.  
  436.     },
  437.  
  438.  
  439.     updatePoints: function () {
  440.  
  441.         var i, currentPoint, theta, distance, dx, dy;
  442.  
  443.         this.impulsX = this.impulsX - this.impulsX / 30;
  444.         this.impulsY = this.impulsY - this.impulsY / 30;
  445.  
  446.         //handle new points
  447.         /*var shapePointArr = [];
  448.         var highestPointIndex = 0;
  449.  
  450.         for(var i=0; i<this.points.length;i++){
  451.             shapePointArr[i] = this.points[index].length
  452.         }
  453.  
  454.         var largest = Math.max.apply(Math, shapePointArr); */
  455.  
  456.  
  457.         //reset to first shape at end
  458.         //if(Math.floor(this.currentShapeIndex) == this.points.length) this.currentShapeIndex = 0;
  459.  
  460.         //handle indexing for sequencing and static shapes
  461.         /*if(!jQuery.isArray(Nodes.points[Nodes.currentShapeIndex]) && typeof Nodes.points[Nodes.currentShapeIndex] === 'object') {
  462.             var shapeIndex = this.points[Math.floor(this.currentShapeIndex)][0];
  463.         } else { */
  464.         var shapeIndex = this.points[Math.floor(this.currentShapeIndex)];
  465.         /*}*/
  466.         if (this.onMobile == true) {
  467.             if (Nodes.decMultiplier < 0.23) Nodes.decMultiplier += 0.0015;
  468.         }
  469.         else {
  470.             if (Nodes.decMultiplier < 0.125) Nodes.decMultiplier += 0.0004;
  471.         }
  472.  
  473.  
  474.         //proc
  475.         for (i = 0; i < shapeIndex.length; i++) {
  476.  
  477.             currentPoint = shapeIndex[i];
  478.  
  479.             theta = Math.atan2(currentPoint.y - this.mouse.y, currentPoint.x - this.mouse.x);
  480.  
  481.  
  482.             distance = this.reactionSensitivity * 60 / Math.sqrt((this.mouse.x - currentPoint.x) * (this.mouse.x - currentPoint.x) +
  483.                 (this.mouse.y - currentPoint.y) * (this.mouse.y - currentPoint.y));
  484.             if (distance > 50) distance = 0;
  485.  
  486.  
  487.             if (!shapeIndex[i].time) {
  488.  
  489.                 shapeIndex[i].time = this.ran(70, 200);
  490.                 shapeIndex[i].deg = this.ran(-120, 180);
  491.                 shapeIndex[i].vel = this.ran(0.08, 0.14);
  492.                 // this.points[Math.floor(this.currentShapeIndex)][i].curve = this.ran(0, 1);
  493.                 //this.points[Math.floor(this.currentShapeIndex)][i].fade  = this.ran(0, 1);
  494.             }
  495.  
  496.             // Calc movement
  497.  
  498.             var velocity = (Nodes.randomMovement == false) ? shapeIndex[i].vel : shapeIndex[i].vel;
  499.  
  500.             dx = velocity * Math.cos(shapeIndex[i].deg * Math.PI / 180);
  501.             dy = velocity * Math.sin(shapeIndex[i].deg * Math.PI / 180);
  502.  
  503.             if (Nodes.loaded != false) {
  504.                 // Calc new position
  505.                 currentPoint.x += dx;
  506.                 currentPoint.y += dy;
  507.             }
  508.  
  509.             if (shapeIndex[i].curve > 0) {
  510.                 shapeIndex[i].deg = shapeIndex[i].deg + 2;
  511.             }
  512.             else {
  513.                 shapeIndex[i].deg = shapeIndex[i].deg - 2;
  514.             }
  515.  
  516.             shapeIndex[i].time = shapeIndex[i].time - 1;
  517.  
  518.  
  519.             //before loaded
  520.             if (Nodes.loaded == false) {
  521.  
  522.  
  523.                 if (shapeIndex[i].vel < 0.4) {
  524.                 }
  525.                 else shapeIndex[i].vel = shapeIndex[i].vel - .00;
  526.  
  527.                 currentPoint.x += Math.cos(theta) * distance;
  528.                 currentPoint.y += Math.sin(theta) * distance;
  529.                 //after loaded
  530.             } else {
  531.  
  532.                 //next shape
  533.                 if (Nodes.randomMovement == false) {
  534.  
  535.                     if (Nodes.sequenceActive == false) {
  536.                         //static shape
  537.  
  538.                         ////resetting attrs
  539.  
  540.                         //////reset opacity for hidden particles after explosion
  541.                         //if(currentPoint.duplicate == true) {
  542.                         //  currentPoint.alpha = (currentPoint.alpha < currentPoint.originalAlpha) ? currentPoint.alpha + 0.04 : currentPoint.originalAlpha;
  543.                         //    currentPoint.color = 'rgba(' + currentPoint.r + ',' + currentPoint.g + ',' + currentPoint.b + ',' + currentPoint.alpha+')';
  544.                         //    if(currentPoint.alpha == currentPoint.originalAlpha) currentPoint.duplicate = false;
  545.                         //}
  546.  
  547.                         currentPoint.baseRadius = Math.ceil(currentPoint.randomNum * Nodes.imgsToDraw[Math.floor(this.currentShapeIndex)].maxParticleSize);
  548.                         //if(currentPoint.baseRadius < 1) currentPoint.baseRadius = 1; //min size
  549.                         currentPoint.baseRadiusOriginal = currentPoint.baseRadius;
  550.                         //if(currentPoint.hiddenDuringTrans == true) currentPoint.color = 'rgba(' + currentPoint.r + ',' + currentPoint.g + ',' + currentPoint.b + ',' + currentPoint.originalAlpha +')';
  551.  
  552.                         if (shapeIndex[i].vel < 0.4) shapeIndex[i].time = 0;
  553.                         else shapeIndex[i].vel = shapeIndex[i].vel - .008;
  554.  
  555.                         currentPoint.x += Math.cos(theta) * distance + (shapeIndex[i].originalX - currentPoint.x) * Nodes.decMultiplier;
  556.                         currentPoint.y += Math.sin(theta) * distance + (shapeIndex[i].originalY - currentPoint.y) * Nodes.decMultiplier;
  557.                     } else {
  558.                         //sequence
  559.  
  560.                         //if (shapeIndex[i].vel < 0.7) shapeIndex[i].time = 0;
  561.                         // else shapeIndex[i].vel = shapeIndex[i].vel - .002;
  562.  
  563.                         if (typeof this.points[Math.floor(this.currentShapeIndex)][Nodes.currentSequenceIndex][i] !== 'undefined') {
  564.                             currentPoint.x += Math.cos(theta) * distance + (this.points[Math.floor(this.currentShapeIndex)][0][i].seqX - currentPoint.x) * .08;
  565.                             currentPoint.y += Math.sin(theta) * distance + (this.points[Math.floor(this.currentShapeIndex)][0][i].seqY - currentPoint.y) * .08;
  566.                         }
  567.                     }
  568.                 }
  569.  
  570.                 //random movement
  571.                 else {
  572.  
  573.  
  574.                     if (i == 0 && this.reactionSensitivity < 8) this.reactionSensitivity = 8;
  575.  
  576.                     /*if(shapeIndex[i].time == 0) {
  577.                         currentPoint.randomPosX = 1-2*Math.random() *sizeMovement*2;
  578.                         currentPoint.randomPosY = 1-2*Math.random() *sizeMovement*2;
  579.                     }*/
  580.                     //if(shapeIndex[i].time == 0) console.log('e')
  581.                     //if (this.points[Math.floor(this.currentShapeIndex)][i].vel < 0.4) this.points[Math.floor(this.currentShapeIndex)][i].time = 0;
  582.                     // else this.points[Math.floor(this.currentShapeIndex)][i].vel = this.points[Math.floor(this.currentShapeIndex)][i].vel - .008;
  583.                     //currentPoint.x += Math.cos(theta) * distance + (currentPoint.originalX - currentPoint.x) * .11;
  584.                     //currentPoint.y += Math.sin(theta) * distance + (currentPoint.originalY - currentPoint.y) * .11;
  585.  
  586.  
  587.                     //hide particles accoirding to density
  588.  
  589.  
  590.                     var sizeMovement = shapeIndex[i].randomNum * currentPoint.baseRadius / 4;
  591.                     if (sizeMovement < 0.25) sizeMovement = 0.25;
  592.  
  593.  
  594.                     if (!shapeIndex[i].time2) {
  595.                         shapeIndex[i].time2 = this.ran(300, 900);
  596.                     }
  597.  
  598.                     shapeIndex[i].time2 = shapeIndex[i].time2 - 1;
  599.  
  600.                     /*if(shapeIndex[i].time2 == 0) {
  601.  
  602.                         var rndX = (Math.random() >= 0.5) ? 1-2*Math.random()*-1.3:  1-2*Math.random()*1.3;
  603.                           var rndY = (Math.random() >= 0.5) ? 1-2*Math.random()*-1.3 :  1-2*Math.random()*1.3;
  604.                         currentPoint.randomPosX = rndX;
  605.                         currentPoint.randomPosY = rndY;
  606.                         shapeIndex[i].time2 = this.ran(300, 900);
  607.                     }*/
  608.  
  609.  
  610.                     currentPoint.x += Math.cos(theta) * distance + ((shapeIndex[i].toX - currentPoint.x) * .027);
  611.                     currentPoint.y += Math.sin(theta) * distance + ((shapeIndex[i].toY - currentPoint.y) * .027);
  612.  
  613.  
  614.                     // check for bounds
  615.                     if (currentPoint.x < -(this.canvas.width * 0.1)) {
  616.                         currentPoint.x = this.canvas.width * 1.1;
  617.                         currentPoint.toX = this.canvas.width * 1.1 - (this.ran(20, 40) * 4)
  618.                     }
  619.                     if (currentPoint.x > this.canvas.width * 1.1) {
  620.                         currentPoint.x = -(this.canvas.width * 0.1);
  621.                         currentPoint.toX = -(this.canvas.width * 0.1) + (this.ran(20, 40) * 4);
  622.                     }
  623.  
  624.                     if (currentPoint.y < -(this.canvas.height * 0.1)) {
  625.                         currentPoint.y = this.canvas.height * 1.1;
  626.                         currentPoint.toY = this.canvas.height * 1.1 - (this.ran(20, 40) * 4)
  627.                     }
  628.                     if (currentPoint.y > this.canvas.height * 1.1) {
  629.                         currentPoint.y = -(this.canvas.height * 0.1);
  630.                         currentPoint.toY = -(this.canvas.height * 0.1) + (this.ran(20, 40) * 4)
  631.                     }
  632.  
  633.                     currentPoint.toX += Math.floor(this.impulsX * sizeMovement * 30 / 30) + (this.impulsX / 7 * currentPoint.randomPosX);
  634.                     currentPoint.toY += Math.floor(this.impulsY * sizeMovement * 30 / 30) + (this.impulsY / 7 * currentPoint.randomPosY);
  635.  
  636.                     //sparkle
  637.                     if (currentPoint.shrinkDelay >= 0) currentPoint.shrinkDelay = currentPoint.shrinkDelay - 0.5;
  638.  
  639.                     if (currentPoint.flashSize == true && currentPoint.shrinkDelay <= 0) {
  640.  
  641.                         ////start large
  642.                         if (currentPoint.baseRadius == currentPoint.baseRadiusOriginal && currentPoint.shrinking == false) {
  643.                             currentPoint.baseRadius = Nodes.imgsToDraw[Math.floor(this.currentShapeIndex)].maxParticleSize + 4;
  644.                             currentPoint.alpha = 1;
  645.                             currentPoint.color = 'rgba(' + currentPoint.a + ',' + currentPoint.g + ',' + currentPoint.b + ',' + '1)';
  646.                             currentPoint.shrinking = true;
  647.                         }
  648.  
  649.                         ////dec
  650.                         currentPoint.baseRadius = (currentPoint.baseRadius - 0.3 > 1) ? currentPoint.baseRadius - 0.3 : 1;
  651.                         currentPoint.alpha = (currentPoint.alpha >= currentPoint.originalAlpha && currentPoint.originalAlpha != 1) ? currentPoint.alpha - 0.01 : currentPoint.originalAlpha;
  652.                         currentPoint.color = 'rgba(' + currentPoint.r + ',' + currentPoint.g + ',' + currentPoint.b + ',' + currentPoint.alpha + ')';
  653.  
  654.                         ////end size
  655.                         if (currentPoint.baseRadius <= currentPoint.baseRadiusOriginal && currentPoint.shrinking == true) {
  656.                             currentPoint.baseRadius = currentPoint.baseRadiusOriginal;
  657.                             currentPoint.flashSize = false
  658.                             currentPoint.shrinking = false;
  659.                             currentPoint.shrinkDelay = Math.random() * 100;
  660.                             currentPoint.color = 'rgba(' + currentPoint.r + ',' + currentPoint.g + ',' + currentPoint.b + ',' + currentPoint.originalAlpha + ')';
  661.  
  662.                             ////set new random one
  663.                             shapeIndex[Math.floor(Math.random() * shapeIndex.length)].flashSize = true;
  664.                         }
  665.  
  666.  
  667.                     }
  668.  
  669.  
  670.                 }
  671.  
  672.             }
  673.  
  674.         }
  675.  
  676.  
  677.     },
  678.  
  679.  
  680.     drawPoints: function () {
  681.  
  682.         var i, currentPoint;
  683.         //if(!jQuery.isArray(Nodes.points[Nodes.currentShapeIndex]) && typeof Nodes.points[Nodes.currentShapeIndex] === 'object') {
  684.         //  var shapeIndex = this.points[Math.floor(this.currentShapeIndex)][0];
  685.         //} else {
  686.         var shapeIndex = this.points[Math.floor(this.currentShapeIndex)];
  687.         //}
  688.  
  689.         for (i = 0; i < shapeIndex.length; i++) {
  690.  
  691.             currentPoint = shapeIndex[i];
  692.  
  693.             var randomNum = shapeIndex[i].randomNum;
  694.             if (randomNum < 0.1) randomNum = 0.3;
  695.  
  696.             //skip drawing some particles during trans
  697.             if (currentPoint.hiddenDuringTrans == true && Nodes.randomMovement == true) continue;
  698.  
  699.             // Draw the particle
  700.             this.context.beginPath();
  701.             this.context.arc(currentPoint.x, currentPoint.y, currentPoint.baseRadius, 0, Math.PI * 2, true);
  702.             this.context.fillStyle = currentPoint.color;
  703.             this.context.fill();
  704.             this.context.closePath();
  705.  
  706.         }
  707.     },
  708.  
  709.     draw: function () {
  710.  
  711.         //if($('.no-scroll').length > 0) {
  712.  
  713.         //box roll logic that will need to be bound
  714.         //$(Nodes.canvasID).parents('.nectar-box-roll').find('.canvas-bg.topBoxOut').length == 0 && $(Nodes.canvasID).parents('.nectar-box-roll').find('.canvas-bg.topBoxIn').length == 0
  715.  
  716.         var $that = this;
  717.  
  718.         if (Nodes.regularAnimation == true || Nodes.randomMovement == true) {
  719.  
  720.             Nodes.animation = requestAnimationFrame(Nodes.draw);
  721.  
  722.             //throttle fps to 60
  723.             Nodes.now = Date.now();
  724.             Nodes.elapsed = Nodes.now - Nodes.then;
  725.             if (Nodes.elapsed > 16.666) {
  726.                 Nodes.then = Nodes.now - (Nodes.elapsed % 16.666);
  727.                 //stop drawing when the slider is out of view
  728.                 if ($('#page-header-bg.out-of-sight').length == 0) {
  729.                     Nodes.clear();
  730.                     Nodes.updatePoints();
  731.                     Nodes.drawPoints();
  732.                 }
  733.             }
  734.  
  735.         }
  736.         else {
  737.             Nodes.fpsDec += 0.23;
  738.             Nodes.fps = (Nodes.fps >= 0) ? Nodes.fps - Nodes.fpsDec : 0;
  739.             Nodes.decMultiplier = 0.14;
  740.             setTimeout(function () {
  741.                 Nodes.animation = requestAnimationFrame(function () {
  742.                     if (Nodes.fps > 0) Nodes.draw()
  743.                 });
  744.                 // Drawing code goes here
  745.             }, 1000 / Nodes.fps);
  746.  
  747.             //stop drawing when the slider is out of view
  748.             if ($('#page-header-bg.out-of-sight').length == 0) {
  749.                 Nodes.clear();
  750.                 Nodes.updatePoints();
  751.                 Nodes.drawPoints();
  752.             }
  753.  
  754.         }
  755.  
  756.         //}
  757.     },
  758.  
  759.     clear: function () {
  760.         this.context.clearRect(0, 0, canvas.width, canvas.height);
  761.     },
  762.  
  763.     ran: function (min, max) {
  764.         return Math.floor(Math.random() * (max - min + 1)) + min;
  765.     },
  766.  
  767.     // The filereader has loaded the image... add it to image object to be drawn
  768.     loadData: function (data, index, index2, sequence) {
  769.  
  770.  
  771.         if (sequence == true) {
  772.             if (typeof this.bgImage[index] !== 'object') this.bgImage[index] = [];
  773.             this.bgImage[index][index2] = new Image;
  774.             this.bgImage[index][index2].src = data;
  775.         } else {
  776.             this.bgImage[index] = new Image;
  777.             this.bgImage[index].src = data;
  778.         }
  779.  
  780.         if (!jQuery.isArray(this.bgImage[index])) {
  781.             this.bgImage[index].onload = function () {
  782.                 Nodes.callDrawImageToBackground(index, index2);
  783.             }
  784.  
  785.  
  786.         } else {
  787.             this.bgImage[index][index2].onload = function () {
  788.                 Nodes.callDrawImageToBackground(index, index2);
  789.             }
  790.         }
  791.  
  792.  
  793.     },
  794.  
  795.     particlesRotate: function (skipInitialDelay) {
  796.  
  797.         initTimeOut = (skipInitialDelay == true) ? 0 : 800;
  798.  
  799.         setTimeout(function () {
  800.  
  801.             //interval between shapes - extra fo first load to balance initial scatter animation
  802.             var timeoutInterval = (Nodes.loaded == false) ? Nodes.rotateTimer + 1000 : Nodes.rotateTimer;
  803.  
  804.             Nodes.loaded = true;
  805.             setTimeout(function () {
  806.                 $(Nodes.canvasID).attr('data-loaded', 'true');
  807.             }, 1000);
  808.  
  809.             if (Nodes.imgsToDraw.length > 1) Nodes.timeoutHolder = setTimeout(function () {
  810.                 Nodes.particleRotateLogic(false)
  811.             }, timeoutInterval);
  812.  
  813.             Nodes.canvasBgColor();
  814.             initTextEffect(Nodes.canvasID);
  815.  
  816.  
  817.         }, initTimeOut);
  818.  
  819.         //fadeout loading animation
  820.         if (skipInitialDelay != true) {
  821.             $('#ajax-loading-screen').stop().transition({'opacity': 0}, 1000, function () {
  822.                 $(this).css({'display': 'none'});
  823.             });
  824.             $('#ajax-loading-screen .loading-icon').transition({'opacity': 0}, 1000)
  825.         }
  826.  
  827.     },
  828.  
  829.  
  830.     particleRotateLogic: function (seek) {
  831.  
  832.         //clear current timeout incase seeked
  833.         clearTimeout(Nodes.timeoutHolder);
  834.  
  835.         //don't switch during boxroll
  836.         if ($('.canvas-bg.topBoxOut').length > 0) {
  837.             //setTimeout( rotate, timeoutInterval);
  838.             return false;
  839.         }
  840.  
  841.         //chance for random movement or next shape
  842.         var explodeChance = (Nodes.disableExplosion == 'on') ? 0 : 0.4;
  843.         if (Math.random() > explodeChance || seek !== false) {
  844.  
  845.             //update shape index
  846.             if (seek !== false) {
  847.                 Nodes.prevShapeIndex = Nodes.currentShapeIndex;
  848.                 Nodes.currentShapeIndex = seek;
  849.             } else {
  850.                 Nodes.currentShapeIndex = (Nodes.currentShapeIndex + 1 == Nodes.imgsToDraw.length) ? 0 : Nodes.currentShapeIndex + 1;
  851.             }
  852.  
  853.             //slow particles during trans
  854.             if (Nodes.randomMovement == false) Nodes.decMultiplier = 0.06;
  855.             else {
  856.                 Nodes.decMultiplier = 0.06;
  857.             }
  858.  
  859.             //sequenced shape
  860.             /*if(!jQuery.isArray(Nodes.points[Nodes.currentShapeIndex]) && typeof Nodes.points[Nodes.currentShapeIndex] === 'object') {
  861.                 clearInterval(rotation);
  862.                 Nodes.sequenceActive = true;
  863.                 Nodes.particleSequenceRotate();
  864.             }*/
  865.  
  866.             var prevIndex = (Nodes.currentShapeIndex == Nodes.points.length) ? 0 : Math.floor(Nodes.currentShapeIndex - 1);
  867.             if (Math.floor(Nodes.currentShapeIndex) - 1 == -1) prevIndex = Nodes.points.length - 1;
  868.             var prevPrevIndex = (prevIndex - 1 == -1) ? Nodes.points.length - 1 : prevIndex - 1;
  869.  
  870.             //set next shape x/y pos to match the previos one after rnd movement
  871.             for (i = 0; i < Nodes.points[Nodes.currentShapeIndex].length; i++) {
  872.                 var mathRnd = Math.random();
  873.                 if (seek !== false) {
  874.                     var xPos = Nodes.points[Nodes.prevShapeIndex][Math.floor(mathRnd * Nodes.points[Nodes.prevShapeIndex].length)].x;
  875.                     var yPos = Nodes.points[Nodes.prevShapeIndex][Math.floor(mathRnd * Nodes.points[Nodes.prevShapeIndex].length)].y;
  876.                 } else {
  877.                     if (Nodes.randomMovement == true) {
  878.                         //for(j = 0; j < Nodes.points[prevIndex].length; j++){
  879.                         var mathRnd = Math.random();
  880.                         //if(Nodes.points[prevIndex][Math.floor(mathRnd*Nodes.points[prevIndex].length)].hiddenDuringTrans == false && Nodes.points[prevIndex][Math.floor(mathRnd*Nodes.points[prevIndex].length)].used == false) {
  881.                         //Nodes.points[prevIndex][Math.floor(mathRnd*Nodes.points[prevIndex].length)].used = true;
  882.                         var xPos = Nodes.points[prevIndex][Math.floor(mathRnd * Nodes.points[prevIndex].length)].x;
  883.                         var yPos = Nodes.points[prevIndex][Math.floor(mathRnd * Nodes.points[prevIndex].length)].y;
  884.                         //var color = Nodes.points[prevIndex][Math.floor(mathRnd*Nodes.points[prevIndex].length)].color;
  885.                         //Nodes.points[Nodes.currentShapeIndex][i].color = color;
  886.                         //  break;
  887.                         //}
  888.                         //hide duplicate points now and fade them in mid way as they're going to the next shape
  889.                         /*else if(Nodes.points[prevIndex][Math.floor(mathRnd*Nodes.points[prevIndex].length)].hiddenDuringTrans == false && Nodes.points[prevIndex][Math.floor(mathRnd*Nodes.points[prevIndex].length)].used == true) {
  890.                             var currentPoint = Nodes.points[Nodes.currentShapeIndex][i];
  891.                             var xPos = Nodes.points[prevIndex][Math.floor(mathRnd*Nodes.points[prevIndex].length)].x;
  892.                             var yPos = Nodes.points[prevIndex][Math.floor(mathRnd*Nodes.points[prevIndex].length)].y;
  893.                             currentPoint.duplicate = true;
  894.                             currentPoint.alpha = 0;
  895.                                currentPoint.color = 'rgba(' + currentPoint.a + ',' + currentPoint.g + ',' + currentPoint.b + ',' +'0)';
  896.  
  897.                                break;
  898.                         }
  899.                      }*/
  900.                     } else {
  901.                         var xPos = Nodes.points[prevIndex][Math.floor(mathRnd * Nodes.points[prevIndex].length)].x;
  902.                         var yPos = Nodes.points[prevIndex][Math.floor(mathRnd * Nodes.points[prevIndex].length)].y;
  903.                     }
  904.  
  905.  
  906.                     //reset used attr on end of loop
  907.                     //if(i == Nodes.points[Nodes.currentShapeIndex].length - 1) {
  908.                     //  for(j = 0; j < Nodes.points[prevIndex].length; j++) {
  909.                     //      Nodes.points[prevIndex][j].used = false;
  910.                     //  }
  911.                     //}
  912.  
  913.  
  914.                 }
  915.  
  916.                 Nodes.points[Nodes.currentShapeIndex][i].x = xPos;
  917.                 Nodes.points[Nodes.currentShapeIndex][i].y = yPos;
  918.  
  919.             }
  920.  
  921.             var $paginationTimeout = (Nodes.randomMovement == true) ? 300 : 300;
  922.             Nodes.randomMovement = false;
  923.             $(Nodes.canvasID).attr('data-randomMovement', 'false');
  924.  
  925.             //reset points to prev shap after animation is complete
  926.             for (i = 0; i < Nodes.points[prevIndex].length; i++) {
  927.                 var mathRnd = Math.random();
  928.                 var xPos = Nodes.points[prevPrevIndex][Math.floor(mathRnd * Nodes.points[prevPrevIndex].length)].originalX;
  929.                 var yPos = Nodes.points[prevPrevIndex][Math.floor(mathRnd * Nodes.points[prevPrevIndex].length)].originalY;
  930.                 Nodes.points[prevIndex][i].x = xPos;
  931.                 Nodes.points[prevIndex][i].y = yPos;
  932.  
  933.                 Nodes.points[prevIndex][i].toX = Math.random() * (window.innerWidth);
  934.                 Nodes.points[prevIndex][i].toY = Math.random() * (window.innerHeight);
  935.  
  936.                 //reset flash chance
  937.                 var flashChance = (Math.random() < 0.5) ? true : false;
  938.                 Nodes.points[prevIndex][i].flashSize = flashChance;
  939.             }
  940.  
  941.             if (this.reactionSensitivity > 4) this.reactionSensitivity = (window.innerWidth > 690) ? 4 : 1;
  942.  
  943.             //handle captions
  944.             if (seek !== false) {
  945.                 var currentCaptionIndex = seek + 1;
  946.                 var nextCaptionIndex = seek + 1;
  947.             } else {
  948.                 var currentCaptionIndex = (Nodes.currentShapeIndex == 0) ? Nodes.imgsToDraw.length : Nodes.currentShapeIndex;
  949.                 var nextCaptionIndex = (Nodes.currentShapeIndex == Nodes.points.length) ? 0 : Math.floor(Nodes.currentShapeIndex + 1);
  950.             }
  951.  
  952.             Nodes.shapeTextDisplay(currentCaptionIndex, nextCaptionIndex, seek);
  953.  
  954.             //update pagination
  955.             var $selector = ($('.nectar-box-roll').length > 0) ? '.nectar-box-roll' : '.nectar-particles';
  956.             if ($(Nodes.canvasID).parents($selector).find('.pagination-navigation').length > 0 && seek == false) {
  957.                 setTimeout(function () {
  958.                     $(Nodes.canvasID).parents($selector).find('.pagination-dot').eq(Nodes.currentShapeIndex).click();
  959.                 }, $paginationTimeout);
  960.             }
  961.  
  962.             var timeoutInterval = Nodes.rotateTimer;
  963.             Nodes.timeoutHolder = setTimeout(function () {
  964.                 Nodes.particleRotateLogic(false)
  965.             }, timeoutInterval);
  966.  
  967.         } else {
  968.             var timeoutInterval = 2800;
  969.             Nodes.timeoutHolder = setTimeout(function () {
  970.                 Nodes.particleRotateLogic(false)
  971.             }, timeoutInterval);
  972.  
  973.             Nodes.randomMovement = true;
  974.             $(Nodes.canvasID).attr('data-randomMovement', 'true');
  975.  
  976.             Nodes.impulsX = Math.random() * 600 - 300;
  977.             Nodes.impulsY = -Math.random() * 300;
  978.             for (i = 0; i < Nodes.points[Nodes.currentShapeIndex].length; i++) {
  979.                 var currentPoint = Nodes.points[Nodes.currentShapeIndex][i];
  980.                 currentPoint.randomPosX = Math.random() * 6;
  981.                 currentPoint.randomPosY = Math.random() * 6;
  982.             }
  983.  
  984.         }
  985.  
  986.         Nodes.canvasBgColor();
  987.  
  988.  
  989.     },
  990.  
  991.     canvasBgColor: function () {
  992.  
  993.         jQuery(Nodes.canvasID).parents('.nectar-particles').find('.canvas-bg').css({
  994.             'background-color': Nodes.imgsToDraw[Nodes.currentShapeIndex].backgroundColor
  995.         });
  996.     },
  997.  
  998.     resetShapeTextTimeout: null,
  999.     shapeTextDisplay: function (index, index2, seek) {
  1000.  
  1001.         clearTimeout(Nodes.resetShapeTextTimeout);
  1002.  
  1003.         var $rotate = 0;
  1004.         var $selector = ($('.nectar-box-roll').length > 0) ? '.nectar-box-roll' : '.nectar-particles';
  1005.         jQuery(Nodes.canvasID).parents($selector).find('.inner-wrap').css('z-index', 10);
  1006.  
  1007.         if (seek !== false) {
  1008.             jQuery(Nodes.canvasID).parents($selector).find('.inner-wrap:not(.shape-' + index + ')').each(function (i) {
  1009.                 $(this).find('> *').each(function (i) {
  1010.                     $(this).stop(true, true).delay(i * 150).transition({'opacity': '0'}, 250, 'ease');
  1011.                 });
  1012.             });
  1013.             Nodes.resetShapeTextTimeout = setTimeout(function () {
  1014.                 jQuery(Nodes.canvasID).parents($selector).find('.inner-wrap:not(.shape-' + index + ') > *').delay(50).transition({
  1015.                     'rotateX': $rotate,
  1016.                     'y': '30px'
  1017.                 }, 0);
  1018.             }, jQuery(Nodes.canvasID).parents($selector).find('.inner-wrap:not(.shape-' + index + ')').length * 200);
  1019.  
  1020.         } else {
  1021.             jQuery(Nodes.canvasID).parents($selector).find('.shape-' + index + ' > *').each(function (i) {
  1022.                 $(this).stop(true, true).delay(i * 150).transition({'opacity': '0'}, 250, 'ease');
  1023.             });
  1024.  
  1025.             Nodes.resetShapeTextTimeout = setTimeout(function () {
  1026.                 jQuery(Nodes.canvasID).parents($selector).find('.shape-' + index + ' > *').transition({
  1027.                     'rotateX': $rotate,
  1028.                     'y': '30px'
  1029.                 }, 0);
  1030.             }, jQuery(Nodes.canvasID).parents($selector).find('.shape-' + index + ' > *').length * 200);
  1031.  
  1032.         }
  1033.  
  1034.         jQuery(Nodes.canvasID).parents($selector).find('.shape-' + index2).css('z-index', 100);
  1035.         jQuery(Nodes.canvasID).parents($selector).find('.shape-' + index2 + ' > *').each(function (i) {
  1036.             $(this).stop(true, true).delay(jQuery(Nodes.canvasID).parents($selector).find('.shape-' + index + ' > *').length * 150 + (i * 175)).transition({
  1037.                 'opacity': '1',
  1038.                 'y': 0,
  1039.                 'rotateX': '0'
  1040.             }, 700, 'ease');
  1041.         });
  1042.  
  1043.     },
  1044.  
  1045.  
  1046.     particleSequenceRotate: function () {
  1047.         setInterval(function () {
  1048.  
  1049.  
  1050.             var seqXPos, seqYPos, currentPoint, otherPoint, otherPointCache, distance, nextIndex, closestMatchX,
  1051.                 closestMatchY, def;
  1052.  
  1053.  
  1054.             for (var i = 0; i < Nodes.points.length; i++) {
  1055.  
  1056.                 //check for sequenced
  1057.                 if (!jQuery.isArray(Nodes.points[i]) && typeof Nodes.points[i] === 'object') {
  1058.  
  1059.                     for (j = 0; j < 1; j++) {
  1060.  
  1061.  
  1062.  
  1063.                         //nextIndex = ( j+1 > Object.keys(Nodes.points[i]).length -1 ) ?  0 : j+1;
  1064.  
  1065.                         for (var k = 0; k < Nodes.points[i][0].length; k++) {
  1066.  
  1067.                             currentPoint = Nodes.points[i][0][k];
  1068.  
  1069.                             def = 1000;
  1070.                             closestMatchX = 0;
  1071.                             closestMatchY = 0;
  1072.  
  1073.                             for (var u = 0; u < Nodes.points[i][Nodes.currentSequenceIndex].length; u++) {
  1074.  
  1075.                                 otherPoint = Nodes.points[i][Nodes.currentSequenceIndex][u];
  1076.  
  1077.                                 if (otherPoint.sequenceUsed != true) {
  1078.  
  1079.                                     distance = Math.sqrt((otherPoint.originalX - currentPoint.x) * (otherPoint.originalX - currentPoint.x) + (otherPoint.originalY - currentPoint.y) * (otherPoint.originalY - currentPoint.y));
  1080.  
  1081.                                     if (distance <= def && def > 10) {
  1082.                                         def = distance;
  1083.  
  1084.                                         currentPoint.seqX = otherPoint.originalX;
  1085.                                         currentPoint.seqY = otherPoint.originalY;
  1086.  
  1087.                                         otherPointCache = otherPoint;
  1088.                                     }
  1089.  
  1090.  
  1091.                                     if (u == Nodes.points[i][Nodes.currentSequenceIndex].length - 1) {
  1092.  
  1093.                                         otherPointCache.sequenceUsed = true;
  1094.                                     }
  1095.  
  1096.                                 }
  1097.                             }
  1098.  
  1099.                             //clear sequence used
  1100.                             if (k == Nodes.points[i][0].length - 1) {
  1101.                                 for (var u = 0; u < Nodes.points[i][Nodes.currentSequenceIndex].length; u++) {
  1102.                                     Nodes.points[i][Nodes.currentSequenceIndex][u].sequenceUsed = false;
  1103.                                 }
  1104.                             }
  1105.  
  1106.                         }
  1107.  
  1108.                     }
  1109.  
  1110.                 }
  1111.             }
  1112.  
  1113.  
  1114.             //update shape index
  1115.             Nodes.currentSequenceIndex = (Nodes.currentSequenceIndex + 1 == Object.keys(Nodes.points[Nodes.currentShapeIndex]).length) ? 0 : Nodes.currentSequenceIndex + 1;
  1116.         }, 80);
  1117.     },
  1118.     callDrawImageToBackground: function (index, index2) {
  1119.  
  1120.         Nodes.loadedCount += 1;
  1121.  
  1122.         //wait until all are loaded
  1123.         if (Nodes.loadedCount == Nodes.totalImgCount) {
  1124.  
  1125.  
  1126.             for (var i = 0; i < Nodes.imgsToDraw.length; i++) {
  1127.  
  1128.                 if (!jQuery.isArray(this.bgImage[i])) {
  1129.  
  1130.                     Nodes.drawImageToBackground(i, null, false, true);
  1131.                 } else {
  1132.                     for (j = 0; j < Nodes.imgsToDraw[i].shape.length; j++) {
  1133.  
  1134.                         Nodes.drawImageToBackground(i, j, false, true);
  1135.                     }
  1136.                 }
  1137.             }
  1138.  
  1139.         }
  1140.     },
  1141.     // Image is loaded... draw to bg canvas
  1142.     drawImageToBackground: function (index, index2, resize, sequence) {
  1143.  
  1144.         shapeIndex = (index2 == null) ? this.bgImage[index] : this.bgImage[index][index2];
  1145.  
  1146.         this.bgCanvas = document.createElement('canvas');
  1147.         this.bgCanvas.width = this.canvas.width;
  1148.         this.bgCanvas.height = this.canvas.height;
  1149.  
  1150.         var newWidth, newHeight;
  1151.         var userResized = resize;
  1152.         var $selector = ($('.nectar-box-roll').length > 0) ? '.nectar-box-roll' : '.nectar-particles';
  1153.         var heightDiff = (Nodes.textPosition == 'bottom' && Nodes.textPositionH == 'center') ? $(Nodes.canvasID).parents($selector).find('.inner-wrap').height() / 1.3 + 50 : 0;
  1154.         if (this.bgCanvas.height < 650) heightDiff = heightDiff / 2;
  1155.  
  1156.         // If the image is too big for the screen... scale it down.
  1157.         if (shapeIndex.width > this.bgCanvas.width - 50 - heightDiff || shapeIndex.height > this.bgCanvas.height - 50 - heightDiff) {
  1158.  
  1159.             var maxRatio = Math.max(shapeIndex.width / (this.bgCanvas.width - 50), shapeIndex.height / (this.bgCanvas.height - 100 - heightDiff));
  1160.  
  1161.             newWidth = shapeIndex.width / maxRatio;
  1162.             newHeight = shapeIndex.height / maxRatio;
  1163.  
  1164.  
  1165.             //change density based on ratio
  1166.             if (this.bgCanvas.width < 1600) {
  1167.  
  1168.                 if (maxRatio > 3 && maxRatio <= 4) {
  1169.                     this.imgsToDraw[index].density = this.imgsToDraw[index].densityOriginal - 3;
  1170.                     if (this.imgsToDraw[index].maxParticleSize >= 3) this.imgsToDraw[index].maxParticleSize = this.imgsToDraw[index].maxParticleSizeOriginal - 1;
  1171.  
  1172.                 }
  1173.                 else if (maxRatio > 4) {
  1174.                     if (this.bgCanvas.width > 800) this.imgsToDraw[index].density = this.imgsToDraw[index].densityOriginal - 4;
  1175.                     else this.imgsToDraw[index].density = this.imgsToDraw[index].densityOriginal - 5;
  1176.  
  1177.                     if (this.imgsToDraw[index].maxParticleSize > 2) this.imgsToDraw[index].maxParticleSize = 2;
  1178.                 } else if (maxRatio <= 3) {
  1179.                     this.imgsToDraw[index].density = this.imgsToDraw[index].densityOriginal;
  1180.                     this.imgsToDraw[index].maxParticleSize = this.imgsToDraw[index].maxParticleSizeOriginal;
  1181.  
  1182.                 }
  1183.             } else {
  1184.                 this.imgsToDraw[index].density = this.imgsToDraw[index].densityOriginal;
  1185.                 this.imgsToDraw[index].maxParticleSize = this.imgsToDraw[index].maxParticleSizeOriginal;
  1186.             }
  1187.  
  1188.  
  1189.         } else {
  1190.             newWidth = shapeIndex.width;
  1191.             newHeight = shapeIndex.height;
  1192.         }
  1193.  
  1194.         // Draw to background canvas
  1195.         var headerHeight = ($('#header-outer[data-transparent-header="true"]').length > 0 && $('body.mobile').length == 0 || $('#header-outer[data-permanent-transparent="1"]').length > 0) ? 0 : $('#header-outer').height();
  1196.  
  1197.  
  1198.         this.bgContext = this.bgCanvas.getContext('2d');
  1199.         this.bgContext.drawImage(shapeIndex, (this.canvas.width - newWidth) / 2, (((this.canvas.height + headerHeight / 2) - newHeight - heightDiff * 1) / 2), newWidth, newHeight);
  1200.         this.bgContextPixelData = this.bgContext.getImageData(0, 0, this.bgCanvas.width, this.bgCanvas.height);
  1201.         this.preparePoints(index, index2, userResized);
  1202.  
  1203.  
  1204.     },
  1205.  
  1206.  
  1207.     // Resize and redraw the canvas.
  1208.     onWindowResize: function () {
  1209.         cancelAnimationFrame(this.animation);
  1210.         if (Nodes.loadedCount == Nodes.imgsToDraw.length) {
  1211.             for (var i = 0; i < Nodes.imgsToDraw.length; i++) {
  1212.                 this.drawImageToBackground(i, null, true, false);
  1213.             }
  1214.         }
  1215.  
  1216.         //set mobile state
  1217.         this.onMobile = (this.canvas.width <= 690) ? true : false;
  1218.     }
  1219.  
  1220. }
  1221.  
  1222.  
  1223. if($shapes.length > 0) Nodes.init('#canvas');
  1224.  
  1225. var $selector = ($('.nectar-box-roll').length > 0) ? '.nectar-box-roll': '.nectar-particles';
  1226. function initTextEffect(canvasID){
  1227.     if($(canvasID).parents('#page-header-bg').hasClass('topBoxIn')) return false;
  1228.     $timeOut = ($(canvasID).parents('#page-header-bg[data-text-effect="rotate_in"]').length > 0) ? 800 : 0;
  1229.     setTimeout(function(){
  1230.         $(canvasID).parents($selector).find('.inner-wrap.shape-1').css('z-index',100);
  1231.         $(canvasID).parents($selector).find('.inner-wrap.shape-1 .top-heading').transition({'opacity':1, 'y': 0},0);
  1232.  
  1233.         $(canvasID).parents($selector).find('.span_6').find('.wraped').each(function(i){
  1234.             $(this).find('span').delay(i*370).transition({ rotateX: '0', 'opacity' : 1, y: 0},400,'easeOutQuad');
  1235.         });
  1236.  
  1237.         setTimeout(function(){
  1238.  
  1239.             $(canvasID).parents($selector).find('.span_6').find('.inner-wrap.shape-1 > *:not(.top-heading)').each(function(i){
  1240.                 $(this).delay(i*370).transition({ rotateX: '0', 'opacity' : 1, y: 0 },650,'easeOutQuad');
  1241.             });
  1242.  
  1243.             setTimeout(function(){
  1244.                 $('.scroll-down-wrap').removeClass('hidden');
  1245.  
  1246.                 if( Nodes.imgsToDraw.length > 1) {
  1247.                     $('.pagination-dots .pagination-dot').each(function(i){
  1248.                         $(this).delay(i*75).transition({ y: 0, 'opacity': 1}, 400);
  1249.                     });
  1250.                     $('.pagination-navigation .pagination-current').each(function(i){
  1251.                         $(this).delay(i*75).transition({ y: 0, 'opacity': 1, scale: 1.15}, 400);
  1252.                     });
  1253.  
  1254.                     //init pag
  1255.                     setTimeout(function(){
  1256.                         initGooPagination();
  1257.                     },$(canvasID).parents($selector).find('.pagination-dot').length*75 +370);
  1258.                 }
  1259.  
  1260.             }, $(canvasID).parents($selector).find('.inner-wrap.shape-1 > *:not(.top-heading)').length-1 * 400 + 370);
  1261.  
  1262.         }, ($(canvasID).parents($selector).find('.span_6').find('.wraped').length * 370));
  1263.  
  1264.     },$timeOut);
  1265.  
  1266. }
  1267.  
  1268.  
  1269. /*pagination*/
  1270.     var $dots=$($selector+" .pagination-dot")
  1271.             ,$current=$($selector+" .pagination-current")
  1272.             ,$items=$($selector+" .pagination-item")
  1273.  
  1274.             ,spacing=parseFloat($dots.css("height"))+(parseFloat($dots.css("marginBottom"))*2)
  1275.             ,halfSpacing=spacing/2
  1276.             ,startPos
  1277.  
  1278.             ,itemsSpacing=450
  1279.             ,lastItem=0
  1280.             ,lastItemR=0
  1281.             ,lastTime=Date.now()
  1282.         ;
  1283.  
  1284.     function initGooPagination(){
  1285.         startPos=0;
  1286.    
  1287.         $current.data("pos",{y:startPos});
  1288.        
  1289.         $dots.click(function(event){
  1290.  
  1291.  
  1292.             var $cur=$(this);
  1293.            
  1294.  
  1295.             var dest=($cur.index())*spacing;
  1296.             TweenMax.to($current.data("pos"),0.7,{
  1297.                 y:startPos+dest,
  1298.                 onUpdate:updatePos,
  1299.                 onComplete:updatePos,
  1300.                 ease:Quint.easeOut
  1301.             });
  1302.  
  1303.             //switch shape
  1304.             if(event.originalEvent !== undefined && !$cur.hasClass('active')) Nodes.particleRotateLogic($(this).index());
  1305.             $($selector+' .pagination-dot').removeClass('active');
  1306.             $cur.addClass('active');
  1307.  
  1308.         });
  1309.         $dots.eq(0).click();
  1310.  
  1311.         $items.click(function(){
  1312.             $dots.eq($(this).index()).click();
  1313.  
  1314.         });
  1315.         var dragging=false;
  1316.         var startDrag={x:0,y:0};
  1317.     }
  1318.  
  1319.     function updatePos(){
  1320.         var pos=$current.data("pos").y-startPos;
  1321.         var scale=pos%spacing;
  1322.         if(scale>halfSpacing){
  1323.           scale=halfSpacing-(scale-halfSpacing);
  1324.         }
  1325.         scale=1-((scale/halfSpacing)*0.35);
  1326.         TweenMax.set($current,{
  1327.             y:pos+startPos,
  1328.             scale:scale*1.15,
  1329.             force3D:true
  1330.         });
  1331.  
  1332.         var curItem=pos/spacing,
  1333.             curItemR=Math.round(curItem)
  1334.         ;
  1335.  
  1336.     }
  1337.  
  1338.  
  1339.  
  1340. //box roll
  1341. var perspect = 'not-rolled';
  1342. var animating = 'false';
  1343. function boxRoll(e,d) {
  1344.    
  1345.     if($('#slide-out-widget-area.open').length > 0) return false;
  1346.  
  1347.     if(perspect == 'not-rolled' && animating == 'false' && d == -1 && $('.nectar-box-roll canvas[data-loaded="true"]').length > 0) {
  1348.         perspect = 'rolled';
  1349.         animating = 'true';
  1350.         //stop mouse movement
  1351.         Nodes.mouse.x = 2000;
  1352.         Nodes.mouse.y = -2000;
  1353.  
  1354.         //slow fps
  1355.         Nodes.regularAnimation = false;
  1356.        
  1357.         setTimeout(function(){
  1358.                     animating ='false';
  1359.         },1650);
  1360.        
  1361.         clearTimeout(Nodes.timeoutHolder);
  1362.  
  1363.     }
  1364.  
  1365.     else if(perspect == 'rolled' && animating == 'false' && d == 1 && $(window).scrollTop() < 100) {
  1366.  
  1367.    
  1368.         perspect = 'not-rolled';
  1369.         animating = 'true';
  1370.        
  1371.         setTimeout(function(){
  1372.            
  1373.             animating ='false';
  1374.             Nodes.regularAnimation = true;
  1375.         },1600);
  1376.  
  1377.         if(Nodes.randomMovement == false) {
  1378.             setTimeout(function(){
  1379.                 //start animation again
  1380.                 Nodes.draw();
  1381.                 Nodes.fps = 43;
  1382.                 Nodes.fpsDec = 0.13;
  1383.                 Nodes.decMultiplier = 0.06;
  1384.             },1630);
  1385.  
  1386.         }
  1387.  
  1388.         if(Nodes.randomMovement == true) {
  1389.              Nodes.draw();
  1390.  
  1391.              setTimeout(function(){
  1392.                 Nodes.impulsX = Math.random()*800-400;
  1393.                 Nodes.impulsY = -Math.random()*400;
  1394.                
  1395.              },400);
  1396.              setTimeout(function(){  Nodes.particleRotateLogic(false); },3400);
  1397.              
  1398.         }
  1399.         //Nodes.randomMovement = false;
  1400.         if(Nodes.randomMovement == false) Nodes.particlesRotate(true);
  1401.    
  1402.     }
  1403.    
  1404. }
  1405.  
  1406. if($shapes.length > 0) {
  1407.  
  1408.   $('body').mousewheel(function(event, delta) {
  1409.     if($('#slide-out-widget-area.open.fullscreen').length > 0) return false;
  1410.     boxRoll(event,delta);
  1411.   });
  1412.  
  1413.   $('body').on('click','.nectar-box-roll .section-down-arrow',function(){
  1414.     boxRoll(null,-1);
  1415.     $(this).addClass('hovered');
  1416.     return false;
  1417.   });
  1418.  
  1419.   //touch
  1420.   if(navigator.userAgent.match(/(Android|iPod|iPhone|iPad|BlackBerry|IEMobile|Opera Mini)/)) {
  1421.     $('body').swipe({
  1422.       swipeStatus: function(event, phase, direction, distance, duration, fingers) {
  1423.         if($('#slide-out-widget-area.open').length > 0) return false;
  1424.         if(direction == 'up') {
  1425.           boxRoll(null,-1);
  1426.           if($('#ajax-content-wrap.no-scroll').length == 0) $('body').swipe("option", "allowPageScroll", 'vertical');
  1427.         } else if(direction == "down" && $(window).scrollTop() == 0) {
  1428.           boxRoll(null,1);
  1429.           $('body').swipe("option", "allowPageScroll", 'auto');
  1430.         }
  1431.       }
  1432.     });
  1433.  
  1434.   }
  1435.  
  1436. }
  1437. /*
  1438. if($('body[data-ajax-transitions="true"]').length > 0 && $('#ajax-loading-screen[data-method="ajax"]').length > 0 && !navigator.userAgent.match(/(Android|iPod|iPhone|iPad|BlackBerry|IEMobile|Opera Mini)/) && $(window).width() > 690 ) {
  1439.     $(window).on("pronto.request",initSetup);
  1440. } */
  1441.  
  1442. function updateRowRightPadding(d){
  1443.     $('.wpb_row.full-width-section').each(function(){
  1444.       if($(this).hasClass('extraPadding') && d == 1) {
  1445.         $(this).css('padding-right',parseInt($(this).css('padding-right')) - parseInt($('body').attr('data-scrollbar-width')) + 'px' ).removeClass('extraPadding');
  1446.       } else {
  1447.         $(this).css('padding-right',parseInt($('body').attr('data-scrollbar-width')) + parseInt($(this).css('padding-right')) + 'px' ).addClass('extraPadding');
  1448.       }
  1449.     });
  1450. }
  1451.  
  1452.  
  1453. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement