var animationData = [
    {
        name: "bjork",
        waypoints: [
            {
                duration: 2000,
                easeFunction: 6,
                px: 222.81633800598513,
                py: -299.81280185547837,
                pz: 105.00392983599116,
                qx: 0.7271461030878897,
                qy: 0.023414709608057256,
                qz: 0.0033956289871526907,
                qw: 0.686074898128388
            }
        ]
    },
    {
        name: "intro",
        waypoints: [
            {
                duration: 1,
                easeFunction: 0,
                px: -432.24287712041877,
                py: 254.3361800641652,
                pz: -121618.519394506046,
                qx: 0.0343159980140686,
                qy: -0.013569541796805326,
                qz: 0.15456563990674532,
                qw: -0.9872931392327021
            },
            {
                speed: 30,
                easeFunction: 0,
                px: -432.24287712041877,
                py: 254.3361800641652,
                pz: -21618.519394506046,
                qx: -0.01163665112777878,
                qy: -0.013225370406509864,
                qz: -0.5192253021526853,
                qw: -0.8544558288949948
            },
            {
                speed: 8.8,
                easeFunction: 2,
                px: 119.41319635681427,
                py: 815.4150324921295,
                pz: -4527.054989341502,
                qx: -0.01163665112777878,
                qy: -0.013225370406509864,
                qz: -0.5192253021526853,
                qw: -0.8544558288949948
            },
            {
                speed: 1.2,
                easeFunction: 1,
                px: 814.1188545437097,
                py: 718.604418103952,
                pz: -3998.636475556927,
                qx: -0.04317441606270132,
                qy: -0.09106418041351519,
                qz: -0.043586696591018215,
                qw: 0.9939534620511957
            },
            {
                speed: 1.2,
                easeFunction: 2,
                px: -58.453884688994435,
                py: -1882.4386661369526,
                pz: 1866.7301363667675,
                qx: -0.8029811537107124,
                qy: 0.3864564694358206,
                qz: 0.13540231107426082,
                qw: -0.4330575922118876
            },
            {
                speed: 1.4,
                easeFunction: 1,
                px: 222.81633800598513,
                py: -299.81280185547837,
                pz: 105.00392983599116,
                qx: 0.7271461030878897,
                qy: 0.023414709608057256,
                qz: 0.0033956289871526907,
                qw: 0.686074898128388
            }
        ]
    },
    {
        name: "newSongBtn",
        waypoints: [
            {
                duration: 2000,
                easeFunction: 6,
                px: -2362.380737790742,
                py: 672.6233871885859,
                pz: 187.793474163967,
                qx: -0.3679241986142157,
                qy: 0.5661342241462031,
                qz: -0.5667809300653299,
                qw: -0.47210507478607455
            }
        ]
    },
    {
        name: "newsBtn",
        waypoints: [
            {
                duration: 2000,
                easeFunction: 6,
                px: 4110.341128121732,
                py: 5030.919520106762,
                pz: 2772.0739243285557,
                qx: 0.28213468591888047,
                qy: 0.6960501726225545,
                qz: -0.6320567770474661,
                qw: 0.1908360730625792
            }
        ]
    },
    {
        name: "forumBtn",
        waypoints: [
            {
                duration: 2000,
                easeFunction: 6,
                px: 772.7060972785458,
                py: -264.2051143987834,
                pz: 215.13891962994956,
                qx: -0.7042835744838258,
                qy: -0.26622935633593536,
                qz: 0.31064705059833114,
                qw: -0.5801766855810458
            }
        ]
    },
    {
        name: "storeBtn",
        waypoints: [
            {
                duration: 2000,
                easeFunction: 0,
                px: 1654.4292267534447,
                py: 489.6641653893199,
                pz: -1349.0402329973988,
                qx: -0.5746118073542715,
                qy: 0.29745374162923827,
                qz: -0.3554337668873689,
                qw: -0.6745438308931917
            },
            {
                duration: 3700,
                easeFunction: 5,
                px: 1266.8836990247562,
                py: 289.19362353148097,
                pz: -1202.9217247029349,
                qx: 0.059006862390738754,
                qy: -0.07166452060984177,
                qz: -0.6423140090029718,
                qw: 0.760798988245317
            }
        ]
    },
    {
        name: "facebookBtn",
        waypoints: [
            {
                duration: 2000,
                easeFunction: 6,
                px: 218.899222270693,
                py: 959.4841586222396,
                pz: -134.9835672869272,
                qx: 0.10229380474866225,
                qy: -0.9015783385989482,
                qz: -0.406957509649342,
                qw: 0.10525237393608958
            }
        ]
    },
    {
        name: "twitterBtn",
        waypoints: [
            {
                duration: 2000,
                easeFunction: 6,
                px: 396.5053518876405,
                py: 313.1038797905428,
                pz: -140.72535874338172,
                qx: 0.8385511574809927,
                qy: 0.47963188817325625,
                qz: -0.08358574412128233,
                qw: -0.24453758711972953
            }
        ]
    },
    {
        name: "youtubeBtn",
        waypoints: [
            {
                duration: 2000,
                easeFunction: 6,
                px: 481.46013577160267,
                py: -128.16191721686525,
                pz: -920.5119841010187,
                qx: 0.126054933657225,
                qy: 0.26857523091950347,
                qz: 0.8332255241131847,
                qw: 0.466596962059889
            }
        ]
    },
    {
        name: "creditsBtn",
        waypoints: [
            {
                duration: 2000,
                easeFunction: 6,
                px: -1106.5403462641702,
                py: 2068.7921905879675,
                pz: 776.8293762353782,
                qx: -0.4094082672710558,
                qy: 0.5176413502809832,
                qz: -0.15626617695482697,
                qw: 0.7348558941107364
            },
            {
                duration: 4500,
                easeFunction: 1,
                px: -941.5872866211714,
                py: 2169.211188347568,
                pz: 676.9892032212725,
                qx: 0.7297891854148035,
                qy: -0.22319351040708554,
                qz: 0.5467376678781458,
                qw: 0.3444855937291037
            }
        ]
    },
    {
        name: "pastBtn",
        waypoints: [
            {
				duration: 2000,
                easeFunction: 6,
                px: 1057.190011120911,
                py: 513.0058456685329,
                pz: -2986.690447587023,
                qx: -0.056002106140770155,
                qy: -0.03985445547764202,
                qz: -0.44976548478395195,
                qw: 0.8904978355860801
            }
        ]
    },
    {
		name: "discographyBtn",
		waypoints: [
			{duration: 2000,
                easeFunction: 0,
                px: 999.6591744637453,
                py: 438.72018176471477,
                pz: 60.668658383242175,
                qx: 0.6499104285196987,
                qy: -0.3220152088203255,
                qz: 0.6565472446356259,
                qw: 0.20704674774341073
             },
             {
             	duration: 2700,
                easeFunction: 5,
             	px: 715.450695473054, 
             	py: 428.95962552820765, 
             	pz: 201.4522977515128, 
             	qx: -0.5283423542874325, 
             	qy: -0.3910846293571595, 
             	qz: -0.44371358404356326, 
             	qw: 0.6091185637310869
             }
		]
	},
	{
		name: "gigographyBtn",
		waypoints: [
			{
				duration: 1500, 
				easeFunction: 0, 
				px: 0, 
				py: 0, 
				pz: 0, 
				qx: -0.06761884562824161, 
				qy: 0.9024443339753593, 
				qz: 0.08377255698388075, 
				qw: -0.41713795618243243
			},
			{
				duration: 3200,
                easeFunction: 5,
				px: 741.5583628886433, 
				py: 207.6129129150224, 
				pz: -637.9561684166514, 
				qx: 0.15983125017144648, 
				qy: 0.31891902370656605, 
				qz: 0.0017945011118057342, 
				qw: -0.934206298176396
			}
		]
	},
	{
		name: "videosBtn",
		waypoints: [
			{
				duration: 2000, 
				easeFunction: 0, 
				px: 1055.762093422871, 
				py: -295.9683331302298, 
				pz: 554.7496434113641, 
				qx: -0.8419275021798378, 
				qy: 0.0963484238437811, 
				qz: -0.5203331276941187, 
				qw: 0.1054916988208442
			},{
				duration: 3700,
                easeFunction: 5,
				px: 544.3445741763644, 
				py: 69.20226956408851, 
				pz: -319.00272338614616, 
				qx: -0.7188736005719143, 
				qy: -0.533797577756708, 
				qz: 0.059005817833539156, 
				qw: 0.44136063014687893
			}
		]
	},
	{
		name: "archiveBtn",
		waypoints: [
			{
				duration: 2000, 
				easeFunction: 0, 
				px: -3354.2761912904625, 
				py: 939.315655335069, 
				pz: 341.34635223541886, 
				qx: -0.06009556348365909, 
				qy: -0.4932305043743597, 
				qz: -0.00634441831717744, 
				qw: 0.8677971774328478
			},{
				duration: 3700,
                easeFunction: 5,
				px: 1055.762093422871, 
				py: -295.9683331302298, 
				pz: 554.7496434113641, 
				qx: -0.8419275021798378, 
				qy: 0.0963484238437811, 
				qz: -0.5203331276941187, 
				qw: 0.1054916988208442
			}
		]
	}


];




var animationNameToIndex = {};

/* 0 is Linear */ 
/* 1 */ function quadEaseIn(t, b, c, d) { return c * (t /= d) * t + b; }
/* 2 */ function quadEaseOut(t, b, c, d) { return -c * (t /= d) * (t - 2) + b; }
/* 3 */ function quadEaseInOut(t, b, c, d) { return ((t /= d / 2) < 1) ? c / 2 * t * t + b : -c / 2 * ((--t) * (t - 2) - 1) + b; }
/* 4 */ function cubicEaseIn(t, b, c, d) { return c * (t /= d) * t * t + b; }
/* 5 */ function cubicEaseOut(t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b; }
/* 6 */ function cubicEaseInOut(t, b, c, d) { return ((t /= d / 2) < 1) ? c / 2 * t * t * t + b : c / 2 * ((t -= 2) * t * t + 2) + b; }



function prepareAnimationData()
{
	for(var i=0; i < animationData.length; i++)
	{
		animationNameToIndex[(animationData[i]).name] = i;

		var curWaypoints = animationData[i].waypoints;
		
		for (var j=0; j < curWaypoints.length; j++)
		{
			// Calculate distance and duration
			if (j==0)
			{
				curWaypoints[0].distance = null;
				curWaypoints[0].speed = null;
			}
			else
			{
				var dx = curWaypoints[j].px - curWaypoints[j-1].px;
				var dy = curWaypoints[j].py - curWaypoints[j-1].py;
				var dz = curWaypoints[j].pz - curWaypoints[j-1].pz;
				
				curWaypoints[j].distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
				
				if (curWaypoints[j].duration) {
					curWaypoints[j].speed = curWaypoints[j].distance / curWaypoints[j].duration;
				} else {
					curWaypoints[j].duration = curWaypoints[j].distance / curWaypoints[j].speed;
				}
			}
			
			curWaypoints[j].rotation = new Quaternion(curWaypoints[j].qw, curWaypoints[j].qx, curWaypoints[j].qy, curWaypoints[j].qz);
			
			if (!curWaypoints[j].easeFunction) curWaypoints[j].easeFunction = 0;
			
			switch (curWaypoints[j].easeFunction){
				case 0:	curWaypoints[j].easeFunction = null; break;
				case 1:	curWaypoints[j].easeFunction = quadEaseIn; break;
				case 2:	curWaypoints[j].easeFunction = quadEaseOut; break;
				case 3:	curWaypoints[j].easeFunction = quadEaseInOut; break;
				case 4:	curWaypoints[j].easeFunction = cubicEaseIn; break;
				case 5:	curWaypoints[j].easeFunction = cubicEaseOut; break;
				case 6:	curWaypoints[j].easeFunction = cubicEaseInOut; break;
			}
				
		}
	}
}

