/*
Fixlists:
0:40 tekstit, curvejen värit
0:58 curvet ylös ja gridi piiloon
1:00 - kiväärit ilmestymään myöhemmin

*/
var sValue1 = 1.0;
var sValue2 = 1.0;
var cubeNumber = 0;
var beat = .5;
var tick= beat/4;
var pattern = 8*beat;
var snareValue = Math.floor(Math.random()*4);
var effectType = Math.floor(Math.random()*5);
var texnumber = 0;
var frontLayer;
var activeBgEffect;
var direction;
var activeVoice=10;
var shiftBeat = false;
var shiftHat = false;
var shiftBass = false;
var shiftSnare = false;
prevTime=0.0;
var currentTime;
var beatTimer = 2*pattern;
var globalHat = 0.0;
var bassTimer = 2*pattern;
var hatTimer = 2*pattern;
var voiceTimer = 2*pattern;
var hatTimes = [];
var kickTimes = [];
var snareTimes = [];
var bassTimes = [];
var voiceTimes = [];
var timeCounter;
var kickReader = 0;
var snareReader = 0;
var hihatReader = 0;
var bassReader = 0;
var voiceReader = 0;
var textype = Math.floor(Math.random()*4);

var voiceSelectorReader = 0;
var voiceSelector = [];
var kickSelectorReader = 0;
var kickSelector = [];
var snareSelectorReader = 0;
var snareSelector = [];
var hihatSelectorReader = 0;
var hihatSelector = [];
var bassSelectorReader = 0;
var bassSelector = [];
var endTime = 90;
var bassObject = [Math.floor(Math.random()*10+1),Math.floor(Math.random()*10+1),Math.floor(Math.random()*10+1)];
var bassEffectType = 0;
var bassEffectCounter = 0;
var fourValueValues = 0;
var bassOrBeat = 1;
var fourRandomPos = [];
var objects = ["data/possu.obj", "data/heppa.obj", "data/piikki.obj","data/cube2.obj","data/pyssy.obj","data/threecubes.obj"]
var bassFlash = ["data/bassflash.png","data/bassflash2.png","data/bassflash3.png"]
var randomObj1 = Math.floor(Math.random()*objects.length);
var randomObj2 = Math.floor(Math.random()*objects.length);
var randomPosX;
var randomPosY;
var randomScales;

var bassPattern = [
	[1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1],
	[1,0,1,1,0,1,1,1,0,1,1,0,1,0,1,1],
	[0,0,1,1,0,0,1,1,0,1,0,1,0,0,1,1],
	[1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0],
	[0,0,1,0,1,0,1,1,0,0,1,0,1,0,1,1],
	[1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1],
	[0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0],
	[0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1],
	[1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,0],
	
]
var beatPattern1 = [
	[1,1,1,1],
	[1,2,1,2],
	[1,1,2,1],
	[1,1,1,2],
	[2,1,1,1]
	];
	
var beatPattern2 = [
	[1,2,3,2],
	[1,1,1,3],
	[3,3,3,3],
	[1,2,2,3],
	[1,0,3,0],
	[2,0,3,0]
	];
	
var snareRandomizer;
var kickRandomizer;
var bassRandomizer;
var hihatRandomizer;

var playSnare = false;
var playKick = false;
var playBass = false;
var playHat = false;

var gl = new WebGL2RenderingContext(); //enable WebGL 2 partial support

var images = {};
var warPos=[200,-50,-40,-110,-100,-50,200];


var postCreditsTime=47.5*pattern;

var flashes = ["flash1.png","flash2.png","flash3.png"];
var activeFlash = Math.floor(Math.random()*flashes.length);
var sounds = [
    "possu.ogg",
	"heppa.ogg"
	];
	
var kicks = [
    "kick-001.ogg",
	"kick-002.ogg",
	"kick-003.ogg",
	"kick-004.ogg",
	"kick-005.ogg",
	"kick-006.ogg"
	];

var snares = [
    "sd-001.ogg",
	"sd-002.ogg",
	"sd-003.ogg",
	"sd-004.ogg",
	"sd-005.ogg"
	];
	
var hihats = [
    "hihat-001.ogg",
	"hihat-002.ogg",
	"hihat-003.ogg",
	"hihat-004.ogg",
	"hihat-005.ogg",
	"hihat-006.ogg",
	"hihat-007.ogg",
	"hihat-008.ogg",
	"hihat-009.ogg"
	
	];
	
var bass = [
    "bass-001.ogg",
	"bass-002.ogg",
	"bass-003.ogg",
	"bass-004.ogg",
	"bass-005.ogg",
	"bass-006.ogg",
	"bass-007.ogg"
	];
	
var voices = [];

var v1 = [
"v_kokoomus.ogg",
"v_maatalous.ogg",
"v_sosialismi.ogg",
"v_tekno.ogg",
"v_demokratia.ogg",
"v_kansantalous.ogg",
"v_kapitalismi.ogg",
"v_kekkonen.ogg",
"v_keskusta.ogg",
"v_fasismi.ogg",
"v_rakkaus.ogg",
"v_vastustus.ogg",
"v_vihat.ogg",
"v_aurinko.ogg",
"v_halu.ogg",
"v_ihminen.ogg"
];

var v2 = [
"v_hallitsee.ogg",
"v_haviaa.ogg",
"v_pyorii.ogg",
"v_voihyvin.ogg",
"v_voipahoin.ogg",
"v_menestyy.ogg",
"v_itkee.ogg",
"v_kaantyy.ogg",
"v_kasvaa.ogg",
"v_nauraa.ogg",
"v_nousee.ogg",
"v_kuolee.ogg",
"v_laskee.ogg",
"v_tuhoutuu.ogg",
"v_syntyy.ogg"
]

var v3 = [
"v_demokratiassa.ogg",
"v_diktatuurissa.ogg",
"v_euroopassa.ogg",
"v_kunnallisvaaleissa.ogg",
"v_sosialismissa.ogg",
"v_tietoyhteiskunnassa.ogg",
"v_suomessa.ogg",
"v_tulevaisuudessa.ogg"
]


var v4 = [
"v_sosialismin.ogg",
"v_teollisuuden.ogg",
"v_hyvinvoinnin.ogg",
"v_kapitalismin.ogg",
"v_keskustan.ogg",
"v_kokoomuksen.ogg",
"v_ihmisen.ogg",
"v_fasismin.ogg"
];	

var v5 = [
"v_maatalous.ogg",
"v_pelko.ogg",
"v_pyora.ogg",
"v_rakkaus.ogg",
"v_tekno.ogg",
"v_vastustus.ogg",
"v_vihat.ogg",
"v_aurinko.ogg",
"v_halu.ogg",
"v_haamu.ogg",
"v_kannatus.ogg",
"v_kapitalismi.ogg",
"v_kekkonen.ogg"
];

var v6 = [
"v_hallitsee.ogg",
"v_haviaa.ogg",
"v_pyorii.ogg",
"v_voihyvin.ogg",
"v_voipahoin.ogg",
"v_menestyy.ogg",
"v_itkee.ogg",
"v_kaantyy.ogg",
"v_kasvaa.ogg",
"v_nauraa.ogg",
"v_nousee.ogg",
"v_kuolee.ogg",
"v_laskee.ogg",
"v_tuhoutuu.ogg",
"v_syntyy.ogg"
]

var v7 = [
"v_on.ogg"]

var text7 = [
"on"]

var text1 = [
"kokoomus",
"maatalous",
"sosialismi",
"tekno",
"demokratia",
"kansantalous",
"kapitalismi",
"kekkonen",
"keskusta",
"fasismi",
"rakkaus",
"vastustus",
"viha",
"aurinko",
"halu",
"ihminen"
]

var text2 = [
"hallitsee",
"häviää",
"pyörii",
"voihyvin",
"voipahoin",
"menestyy",
"itkee",
"kääntyy",
"kasvaa",
"nauraa",
"nousee",
"kuolee",
"laskee",
"tuhoutuu",
"syntyy"
]

var text3 = [
"demokratiassa",
"diktatuurissa",
"euroopassa",
"kunnallisvaaleissa",
"sosialismissa",
"tietoyhteiskunnassa",
"suomessa",
"tulevaisuudessa"
]

var text4 = [
"sosialismin",
"teollisuuden",
"hyvinvoinnin",
"kapitalismin",
"keskustan",
"kokoomuksen",
"ihmisen",
"fasismin"
];	

var text5 = [
"maatalous",
"pelko",
"pyora",
"rakkaus",
"tekno",
"vastustus",
"viha",
"aurinko",
"halu",
"haamu",
"kannatus",
"kapitalismi",
"kekkonen"
];

var text6 = [
"hallitsee",
"häviää",
"pyörii",
"voi   hyvin",
"voi   pahoin",
"menestyy",
"itkee",
"kaantyy",
"kasvaa",
"nauraa",
"nousee",
"kuolee",
"laskee",
"tuhoutuu",
"syntyy"
]

var bgEffectList = [Math.floor(Math.random()*7),Math.floor(Math.random()*7),Math.floor(Math.random()*7)];

var audio = new Audio();

var particleMesh = void null;

var fftImage = new Image();
	
	function additive(animation) {
		glPushMatrix();     
		gl.enable(gl.BLEND);
		gl.blendFunc(gl.ONE, gl.ONE);
	    glPopMatrix();
	}

	function normal(animation) {
		glPushMatrix();     
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glFrontFace(GL_CW);  
		gl.enable(gl.BLEND);
	  gl.blendFunc(gl.ONE, gl.ONE);

	   glPopMatrix();
	}
	
	function blendAdd(animation) {
		gl.enable(gl.DEPTH_TEST);
		gl.depthMask(false);
		gl.enable(gl.BLEND);
//		gl.blendFunc(gl.ONE, gl.ONE);
		gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
	}

	function blendNormal(animation) {
		gl.enable(gl.BLEND);
		gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
	}


Demo.prototype.init = function()
{

	this.loader.addAnimation([{
         "start": 0, "duration": 8888,"layer": 12
        ,"image": "white.png"
		,"scale":[{"uniform3d":100.0}]
		,"color":[{"r":0,"g":0,"b":0,"a":255}]
		  }]);
	
	for(var i = 0; i < sounds.length; i++) {
        audio.load(sounds[i]);
    }

	for(var i = 0; i < snares.length; i++) {
        audio.load(snares[i]);
    }
	
	for(var i = 0; i < kicks.length; i++) {
        audio.load(kicks[i]);
    }

	for(var i = 0; i < bass.length; i++) {
        audio.load(bass[i]);
    }
	
	for(var i = 0; i < hihats.length; i++) {
        audio.load(hihats[i]);
    }

	for(var i = 0; i < v1.length; i++) {
        audio.load(v1[i]);
    }

	for(var i = 0; i < v2.length; i++) {
        audio.load(v2[i]);
    }
	
	for(var i = 0; i < v3.length; i++) {
        audio.load(v3[i]);
    }

	for(var i = 0; i < v4.length; i++) {
        audio.load(v4[i]);
    }

	for(var i = 0; i < v5.length; i++) {
        audio.load(v5[i]);
    }
	
	for(var i = 0; i < v6.length; i++) {
        audio.load(v6[i]);
    }
	
	for(var i = 0; i < v7.length; i++) {
        audio.load(v7[i]);
    }
voices = [v1,v2,v3,v4,v5,v6,v7];

//voiceSelector.push([5, 0, 0]);

// intro

this.alkuteksti(0,1.75*pattern,"JUMALAUTA",640,600);
this.alkuteksti(1,1.75*pattern-1,"OHJELMISTOTUOTANTO",640,500);
this.alkuteksti(2,1.75*pattern-2,"ESITTÄÄ",640,380);
this.alkuteksti(3,1.75*pattern-3,"KANSALLINEN",640,260);
this.alkuteksti(4,1.75*pattern-4,"TEKNOKEHITIN",640,160);
this.alkuteksti(165,1.75*pattern,"KÄYNNISTÄ",640,600);
this.alkuteksti(165.5,1.75*pattern,"UUDELLEEN",640,500);
this.alkuteksti(166,1.75*pattern,"NÄHDÄKSESI",640,400);
this.alkuteksti(166.5,1.75*pattern,"VAIHTOEHTOISEN",640,300);
this.alkuteksti(167,1.75*pattern,"POLIITTISEN",640,200);
this.alkuteksti(167.5,1.75*pattern,"VIESTIN",640,100);

/*

*/

for(i4=0;i4<2;i4++)
{
	bassObject = [Math.floor(Math.random()*10+1),Math.floor(Math.random()*10+1),Math.floor(Math.random()*10+1)];
	

		bassEffectType=Math.floor(Math.random()*6);
		
		kickSelector.push([bassTimer,Math.floor(Math.random()*kicks.length)]);
		snareSelector.push([bassTimer,Math.floor(Math.random()*snares.length)]);
		bassSelector.push([bassTimer,Math.floor(Math.random()*bass.length)]);
		hihatSelector.push([bassTimer,Math.floor(Math.random()*hihats.length)]);
				
		BeatRandomizer=Math.floor(Math.random()*beatPattern1.length);
		BassRandomizer=Math.floor(Math.random()*bassPattern.length);
		activeVoice=Math.floor(Math.random()*11);
		


	for(i3=0;i3<4;i3++)
	{
		

	if(i%1==0)bassEffectType=Math.floor(Math.random()*6);
	bassOrBeat++;
	if(bassOrBeat>1)bassOrBeat=0;
	
		
		for(i2=0;i2<4;i2++)
		{

		randomPosX=[Math.random()*1280,Math.random()*1280,Math.random()*1280,Math.random()*1280];
		randomPosY=[Math.random()*720,Math.random()*720,Math.random()*720,Math.random()*720];
		randomScales=[Math.random()+.2,Math.random()+.2,Math.random()+.2,Math.random()+.2];
		
		
			for(i=0;i<16;i++)
			{

				if(bassPattern[BassRandomizer][i]==1)
				{
					bassTimes.push(bassTimer);
					if(bassOrBeat==0)this.bass(bassTimer,beat);
					
				}
				bassTimer+=tick;
			}
		}

		for(i=0;i<16;i++)
			{
				hatTimes.push(hatTimer);
				hatTimer+=beat;
			}

		for(ii=0;ii<4;ii++)
		{
									if(ii==0||ii==2)	this.bgEffect(beatTimer,pattern,bgEffectList[Math.floor(Math.random()*3)]);
	
			voiceSelector.push([beatTimer, 0, activeVoice]);
					this.teksti(beatTimer,beat*3,text1[activeVoice],640,360);

			for(i=0;i<4;i++)
			{

			this.functionSelector(beatPattern1[BeatRandomizer][i], 0, beatTimer,beat);
			

			beatTimer+=beat;
			}
		}
	}
}
bassTimer+=4*beat;
var texti=Math.floor(Math.random()*v1.length);
voiceSelector.push([bassTimer, 0, texti]);	
this.teksti(bassTimer,beat*3,text1[texti],640,360);

bassTimer+=3*beat;
texti=Math.floor(Math.random()*v2.length);
voiceSelector.push([bassTimer, 1, texti]);		
this.teksti(bassTimer,beat*3,text2[texti],640,360);

bassTimer+=3*beat;
texti=Math.floor(Math.random()*v3.length);
voiceSelector.push([bassTimer, 2, texti]);		
this.teksti(bassTimer,beat*3,text3[texti],640,360);

bassTimer+=4*beat;
texti=Math.floor(Math.random()*v4.length);
voiceSelector.push([bassTimer, 3, texti]);		
this.teksti(bassTimer,beat*3,text4[texti],640,360);

bassTimer+=3*beat;
texti=Math.floor(Math.random()*v5.length);
voiceSelector.push([bassTimer, 4, texti]);		
this.teksti(bassTimer,beat*3,text5[texti],640,360);

bassTimer+=3*beat;
texti=Math.floor(Math.random()*v6.length);
voiceSelector.push([bassTimer, 5, texti]);		
this.teksti(bassTimer,beat*3,text6[texti],640,360);

bassTimer+=3*beat;
texti=Math.floor(Math.random()*v1.length);
voiceSelector.push([bassTimer, 0, texti]);		
this.teksti(bassTimer,beat*3,text1[texti],640,360);

bassTimer+=3*beat;
texti=Math.floor(Math.random()*v6.length);
voiceSelector.push([bassTimer, 1, texti]);		
this.teksti(bassTimer,beat*3,text6[texti],640,360);

bassTimer+=6*beat;
beatTimer=bassTimer;
hatTimer=bassTimer;
currentTime=bassTimer;

 randomObj1 = Math.floor(Math.random()*objects.length);
 randomObj2 = Math.floor(Math.random()*objects.length);
 bgEffectList = [Math.floor(Math.random()*7),Math.floor(Math.random()*7),Math.floor(Math.random()*7)];
 snareValue = Math.floor(Math.random()*4);
 effectType = Math.floor(Math.random()*5);
 
for(i4=0;i4<2;i4++)
{
	bassObject = [Math.floor(Math.random()*10+1),Math.floor(Math.random()*10+1),Math.floor(Math.random()*10+1)];
	

		bassEffectType=Math.floor(Math.random()*6);
		
		kickSelector.push([bassTimer,Math.floor(Math.random()*kicks.length)]);
		snareSelector.push([bassTimer,Math.floor(Math.random()*snares.length)]);
		bassSelector.push([bassTimer,Math.floor(Math.random()*bass.length)]);
		hihatSelector.push([bassTimer,Math.floor(Math.random()*hihats.length)]);
				
		BeatRandomizer=Math.floor(Math.random()*beatPattern1.length);
		BassRandomizer=Math.floor(Math.random()*bassPattern.length);
		activeVoice=Math.floor(Math.random()*11);
		


	for(i3=0;i3<4;i3++)
	{
		

	if(i%1==0)bassEffectType=Math.floor(Math.random()*6);
	bassOrBeat++;
	if(bassOrBeat>1)bassOrBeat=0;
	
		
		for(i2=0;i2<4;i2++)
		{

		randomPosX=[Math.random()*1280,Math.random()*1280,Math.random()*1280,Math.random()*1280];
		randomPosY=[Math.random()*720,Math.random()*720,Math.random()*720,Math.random()*720];
		randomScales=[Math.random()+.2,Math.random()+.2,Math.random()+.2,Math.random()+.2];
		
		
			for(i=0;i<16;i++)
			{

				if(bassPattern[BassRandomizer][i]==1)
				{
					bassTimes.push(bassTimer);
					if(bassOrBeat==0)this.bass(bassTimer,beat);
					
				}
				bassTimer+=tick;
			}
		}

		for(i=0;i<16;i++)
			{
				hatTimes.push(hatTimer);
				hatTimer+=beat;
			}

		for(ii=0;ii<4;ii++)
		{
			if(ii==0||ii==2)	this.bgEffect(beatTimer,pattern,bgEffectList[Math.floor(Math.random()*3)]);
	
			voiceSelector.push([beatTimer, 0, activeVoice]);
					this.teksti(beatTimer,beat*3,text1[activeVoice],640,360);

			for(i=0;i<4;i++)
			{

			this.functionSelector(beatPattern1[BeatRandomizer][i], 0, beatTimer,beat);
			

			beatTimer+=beat;
			}
		}
	}
}

// ending

bassTimer+=4*beat;
var texti=Math.floor(Math.random()*v1.length);
voiceSelector.push([bassTimer, 0, texti]);	
this.teksti(bassTimer,beat*3,text1[texti],640,360);

bassTimer+=3*beat;
texti=Math.floor(Math.random()*v7.length);
voiceSelector.push([bassTimer, 6, texti]);		
this.teksti(bassTimer,beat*3,text7[texti],640,360);

bassTimer+=3*beat;
texti=Math.floor(Math.random()*v4.length);
voiceSelector.push([bassTimer, 3, texti]);		
this.teksti(bassTimer,beat*3,text4[texti],640,360);

bassTimer+=4*beat;
texti=Math.floor(Math.random()*v1.length);
voiceSelector.push([bassTimer, 0, texti]);		
this.teksti(bassTimer,beat*3,text1[texti],640,360);

voiceSelector.push([1000, 0, 0]);
		kickSelector.push([1000,Math.floor(Math.random()*kicks.length)]);
		snareSelector.push([1000,Math.floor(Math.random()*snares.length)]);
		bassSelector.push([1000,Math.floor(Math.random()*bass.length)]);
		hihatSelector.push([1000,Math.floor(Math.random()*hihats.length)]);
		
		endTime=bassTimer+100;
//this.geneObjects(0,10);

	Sync.addSync(
	[
		 { "name":"Sync1", "type":"rocket" },
		 { "name":"Sync2", "type":"rocket" }
	]);
    var start = 0;
    var duration = 60*20;
    var layer = 1; 


	fftImage.load("fft0");
	
	//fbot
	this.createFBO(0,20000,"fbo20k");
	this.createFBO(20003,30000,"fbo30k");
	this.createFBO(30003,40000,"fbo40k");
	this.createFBO(40005,50000,"fbo50k");
	this.createFBO(50005,60000,"fbo60k");
	debugPrint(666);
	
	//global effects
for(var i = 0; i < 88;i++)
{
	direction=-3+(Math.random()*6);
	var shaderRandomizer=Math.floor(Math.random()*4);

	if(shaderRandomizer==0)
	{
		this.loader.addAnimation ([
		{
			 "start": i*(pattern*.5), "duration": pattern*.5
			,"image": ["fbo20k.color.fbo"]
			,"layer": 30107
						,"shader":{
					"name":["mirrorscrollbg.fs"],
					"variable":[
						  {"name":"tim3","value":["{return 0.1*direction*slowTime()}"]},
				
					]
				}
		}]);
		}
	else if(shaderRandomizer==1)
	{
		this.loader.addAnimation ([
		{
			 "start": i*(pattern*.5), "duration": pattern*.5
			,"image": ["fbo20k.color.fbo"]
			,"layer": 30107
			,"scale":[{"uniform3d":"{return 1.0+2*(slowTime()%.5)}"}]
		}]);
	}
	else if(shaderRandomizer==2)
	{
		this.loader.addAnimation ([
		{
			 "start": i*(pattern*.5), "duration": pattern*.5
			,"image": ["fbo20k.color.fbo"]
			,"layer": 30107
			,"scale":[{"uniform3d":1.2}]
			,"angle":[{"degreesZ":"{return -10+40*(slowTime()%.5)}"}]
		}]);
	}
	else
	{
	this.loader.addAnimation ([
	{
		 "start": i*(pattern*.5), "duration": pattern*.5
		,"image": ["fbo20k.color.fbo"]
		,"layer": 30107

	}]);
	}
}

for(var i = 0; i < 88;i++)
{
	direction=-3+(Math.random()*6);
	var shaderRandomizer=Math.floor(Math.random()*4);

	if(shaderRandomizer==0)
	{
		this.loader.addAnimation ([
		{
			 "start": i*(pattern*.5), "duration": pattern*.5
			,"image": ["fbo30k.color.fbo"]
			,"layer": 31208
						,"shader":{
					"name":["mirrorscrollbg.fs"],
					"variable":[
						  {"name":"tim3","value":["{return 0.1*direction*slowTime()}"]},
				
					]
				}
		}]);
		}
	else if(shaderRandomizer==1)
	{
		this.loader.addAnimation ([
		{
			 "start": i*(pattern*.5), "duration": pattern*.5
			,"image": ["fbo30k.color.fbo"]
			,"layer": 31208
			,"scale":[{"uniform3d":"{return 1.0+2*(slowTime()%.5)}"}]
		}]);
	}
	else if(shaderRandomizer==2)
	{
		this.loader.addAnimation ([
		{
			 "start": i*(pattern*.5), "duration": pattern*.5
			,"image": ["fbo30k.color.fbo"]
			,"layer": 31208
			,"scale":[{"uniform3d":1.2}]
			,"angle":[{"degreesZ":"{return -10+40*(slowTime()%.5)}"}]
		}]);
	}
	else
	{
	this.loader.addAnimation ([
	{
		 "start": i*(pattern*.5), "duration": pattern*.5
		,"image": ["fbo30k.color.fbo"]
		,"layer": 31208

	}]);
	}
}

 
   
	this.loader.addAnimation ([
	{
		 "start": 0, "duration": 8888
		,"image": ["fbo40k.color.fbo", "fft0"]
		,"layer": 40105
		,"shader":{"name":["fftdistort.fs"]}
	}]);
		
	this.loader.addAnimation ([
	{
		 "start": 0, "duration": 8888
		,"image": ["fbo50k.color.fbo","2dlut.png"]
		,"layer": 50105
		,"position":[{"x":640,"y":360}]
		,"scale":[{"uniform3d":1.0}]


		 ,"shader":{
	         "name":"lut.fs",
	         "variable":[
			{"name":"lut","type":"int","value":[1]}
	          ]
	        }
		
	}]);
	
		this.loader.addAnimation ([
		{
		 "start": 0, "duration": 8888
		,"image": ["fbo60k.color.fbo"]
		,"layer": 60105
	
		,"shader":{"name":["hackglow.fs"]}
		//,"shader":{"name":["edge.fs"]}
		}]);


//this.possu(0,1000);
	this.playSound();
}

Demo.prototype.createFBO = function (startLayer, endLayer, name)
{
	   	this.loader.addAnimation ([
	{
	"start": 0, "duration": 99999
	,"layer": startLayer
	,"fbo":{"name":name,"action":"begin","storeDepth":true}
	}
	]);
	
	this.loader.addAnimation ([
	{
	"start": 0, "duration": 99999
	,"layer": endLayer,"fbo":{"name":name,"action":"unbind"}
	}
	]);
	
}

Demo.prototype.geneObjects = function (startTime, duration)
{
	
	for(i=0;i<64;i++)
	{

		this.loader.addAnimation([{
			 "start": startTime, "duration": duration,"layer": 1002+i%2
			,"image": "object_"+Math.floor(1+Math.random()*10)+".png"
			,"scale":[{"uniform3d":1.3}]
			,"color":[{"r":255,"g":255,"b":255,"a":255}]
			,"angle": [{"degreesZ":360-Math.random()*360}
			,{"duration":duration,"degreesZ":360-Math.random()*360}]
			,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
	   }]);

	}
}

Demo.prototype.alkuteksti = function (startTime, duration,stringi,xpos,ypos)
{

var tscale=2.9;


		this.loader.addAnimation([{
			"start": startTime, "duration": duration ,"layer": 41000,			
			"text":
			{
				"string":stringi	
				,"name":"font.ttf"
			}
			,"scale":[{"uniform3d":tscale}]
		
	 ,"position":[{"x":xpos,"y":ypos,"z":-4}]
		,"shader":{"name":["textblur.fs"]}
		}]);
	}

Demo.prototype.teksti = function (startTime, duration,stringi,xpos,ypos)
{

var tscale=2.9;
if (stringi=="Tietoyhteiskunnassa") tscale=2.5;

if(textype==0)
{


		this.loader.addAnimation([{
			"start": startTime, "duration": duration ,"layer": 41000,			
			"text":
			{
				"string":stringi	
				,"name":"font.ttf"
			}
			,"scale":[{"uniform3d":tscale}]
		
	 ,"position":[{"x":xpos,"y":ypos,"z":-4}
	 ,{"duration":1*pattern,"x":xpos-Math.random()*200}]
		,"shader":{"name":["textblur.fs"]}
		}]);
	}

	if(textype==1)
	{

	this.loader.addAnimation([{
		"start": startTime, "duration": duration ,"layer": 41000,			
		"text":
		{
			"string":stringi	
			,"name":"font.ttf"
		}
		,"scale":[{"uniform3d":tscale}]
		
		,"position":[{"x":xpos,"y":630-texnumber*180,"z":-4}
		,{"duration":2*pattern,"x":xpos-Math.random()*200}]
		,"shader":{"name":["textblur.fs"]}
		}]);
	}

	if(textype==2)
	{

	this.loader.addAnimation([{
		"start": startTime, "duration": duration*2 ,"layer": 36000,			
		"text":
		{
			"string":stringi	
			,"name":"font.ttf"
		}
		,"scale":[{"uniform3d":tscale}]
		
		,"position":[{"x":xpos,"y":630-texnumber*180,"z":-4}
		,{"duration":2*pattern,"x":xpos-Math.random()*200}]
		,"shader":{"name":["textblur.fs"]}
		}]);
	}

	if(textype==3)
	{

	this.loader.addAnimation([{
		"start": startTime, "duration": duration ,"layer": 41000,			
		"text":
		{
			"string":stringi	
			,"name":"font.ttf"
		}
		,"scale":[{"uniform3d":tscale*2}
		,{"duration":duration,"uniform3d":tscale}]
		,"position":[{"x":xpos,"y":ypos,"z":-4}
		,{"duration":2*pattern,"x":xpos-Math.random()*200}]
		,"shader":{"name":["textblur.fs"]}
		}]);
	}
	
texnumber++;
if(texnumber>3)texnumber=0;	

}
Demo.prototype.teksti2 = function (startTime, duration,stringi,xpos,ypos)
{
	this.loader.addAnimation([{
		"start": startTime*tick, "end": duration*2 ,"layer": 40400,			
		"text":
		{
			"string":stringi	
			,"name":"font.ttf"
		}
		,"scale":[{"uniform3d":2.9}]
	
 ,"position":[{"x":xpos,"y":ypos,"z":-4}
 ,{"duration":4*pattern,"y":ypos+5-Math.random()*5}]
 	,"angle":[{"degreesZ":5-Math.random()*10}]
 	,"shader":{"name":["textblur.fs"]}
	}]);
	

	
}

Demo.prototype.creditsTeksti = function (startTime, stringi,scalex)
{
	this.loader.addAnimation([{
		"start": startTime, "end": startTime+pattern ,"layer": 90400,			
		"text":
		
		{
			"string":stringi	
			,"name":"font.ttf"
		}
		,"scale":[{"uniform3d":scalex}]
	
 ,"position":[{"x":640,"y":-100,"z":-4}
	,{"duration":1*pattern,"x":600+Math.random()*80,"y":720}]
 	,"angle":[{"degreesZ":5-Math.random()*10}]
 	,"shader":{"name":["textblur.fs"]}
	}]);
}

Demo.prototype.functionSelector = function ( value1, value2, startTime, duration)
{
	if(value1==1)
	{
		if(bassOrBeat==1)this.possu(startTime, duration);
		kickTimes.push(beatTimer);
	}
	if(value1==2)
	{
		if(bassOrBeat==1)this.heppa(startTime, duration);
		snareTimes.push(beatTimer);
	}
}

Demo.prototype.bgEffect = function (startTime, duration, tunnelEffectType)
{
	 sValue1=Math.random()*10;
	 sValue2=Math.random()*10;
var bgVariable=Math.random();	
activeBgEffect=0;
	direction=-3+(Math.random()*6);
rotation = 90*(-1+Math.floor(Math.random()*2)*2);
var colorr=[Math.random(),Math.random(),Math.random()];
colorr=minMax(colorr);
loggerInfo("colorr "+colorr);
var inversecolorr=[1-colorr[0],1-colorr[1],1-colorr[2]];



    if(tunnelEffectType==8)
	{
		this.loader.addAnimation([{
			 "start": startTime, "duration": duration,"layer": 111
			,"image": "object_"+bassObject[0]+".png"
			,"colorr":colorr						
			,"scale":[{"uniform3d":3.0}]
			 ,"shader":{
				"name":["mirrorscroll2.fs"],
				"variable":[
					  {"name":"tim3","value":["{return 2*direction*slowTime()}"]},
					  {"name":"colorr","value":colorr},
					  	  {"name":"value1","value":sValue1},
						  	  {"name":"value2","value":sValue2}
				]
			}
	   }]);
	}  
	
	if(tunnelEffectType==7)
	{


		this.loader.addAnimation([{
			 "start": startTime, "duration": duration,"layer": 111
			,"image": "object_"+bassObject[1]+".png"
			,"colorr":colorr						
			,"scale":[{"uniform3d":3.0}]
					,"angle":[{"degreesZ":"{return 100*slowTime()}"}]

				,"shader":{
				"name":["mirrorscroll.fs"],
				"variable":[
					  {"name":"tim3","value":["{return direction*slowTime()}"]},
					  {"name":"colorr","value":colorr},
					  	  {"name":"value1","value":sValue1},
						  	  {"name":"value2","value":sValue2}
				]
			}
		}]);

	}
	
	if(tunnelEffectType==6)
	{
		activeBgEffect=2;
		this.loader.addAnimation([{
			"start": startTime, "end": startTime+duration ,"layer": 111,
	
			"object":"data/innercube.obj"		
			,"colorr":colorr
			,"scale":[{"uniform3d":7.65}]	
			,"position":[{"x":0,"y":0,"z":-2}]
			,"angle":[{"degreesZ":"{return Math.sin(sValue1)*direction*100*slowTime()}","degreesY":"{return Math.sin(sValue2)*direction*100*slowTime()}",}]
			,"shader":{
			"name":["color.fs"],
			"variable":[{"name":"colorr","value":colorr}]
			}
		}]);
	}
	
	if(tunnelEffectType==5)
	{
		this.loader.addAnimation([{
			"start": startTime, "end": startTime+duration ,"layer": 111,
			"object":"data/lines_1.obj"		
			,"colorr":colorr
			,"scale":[{"uniform3d":1.25}]	
			,"position":[{"y":0,"x":"{return -8.5+2*Math.sin(0.5*slowTime())}","z":-2}]
			,"angle":[{"degreesZ":90,"degreesX":"{return direction*100*slowTime()}"}]

			,"shader":{
			"name":["color.fs"],
			"variable":[{"name":"colorr","value":colorr}]
			}
		}]);
		this.loader.addAnimation([{
			"start": startTime, "end": startTime+duration ,"layer": 111,
			"object":"data/lines_1.obj"		
			,"inversecolorr":inversecolorr
			,"scale":[{"uniform3d":0.75}]	
			,"position":[{"y":0,"x":"{return -6+2*Math.sin(0.5*slowTime())}","z":-2}]
			,"angle":[{"degreesZ":90,"degreesX":"{return -direction*100*slowTime()}"}]

			,"shader":{
			"name":["color.fs"],
			"variable":[{"name":"colorr","value":inversecolorr}]
			}
		}]);
	}
	
	if(tunnelEffectType==3)
	{
		activeBgEffect=2;
		this.loader.addAnimation([{
			"start": startTime, "end": startTime+duration ,"layer": 111,
			"object":"data/lines_1.obj"		
			,"colorr":colorr
			,"scale":[{"uniform3d":1.75}]	
			,"position":[{"x":0,"y":"{return -5+Math.sin(slowTime())}","z":-2}]
			,"angle":[{"degreesY":"{return direction*100*slowTime()}",}]
			,"shader":{
			"name":["color.fs"],
			"variable":[{"name":"colorr","value":colorr}]
			}
		}]);
	}

	if(tunnelEffectType==4)
	{
		activeBgEffect=2;
		this.loader.addAnimation([{
			"start": startTime, "end": startTime+duration ,"layer": 111,
			"object":"data/lines_2.obj"
			,"colorr":colorr			
			,"scale":[{"uniform3d":1.5}]	
			,"position":[{"x":0,"y":"{return -5+Math.sin(slowTime())}","z":-2}]
			,"angle":[{"degreesY":"{return direction*100*slowTime()}"}]
			,"shader":{
			"name":["color.fs"],
			"variable":[{"name":"colorr","value":colorr}]
			}
		}]);
	}
	
	if(tunnelEffectType==0)
	{
		this.loader.addAnimation([{
			 "start": startTime, "duration": duration,"layer": 111
			,"image": "object_"+bassObject[0]+".png"
			,"colorr":colorr						
			,"scale":[{"uniform3d":3.0}]
			,"shader":{
				"name":["tunnel.fs"],
				"variable":[
					  {"name":"tim3","value":["{return direction*slowTime()}"]},
					  {"name":"colorr","value":colorr},
					  	  {"name":"value1","value":sValue1},
						  	  {"name":"value2","value":sValue2}
				]
			}
		}]);
	}
	
   if(tunnelEffectType==1)
   {
		this.loader.addAnimation([{
			 "start": startTime, "duration": duration,"layer": 111
			,"image": "object_"+bassObject[0]+".png"
			,"colorr":colorr						
			,"scale":[{"uniform3d":3.0}]
				,"shader":{
				"name":["mirrorscroll.fs"],
				"variable":[
					  {"name":"tim3","value":["{return direction*slowTime()}"]},
					  {"name":"colorr","value":colorr}
				]
			}
		}]);
   }
  
    if(tunnelEffectType==2)
	{
		this.loader.addAnimation([{
			 "start": startTime, "duration": duration,"layer": 111
			,"image": "object_"+bassObject[0]+".png"
			,"colorr":colorr						
			,"scale":[{"uniform3d":3.0}]
			 ,"shader":{
				"name":["mirrorscroll2.fs"],
				"variable":[
					  {"name":"tim3","value":["{return direction*slowTime()}"]},
					  {"name":"colorr","value":colorr}
				]
			}
	   }]);
	}   
}

Demo.prototype.bass = function (startTime, duration)
{

// delete	

// bass images = 10
if (bassEffectType==4)
	{
		duration=duration*2.5;
	for(i=0;i<4;i++)
	{
			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":randomScales[i]}
				,{"duration":duration,"uniform3d":0}]
				,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
				,{"duration":duration*.5,"a":255}
				,{"duration":duration*.5,"a":100}]
				,"angle": [{"degreesZ":Math.random()*360}]
				,"position":[{"y":randomPosY[i],"x":randomPosX[i]}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);
	}
	}
if (bassEffectType==3)
	{
		duration=duration*2.5;

			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":.8}
				,{"duration":duration,"uniform3d":.4}]
				,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
				,{"duration":duration,"a":100}]
				,"angle": [{"degreesZ":Math.random()*360}]
				,"position":[{"y":50,"x":Math.random()*1100+90}
				,{"duration":duration,"y":720}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);
	}
	
if (bassEffectType==2)
	{
		duration=duration*3.5;
		if(bassEffectCounter==3)
			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":.8}
				,{"duration":duration,"uniform3d":.4}]
				,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
				,{"duration":duration,"a":100}]
				,"angle": [{"degreesZ":Math.random()*360}]
				,"position":[{"y":"{return 360+180*Math.sin(2*getSceneTimeFromStart())}","x":160}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);
		   
		if(bassEffectCounter==2)
			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":.8}
				,{"duration":duration,"uniform3d":.4}]
					,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
				,{"duration":duration,"a":100}]
				,"angle": [{"degreesZ":Math.random()*360}]
				,"position":[{"y":"{return 360+180*Math.sin(20+2*getSceneTimeFromStart())}","x":480}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);
	
		if(bassEffectCounter==1)
			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":.8}
				,{"duration":duration,"uniform3d":.4}]
					,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
				,{"duration":duration,"a":100}]
				,"angle": [{"degreesZ":Math.random()*360}]
				,"position":[{"y":"{return 360+180*Math.sin(40+2*getSceneTimeFromStart())}","x":800}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);
		
		if(bassEffectCounter==0)
			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":.8}
				,{"duration":duration,"uniform3d":.4}]
					,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
				,{"duration":duration,"a":100}]
				,"angle": [{"degreesZ":Math.random()*360}]
				,"position":[{"y":"{return 360+180*Math.sin(60+2*getSceneTimeFromStart())}","x":1120}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);
		   
		   bassEffectCounter++;
		   if(bassEffectCounter>3)bassEffectCounter=0;

	}

	
if (bassEffectType==5)
	{
		
		duration=duration*.5;
			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":1.5}]
				,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
			,{"duration":duration,"a":100}]
				,"angle": [{"degreesZ":"{return 25*(getSceneTimeFromStart())}"}]
				,"position":[{"y":360,"x":640}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);

	}

if (bassEffectType==0)
	{
		
		duration=duration*.5;
			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":0.75}]
				,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
			,{"duration":duration,"a":100}]
				,"angle": [{"degreesZ":"{return 25*(getSceneTimeFromStart())}"}]
				,"position":[{"y":360,"x":240}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);

			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":0.75}]
				,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
			,{"duration":duration,"r":0,"g":0,"b":0}]
				,"angle": [{"degreesZ":"{return 25*(getSceneTimeFromStart())}"}]
				,"position":[{"y":360,"x":640}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);
		   
		   	
			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":0.75}]
				,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
			,{"duration":duration,"r":0,"g":0,"b":0}]
				,"angle": [{"degreesZ":"{return 25*(getSceneTimeFromStart())}"}]
				,"position":[{"y":360,"x":1040}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);
		   
	}
	
if (bassEffectType==1)
	{
		duration=duration*2;
			this.loader.addAnimation([{
				 "start": startTime, "duration": duration,"layer": 25002
				,"image": "object_"+bassObject[0]+".png"
				,"scale":[{"uniform3d":0.5}
				,{"duration":duration,"uniform3d":5}]
				,"color":[{"r":Math.random()*255,"g":Math.random()*255,"b":Math.random()*255,"a":255}
			,{"duration":duration,"r":0,"g":0,"b":0}]
				,"angle": [{"degreesZ":"{return 25*(getSceneTimeFromStart())}"}]
				,"position":[{"y":360,"x":640}]
				//,"position":[{"y":720-Math.random()*720,"x":1280-Math.random()*1280}
				//	,{"duration":duration,"y":720-Math.random()*720,"x":1280-Math.random()*1280}]
		   }]);
	}
	duration=tick;
			this.loader.addAnimation([{
         "start": startTime, "duration": duration,"layer": 20
        ,"image": "white.png"
		,"scale":[{"uniform3d":100.0}]
		,"color":[{"r":0,"g":0,"b":0,"a":255}
		,{"duration":duration,"r":0,"g":0,"b":0,"a":0}]
		  }]);
		  
}

Demo.prototype.hat = function (startTime, duration)
{
	
	this.loader.addAnimation([{
		"start": startTime, "end": startTime+duration ,"layer": 20401,
		"runFunction":"{if (!animation.once) {animation.once=true;playHat=true}}"
	}]);
		
}

Demo.prototype.playSound = function (startTime, duration)
{
	
	this.loader.addAnimation([{
		"start": 0, "end": 300 ,"layer": 99999,
		"runFunction":"{soundPlayer();}"
	}]);
		
}

Demo.prototype.possu = function (startTime, duration)
{
	scalex=1.0;

	
	if(activeBgEffect==0)
		frontLayer=25401;
	if(activeBgEffect==2)
		frontLayer=112;
	
	if(effectType==4)
	{
			this.loader.addAnimation([{
         "start": startTime, "duration": duration,"layer": frontLayer
        ,"image": bassFlash[Math.floor(Math.random()*3)]

		,"color":[{"r":255,"g":255,"b":255,"a":255}
		,{"duration":duration,"r":0,"g":0,"b":0,"a":0}]
		,"scale":[{"uniform3d":1.3}	
		,{"duration":beat,"uniform3d":1.0}	]
		
		  }]);
		  
	}
	
	if(effectType==3)
	{
		var colorr=[Math.random(),Math.random(),Math.random()];
		this.loader.addAnimation([{
		"start": startTime, "end": startTime+duration ,"layer": frontLayer,
		
		"image": ["fft0"],
		"colorr":colorr,
		"scale":[{"uniform3d":1.0}]
		,"shader":{
			"name":["fftcolor.fs"],
			"variable":[{"name":"colorr","value":colorr}]
			}
	}]);
				
	}
	
	if (effectType==0)
	{
			var colorr=[Math.random(),Math.random(),Math.random()];
		this.loader.addAnimation([{
		"start": startTime, "end": startTime+duration ,"layer": frontLayer,
		"object":objects[randomObj1]		
				,"colorr":colorr
		,"scale":[{"uniform3d":scalex}]	
		,"position":[{"x":0,"y":-0,"z":-4}]
		,"angle":[{"degreesY":45+Math.random()*90, "degreesZ":-30}
		,{"duration":beat*.25,"degreesZ":30}
		,{"duration":beat*.75,"degreesZ":-30}]
		,"shader":{
		"name":["color.fs"],
		"variable":[{"name":"colorr","value":colorr}]
					}

		}]);
	}

	if (effectType==1)
	{
	var angY1=Math.random()*360-Math.random()*360;
	var angX1=Math.random()*360-Math.random()*360;
	var angZ1=Math.random()*360-Math.random()*360;
	var andX2;
	var angZ2;
	var angY2;
	
	
	var angleRandomizer=Math.floor(Math.random()*3);
	
	if (angleRandomizer==0)
	{
	angY2=angY1;
	angX2=angX1;
	angZ2=angZ1+(-1+Math.floor(Math.random()*2)*2)*90;
	}
	else if (angleRandomizer==1)
	{
	angY2=angY1;
	angZ2=angZ1;
	angX2=angX1+(-1+Math.floor(Math.random()*2)*2)*90;
	}
	else if (angleRandomizer==2)
	{
	angX2=angX1;
	angZ2=angZ1;
	angY2=angY1+(-1+Math.floor(Math.random()*2)*2)*90;
	}

	
	

		var colorr=[Math.random(),Math.random(),Math.random()];
		this.loader.addAnimation([{
		"start": startTime, "end": startTime+duration ,"layer": frontLayer,
		"object":objects[randomObj1]
		,"scale":[{"uniform3d":scalex}]
		,"colorr":colorr
		,"position":[{"x":0,"y":-0,"z":-4}]
		,"angle":[{"degreesY":angY1, "degreesZ":angZ1, "degreesX":angX1}
		,{"duration":duration,"degreesY":angY2, "degreesZ":angZ2, "degreesX":angX2}]
		
		,"shader":{
		"name":["color.fs"],
		"variable":[{"name":"colorr","value":colorr}]
					}
		}]);
	}
	
}

Demo.prototype.heppa = function (startTime, duration)
{

	var colorr=[Math.random(),Math.random(),Math.random()];
		var angleRandomizer=Math.floor(Math.random()*3);
	
	var angY1=Math.random()*360-Math.random()*360;
	var angX1=Math.random()*360-Math.random()*360;
	var angZ1=Math.random()*360-Math.random()*360;
	
	var andX2;
	var angZ2;
	var angY2;
	if (angleRandomizer==0)
	{
	angY2=angY1;
	angX2=angX1;
	angZ2=angZ1+(-1+Math.floor(Math.random()*2)*2)*90;
	}
	else if (angleRandomizer==1)
	{
	angY2=angY1;
	angZ2=angZ1;
	angX2=angX1+(-1+Math.floor(Math.random()*2)*2)*90;
	}
	else if (angleRandomizer==2)
	{
	angX2=angX1;
	angZ2=angZ1;
	angY2=angY1+(-1+Math.floor(Math.random()*2)*2)*90;
	}
	scalex=1.0;
if(snareValue==0)
{
	this.loader.addAnimation([{
	"start": startTime, "end": startTime+duration ,"layer": 25400,
	"object":objects[randomObj2]
	,"colorr":colorr
	,"scale":[{"x":scalex*4,"y":scalex,"z":scalex}
	,{"duration":duration*.5,"x":scalex}]
	
	,"position":[{"x":0,"y":-0,"z":-4}]
		,"angle":[{"degreesY":angY1, "degreesZ":angZ1, "degreesX":angX1}
			,{"duration":duration,"degreesY":angY2, "degreesZ":angZ2, "degreesX":angX2}]
		,"shader":{
		"name":["color.fs"],
		"variable":[{"name":"colorr","value":colorr}]
					}
	
	}]);
}


if(snareValue==1)
{
	this.loader.addAnimation([{
         "start": startTime, "duration": duration,"layer": 25400
        ,"image": flashes[activeFlash]

		,"color":[{"r":255,"g":255,"b":255,"a":255}
		,{"duration":duration,"r":0,"g":0,"b":0,"a":0}]
		  }]);
}

if(snareValue==2)
	this.explosion(startTime,duration,100+Math.random()*1080,100+Math.random()*520, Math.random()*2,Math.random()*2,Math.random()*255,Math.random()*255,Math.random()*255,1,1);
}

Demo.prototype.explosion = function(startTime, duration, positionX, positionY, positionZ, scale, randomScaler, colorR, colorG, colorB, startRandomScaler,durationScaler)
{
	var colorr=[Math.random(),Math.random(),Math.random()];
	for(ie=0;ie<15;ie++)
	{
	
	this.loader.addAnimation([{
	"start": startTime, "duration": duration ,"layer": 25400,
	"object":"cube2.obj"
	,"colorr":colorr
	,"scale":[{"uniform3d":scalex*2}
	,{"duration":duration,"uniform3d":0}]

	,"position":[{"x":-3+6*Math.random(),"y":-3+6*Math.random(),"z":-4}]

		,"shader":{
		"name":["color.fs"],
		"variable":[{"name":"colorr","value":colorr}]
					}
	
	}]);
	}
}


function fourValues()
{
if(fourValueValues==3)fourValueValues=0;
else fourValueValues=fourValueValues+1;

return fourValueValues;

}
function soundPlayer()
{
	var currentTime=getSceneTimeFromStart();
	
if(currentTime<endTime)
{


	
	if(currentTime>=kickSelector[kickSelectorReader][0])
	{
		kickSelectorReader++;
	}

	if(currentTime>=snareSelector[snareSelectorReader][0])
	{
		snareSelectorReader++;
	}	
	
	if(currentTime>=bassSelector[bassSelectorReader][0])
	{
		bassSelectorReader++;
	}	
	if(currentTime>=hihatSelector[hihatSelectorReader][0])
	{
		hihatSelectorReader++;
	}	

	
	
	if(currentTime>=voiceSelector[voiceSelectorReader][0])
	{
		
		audio.play(voices[voiceSelector[voiceSelectorReader][1]][voiceSelector[voiceSelectorReader][2]]);
		voiceSelectorReader++;
	}

	
	if(currentTime>=kickTimes[kickReader])
	{
		
		audio.play(kicks[kickSelector[kickSelectorReader][1]]);
		kickReader++;
	}
	
	if(currentTime>=snareTimes[snareReader])
	{
		audio.play(kicks[kickSelector[kickSelectorReader][1]]);
		audio.play(snares[snareSelector[snareSelectorReader][1]]);
		snareReader++;
		
	}
	
	if(currentTime>=hatTimes[hihatReader])
	{
		audio.play(hihats[hihatSelector[hihatSelectorReader][1]]);
		hihatReader++;

	}
	
	if(currentTime>=bassTimes[bassReader])
	{
		audio.play(bass[bassSelector[bassSelectorReader][1]]);
		bassReader++;

	}
}	

	/*
	if(getSceneTimeFromStart()>=prevTime+0.125)
	{
		
		prevTime=prevTime+.125;
		if(playBass)
		{
			audio.play(bass[bassRandomizer]);
			playBass=false;
		}
		if(playKick)
		{
			audio.play(kicks[kickRandomizer]);
			playKick=false;
		}	
		if(playHat)
		{
			audio.play(hihats[hihatRandomizer]);
			playHat=false;
		}
		if(playSnare)
		{
			audio.play(snares[snareRandomizer]);
			playSnare=false;
		}

	}
	*/
}


function minMax(arr)
{
	
	var bigIndex= arr.indexOf(arr.reduce(function(a, b) {return Math.max(a, b);}, 0));
	var smallIndex= arr.indexOf(arr.reduce(function(a, b) {return Math.min(a, b);}, 1));
		

	arr[bigIndex]=1.0;
	arr[smallIndex]=0.0;
	
	return arr;

}
function slowTime()
{

if (getSceneTimeFromStart()	> prevTime+.04)
	{
		prevTime=getSceneTimeFromStart();
		return getSceneTimeFromStart();
	}
	else
	return prevTime;

}