/* Copyright (C) YOOtheme GmbH, YOOtheme Proprietary Use License (http://www.yootheme.com/license) */

jQuery(function(d){function p(){g.remove(l);h.clear();k=new FSS.Plane(e.width*h.width,e.height*h.height,e.segments,e.slices);q=new FSS.Material(e.ambient,e.diffuse);l=new FSS.Mesh(k,q);g.add(l);var b,a;for(b=k.vertices.length-1;0<=b;b--)a=k.vertices[b],a.anchor=FSS.Vector3.clone(a.position),a.step=FSS.Vector3.create(Math.randomInRange(0.2,1),Math.randomInRange(0.2,1),Math.randomInRange(0.2,1)),a.time=Math.randomInRange(0,Math.PIM2)}function r(b,a){h.setSize(b,a);FSS.Vector3.set(s,h.halfWidth,h.halfHeight);
p()}function t(){m=Date.now()-u;var c,a,d,f,j,l=e.depth/2;FSS.Vector3.copy(b.bounds,s);FSS.Vector3.multiplyScalar(b.bounds,b.xyScalar);FSS.Vector3.setZ(n,b.zOffset);c=Math.sin(b.step[0]*m*b.speed);a=Math.cos(b.step[1]*m*b.speed);FSS.Vector3.set(n,b.bounds[0]*c,b.bounds[1]*a,b.zOffset);for(c=g.lights.length-1;0<=c;c--)a=g.lights[c],FSS.Vector3.setZ(a.position,b.zOffset),d=Math.clamp(FSS.Vector3.distanceSquared(a.position,n),b.minDistance,b.maxDistance),d=b.gravity*a.mass/d,FSS.Vector3.subtractVectors(a.force,
n,a.position),FSS.Vector3.normalise(a.force),FSS.Vector3.multiplyScalar(a.force,d),FSS.Vector3.set(a.acceleration),FSS.Vector3.add(a.acceleration,a.force),FSS.Vector3.add(a.velocity,a.acceleration),FSS.Vector3.multiplyScalar(a.velocity,b.dampening),FSS.Vector3.limit(a.velocity,b.minLimit,b.maxLimit),FSS.Vector3.add(a.position,a.velocity);for(f=k.vertices.length-1;0<=f;f--)j=k.vertices[f],c=Math.sin(j.time+j.step[0]*m*e.speed),a=Math.cos(j.time+j.step[1]*m*e.speed),d=Math.sin(j.time+j.step[2]*m*e.speed),
FSS.Vector3.set(j.position,e.xRange*k.segmentWidth*c,e.yRange*k.sliceHeight*a,e.zRange*l*d-l),FSS.Vector3.add(j.position,j.anchor);k.dirty=!0;h.render(g);requestAnimationFrame(t)}function v(){r(f.offsetWidth,f.offsetHeight);h.render(g)}if(void 0===window.orientation){var c=document.createElement("canvas");if(!c.getContext||!c.getContext("2d"))d("body").css({background:"url("+WarpThemePath+"/images/background/polygon/polygon.jpg) no-repeat fixed 50% 50%","background-size":"cover"});else{d("body").prepend('<div id="animatedbg" style="position:fixed; top:0; left:0; right:0; bottom:0; z-index:-1;"></div>');
var e={width:1.1,height:1.1,depth:10,segments:8,slices:8,xRange:0.3,yRange:0.3,zRange:0.3,ambient:"#7c5454",diffuse:"#555555",speed:5E-4},b={count:2,xyScalar:0.8,zOffset:200,ambient:"#880066",diffuse:"#FF8800",speed:8E-4,gravity:600,dampening:0.8,minLimit:0,maxLimit:15,minDistance:10,maxDistance:400,bounds:FSS.Vector3.create(),step:FSS.Vector3.create(Math.randomInRange(0.6,1),Math.randomInRange(0.6,1),Math.randomInRange(0.6,1))},m,u=Date.now(),s=FSS.Vector3.create(),n=FSS.Vector3.create(),f=document.getElementById("animatedbg"),
h=new FSS.CanvasRenderer,g,l,k,q;h.setSize(f.offsetWidth,f.offsetHeight);f.appendChild(h.element);g=new FSS.Scene;p();for(d=g.lights.length-1;0<=d;d--)c=g.lights[d],g.remove(c);h.clear();for(d=0;d<b.count;d++)c=new FSS.Light(b.ambient,b.diffuse),c.ambientHex=c.ambient.format(),c.diffuseHex=c.diffuse.format(),g.add(c),c.mass=Math.randomInRange(0.5,1),c.velocity=FSS.Vector3.create(),c.acceleration=FSS.Vector3.create(),c.force=FSS.Vector3.create();window.addEventListener("resize",v);r(f.offsetWidth,
f.offsetHeight);t()}}});
