/**
* particleground
*
* @author jonathan nicol - @mrjnicol
* @version 1.0.1
* @description creates a canvas based particle system background
*
* inspired by:
* http://requestlab.fr/
* http://disruptivebydesign.com/
*
* @license the mit license (mit)
*
* copyright (c) 2014 jonathan nicol - @mrjnicol
*
* permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "software"), to deal
* in the software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the software, and to permit persons to whom the software is
* furnished to do so, subject to the following conditions:
*
* the above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the software.
*
* the software is provided "as is", without warranty of any kind, express or
* implied, including but not limited to the warranties of merchantability,
* fitness for a particular purpose and noninfringement. in no event shall the
* authors or copyright holders be liable for any claim, damages or other
* liability, whether in an action of contract, tort or otherwise, arising from,
* out of or in connection with the software or the use or other dealings in
* the software.
*/
!function(a){function b(b,d){function e(){if(w){$canvas=a(''),v.prepend($canvas),p=$canvas[0],q=p.getcontext("2d"),f();for(var b=math.round(p.width*p.height/d.density),c=0;b>c;c++){var e=new l;e.setstackpos(c),x.push(e)}a(window).on("resize",function(){h()}),a(document).on("mousemove",function(a){y=a.pagex,z=a.pagey}),b&&!a&&window.addeventlistener("deviceorientation",function(){d=math.min(math.max(-event.beta,-30),30),c=math.min(math.max(-event.gamma,-30),30)},!0),g(),o("oninit")}}function f(){p.width=v.width(),p.height=v.height(),q.fillstyle=d.dotcolor,q.strokestyle=d.linecolor,q.linewidth=d.linewidth}function g(){if(w){s=a(window).width(),t=a(window).height(),q.clearrect(0,0,p.width,p.height);for(var b=0;b=0;i--)(x[i].position.x>v.width()||x[i].position.y>v.height())&&x.splice(i,1);var a=math.round(p.width*p.height/d.density);if(a>x.length)for(;a>x.length;){var b=new l;x.push(b)}else a=0;i--)x[i].setstackpos(i)}function j(){e=!0}function k(){e=!1,g()}function l(){switch(this.stackpos,this.active=!0,this.layer=math.ceil(3*math.random()),this.parallaxoffsetx=0,this.parallaxoffsety=0,this.position={x:math.ceil(math.random()*p.width),y:math.ceil(math.random()*p.height)},this.speed={},d.directionx){case"left":this.speed.x=+(-d.maxspeedx+math.random()*d.maxspeedx-d.minspeedx).tofixed(2);break;case"right":this.speed.x=+(math.random()*d.maxspeedx+d.minspeedx).tofixed(2);break;default:this.speed.x=+(-d.maxspeedx/2+math.random()*d.maxspeedx).tofixed(2),this.speed.x+=this.speed.x>0?d.minspeedx:-d.minspeedx}switch(d.directiony){case"up":this.speed.y=+(-d.maxspeedy+math.random()*d.maxspeedy-d.minspeedy).tofixed(2);break;case"down":this.speed.y=+(math.random()*d.maxspeedy+d.minspeedy).tofixed(2);break;default:this.speed.y=+(-d.maxspeedy/2+math.random()*d.maxspeedy).tofixed(2),this.speed.x+=this.speed.y>0?d.minspeedy:-d.minspeedy}}function m(a,b){return b?void(d[a]=b):d[a]}function n(){v.find(".pg-canvas").remove(),o("ondestroy"),v.removedata("plugin_"+c)}function o(a){void 0!==d[a]&&d[a].call(u)}var p,q,r,s,t,u=b,v=a(b),w=!!document.createelement("canvas").getcontext,x=[],y=0,z=0,a=!navigator.useragent.match(/(iphone|ipod|ipad|android|blackberry|bb10|mobi|tablet|opera mini|nexus 7)/i),b=!!window.deviceorientationevent,c=0,d=0,e=!1;return d=a.extend({},a.fn[c].defaults,d),l.prototype.draw=function(){q.beginpath(),q.arc(this.position.x+this.parallaxoffsetx,this.position.y+this.parallaxoffsety,d.particleradius/2,0,2*math.pi,!0),q.closepath(),q.fill(),q.beginpath();for(var a=x.length-1;a>this.stackpos;a--){var b=x[a],c=this.position.x-b.position.x,e=this.position.y-b.position.y,f=math.sqrt(c*c+e*e).tofixed(2);fv.width()&&(this.position.x=0-this.parallaxoffsetx);break;default:(this.position.x+this.speed.x+this.parallaxoffsetx>v.width()||this.position.x+this.speed.x+this.parallaxoffsetx<0)&&(this.speed.x=-this.speed.x)}switch(d.directiony){case"up":this.position.y+this.speed.y+this.parallaxoffsety<0&&(this.position.y=v.height()-this.parallaxoffsety);break;case"down":this.position.y+this.speed.y+this.parallaxoffsety>v.height()&&(this.position.y=0-this.parallaxoffsety);break;default:(this.position.y+this.speed.y+this.parallaxoffsety>v.height()||this.position.y+this.speed.y+this.parallaxoffsety<0)&&(this.speed.y=-this.speed.y)}this.position.x+=this.speed.x,this.position.y+=this.speed.y},l.prototype.setstackpos=function(a){this.stackpos=a},e(),{option:m,destroy:n,start:k,pause:j}}var c="particleground";a.fn[c]=function(d){if("string"==typeof arguments[0]){var e,f=arguments[0],g=array.prototype.slice.call(arguments,1);return this.each(function(){a.data(this,"plugin_"+c)&&"function"==typeof a.data(this,"plugin_"+c)[f]&&(e=a.data(this,"plugin_"+c)[f].apply(this,g))}),void 0!==e?e:this}return"object"!=typeof d&&d?void 0:this.each(function(){a.data(this,"plugin_"+c)||a.data(this,"plugin_"+c,new b(this,d))})},a.fn[c].defaults={minspeedx:.1,maxspeedx:.7,minspeedy:.1,maxspeedy:.7,directionx:"center",directiony:"center",density:1e4,dotcolor:"#666666",linecolor:"#666666",particleradius:7,linewidth:1,curvedlines:!1,proximity:100,parallax:!0,parallaxmultiplier:5,oninit:function(){},ondestroy:function(){}}}(jquery),/**
* requestanimationframe polyfill by erik möller. fixes from paul irish and tino zijdel
* @see: http://paulirish.com/2011/requestanimationframe-for-smart-animating/
* @see: http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
* @license: mit license
*/
function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c