
var Demo = function() {
}
	var sippeKerroin=0;
	var prevTime=0;
	var prevRandTime=0;
	var xRange = 2;
		var zRange = 360;	
	var yRange = 1080;

	var bpm = 155;
	var beat = 60/bpm;
	var pattern = beat*8;
	var tick = beat/4;
	var hittingOrder = 0;
	var cubeNumber;
	var syncOrder = 0;
	var lastTime;
	var deltaTime;
	var slowRandomValue = [];
	var slowRandomTarget = [];
	slowRandomTarget.length=20;
	slowRandomValue.length=20;
	var normalSyncValue=1.4;
	var syncValue = normalSyncValue;
	var syncTime = [
		,13*pattern+beat
		];
	


Demo.prototype.init = function()
{
	Sync.addSync(
	[
		 { "name":"tunneldistort", "type":"rocket" }
		 ,{ "name":"distortionamount", "type":"rocket"}
		  ,{ "name":"brightnessamount", "type":"rocket"}		  
	]);
	
/* basic cube
	this.loader.addAnimation([
    {
         "start": 16*pattern, "duration":5
        ,"layer": 500, "image": ["data/endscreen.png"]
		,"scale":[{"x":1.0,"y":1.0}
		,{"duration":5, "x":0.9, "y":0.9}]
    }
]);



				this.loader.addAnimation([
						{
						"start": 0, "duration": 1,  "object":"cubes","shape":{"type":"CUBE"}
						,"layer": 300
						,"scale":[{"x":0.2,"y":1.0, "z":0.1}]
						,"position":[{"x":-1.0,"y":0.0,"z":0.0}]
						,"color":[{"a":255}
						,{"duration":0.25*pattern, "a":0}]
						}]);
*/

	this.loader.addAnimation([
    {
         "start": 0*pattern, "duration": 300
        ,"layer": 10, "image": {"name":"data/cat.ogv", "video":{"speed":.1}}
		,"scale":[{"x":3.9,"y":3.9}]
		,"color":[{"a":150}]


		
    }
]);

for (i=0;i<32;i++)
{
				this.loader.addAnimation([
						{
						"start": i*beat, "duration": beat*4,  "object":"cubes","shape":{"type":"CUBE"}
						,"layer": 300
						,"scale":[{"x":0.1,"y":2.0, "z":0.1}]
						,"position":[{"x":-1.5,"y":0.0,"z":0.0}
						,{"duration":beat*4, "x":1.5}]
						,"color":[{"a":0}
						,{"duration":beat*.25, "a":255}
						,{"duration":beat*3.75, "a":0}]
						}]);
						
}

for (i=0;i<32;i++)
{
				this.loader.addAnimation([
						{
						"start": 4*pattern+i*beat, "duration": beat*4,  "object":"cubes","shape":{"type":"CUBE"}
						,"layer": 301
						,"scale":[{"x":0.1,"y":2.0, "z":0.1}]
						,"position":[{"x":1.5,"y":0.0,"z":0.0}
						,{"duration":beat*4, "x":-1.5}]
						,"color":[{"a":0}
						,{"duration":beat*.25, "a":255}
						,{"duration":beat*3.75, "a":0}]
						}]);
}
for (i=0;i<128;i++)
{
				this.loader.addAnimation([
						{
						"start": 8*pattern+i*beat, "duration": beat*9,  "object":"cubes","shape":{"type":"CUBE"}
						,"layer": 302
						,"scale":[{"x":3.0,"y":0.01, "z":0.01}]
						,"position":[{"x":0.0,"y":0.0,"z":0.0}
						,{"duration":beat*9, "y":2-(i%2)*4}]
						,"color":[{"a":255}
						,{"duration":beat*8, "a":0}]
						}]);
}

for (i=0;i<128;i++)
{
				this.loader.addAnimation([
						{
						"start": 24*pattern+i*beat, "duration": beat*9,  "object":"cubes","shape":{"type":"CUBE"}
						,"layer": 302
						,"scale":[{"x":0.01,"y":3.00, "z":0.01}]
						,"position":[{"x":0.0,"y":0.0,"z":0.0}
						,{"duration":beat*9, "x":2-(i%2)*4}]
						,"color":[{"a":255}
						,{"duration":beat*8, "a":0}]
						}]);
}


for(i=0;i<4;i++)
	{
		this.loader.addAnimation([
		{
			 "start": 8*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/i.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

		this.loader.addAnimation([
		{
			 "start": 8.5*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/am.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

	this.loader.addAnimation([
		{
			 "start": 9.0*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/the.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

	this.loader.addAnimation([
		{
			 "start": 9.5*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/dark.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);	
		this.loader.addAnimation([
		{
			 "start": 10.0*pattern+(i*4)*pattern, "duration":1*pattern
			,"layer": 65500, "image": ["data/darkness.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":1*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);	
}
for(i=0;i<4;i++)
	{
		this.loader.addAnimation([
		{
			 "start": 40*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/i.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

		this.loader.addAnimation([
		{
			 "start": 40.5*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/am.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

	this.loader.addAnimation([
		{
			 "start": 41.0*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/the.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

	this.loader.addAnimation([
		{
			 "start": 41.5*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/dark.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);	
		this.loader.addAnimation([
		{
			 "start": 42.0*pattern+(i*4)*pattern, "duration":1*pattern
			,"layer": 65500, "image": ["data/darkness.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":1*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);	
}


for(i=0;i<1;i++)
	{
		this.loader.addAnimation([
		{
			 "start": 58*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/i.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

		this.loader.addAnimation([
		{
			 "start": 58.5*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/am.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

	this.loader.addAnimation([
		{
			 "start": 59.0*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/the.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

	this.loader.addAnimation([
		{
			 "start": 59.5*pattern+(i*4)*pattern, "duration":.5*pattern
			,"layer": 65500, "image": ["data/dark.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":.5*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);	
		this.loader.addAnimation([
		{
			 "start": 60.0*pattern+(i*4)*pattern, "duration":1*pattern
			,"layer": 65500, "image": ["data/darkness.png"]
			,"scale":[{"x":1.0,"y":1.0}
			,{"duration":1*pattern, "x":0.9, "y":0.9}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);	
}



		this.loader.addAnimation([
		{
			 "start": 62*pattern, "duration":8*pattern
			,"layer": 65500, "image": ["data/credits.png"]
			,"scale":[{"x":0.9,"y":0.9}
			,{"duration":4*pattern, "x":0.7, "y":0.7}]
			,"color":[{"r":255,"g":255,"b":255}]
		}]);

		this.loader.addAnimation([
			{
				 "start": 57*pattern+0.75*pattern, "duration":4.25*pattern
				,"layer": 500, "image": ["data/white.png"]
				,"scale":[{"x":1.3,"y":1.3}]
				,"color":[{"a":0}
				,{"duration":.25*pattern, "a":155}
				,{"duration":4*pattern, "a":0}]
			}]);

			this.loader.addAnimation([
				{
					 "start": 62*pattern, "duration":4*pattern
					,"layer": 500, "image": ["data/white.png"]
					,"scale":[{"x":1.3,"y":1.3}]
					,"color":[{"a":155}
					,{"duration":4*pattern, "a":0}]
				}]);
this.explosion(8*pattern,4.1*pattern,-10,0,-11.0,2.0,10,1.0,1.0,1.0,1.0,1.0,255);
this.explosion(12*pattern,4.1*pattern,10,0,-11.0,2.0,10,1.0,1.0,1.0,1.0,1.0,256);
this.explosion(16*pattern,4.1*pattern,0,-6,-11.0,2.0,10,1.0,1.0,1.0,1.0,1.0,257);
this.explosion(20*pattern,4.1*pattern,0,6,-11.0,2.0,10,1.0,1.0,1.0,1.0,1.0,258);

this.explosion(56*pattern,pattern*.75,0,0,-11.0,1.0,10,1.0,1.0,1.0,1.0,1.0,258);
this.explosion(56*pattern+pattern*.5,pattern*.75,0,0,-11.0,1.0,10,1.0,1.0,1.0,1.0,1.0,258);
this.explosion(56*pattern+pattern,pattern*.75,0,0,-11.0,1.0,10,1.0,1.0,1.0,1.0,1.0,258);

var cubeRandom;

for(i=0;i<32;i++)
{
	var xRand;
	var yRand;
	var zRand;
	for(ii=0;ii<10;ii++)
	{
		xRand=Math.random()*30-15;
		yRand=Math.random()*20-10;
		zRand=-Math.random()*50-1;
		for(iii=0;iii<12;iii++)
		{
	cubeRandom=Math.random()*2;
		this.loader.addAnimation([
						{
						"start": 40*pattern+(4*beat*i)+iii*.15, "duration": pattern,  "object":"cubes","shape":{"type":"CUBE"}
						,"layer": 388
						,"scale":[{"x":cubeRandom,"y":cubeRandom, "z":cubeRandom}
						,{"duration":1*pattern, "x":.1,"y":.1,"z":.1}]
						,"position":[{"x":xRand,"y":yRand,"z":zRand}
						,{"duration":1*pattern, "x":0,"y":0,"z":-11}]
						,"color":[{"a":0}
						,{"duration":.1*pattern, "a":255}
						,{"duration":.9*pattern, "a":0}]
						}]);
			}
		}
}

//boom
for(i=0;i<16;i++)
{
this.loader.addAnimation([
	{
		 "start": 40*pattern+4*beat+i*8*beat, "duration":8*pattern
		,"layer": 500, "image": ["data/white.png"]
		,"scale":[{"x":1.3,"y":1.3}]
		,"color":[{"a":155}
		,{"duration":.25*pattern, "a":0}]
	}]);
}
//linet
var yRand1;
var yRand2;

for (iii=0;iii<4;iii++)
{
	if(iii%2)
		{
		for (i=0;i<5;i++)
		{
			yRand1=Math.random();
			yRand2=Math.random();
		for (ii=0;ii<20;ii++)
		{
						this.loader.addAnimation([
								{
								"start": 4*pattern*iii+24*pattern+i*pattern*.5, "duration": 3.5*pattern,  "object":"cubes","shape":{"type":"CUBE"}
								,"layer": 302-i
								,"scale":[{"x":Math.random()*8.0,"y":Math.random()*8.0, "z":Math.random()*8.0}
								,{"duration":.5*pattern, "x":1.0,"y":1.0,"z":1.0}]
								,"position":[{"x":Math.random()*32.0-16,"y":Math.random()*6.0-3,"z":Math.random()*-16.0}
								,{"duration":pattern*.5,"x":Math.random()*32.0-16,"y":-4.0-2*yRand1,"z":-35.0}
								,{"duration":pattern*3.0,"z":2.0}]
								,"color":[{"a":0}
								,{"duration":0.5*pattern, "a":255}
								,{"duration":3.0*pattern, "a":0}]
								}]);

						this.loader.addAnimation([
								{
								"start": 4*pattern*iii+24*pattern+i*pattern*.5, "duration":3.5* pattern,  "object":"cubes","shape":{"type":"CUBE"}
								,"layer": 302-i
								,"scale":[{"x":Math.random()*8.0,"y":Math.random()*8.0, "z":Math.random()*8.0}
								,{"duration":.5*pattern, "x":1.0,"y":1.0,"z":1.0}]
								,"position":[{"x":Math.random()*32.0-16,"y":Math.random()*6.0-3,"z":Math.random()*-16.0}
								,{"duration":pattern*.5,"x":Math.random()*32.0-16,"y":4.0-2*yRand2,"z":-35.0}
								,{"duration":pattern*3.0,"z":2.0}]
								,"color":[{"a":0}
								,{"duration":0.5*pattern, "a":255}
								,{"duration":3.0*pattern, "a":0}]
								}]);
			}
			}
		}
		else
		{
			for (i=0;i<5;i++)
			{
				yRand1=Math.random();
				yRand2=Math.random();
			for (ii=0;ii<20;ii++)
			{
							this.loader.addAnimation([
									{
									"start": 4*pattern*iii+24*pattern+i*pattern*.5, "duration": 3.5*pattern,  "object":"cubes","shape":{"type":"CUBE"}
									,"layer": 302-i
									,"scale":[{"x":Math.random()*8.0,"y":Math.random()*8.0, "z":Math.random()*8.0}
									,{"duration":.5*pattern, "x":1.0,"y":1.0,"z":1.0}]
									,"position":[{"y":Math.random()*32.0-16,"x":Math.random()*6.0-3,"z":Math.random()*-16.0}
									,{"duration":pattern*.5,"y":Math.random()*32.0-16,"x":-4.0-2*yRand1,"z":-35.0}
									,{"duration":pattern*3.0,"z":2.0}]
									,"color":[{"a":0}
									,{"duration":0.5*pattern, "a":255}
									,{"duration":3.0*pattern, "a":0}]
									}]);
	
							this.loader.addAnimation([
									{
									"start": 4*pattern*iii+24*pattern+i*pattern*.5, "duration":3.5* pattern,  "object":"cubes","shape":{"type":"CUBE"}
									,"layer": 302-i
									,"scale":[{"x":Math.random()*8.0,"y":Math.random()*8.0, "z":Math.random()*8.0}
									,{"duration":.5*pattern, "x":1.0,"y":1.0,"z":1.0}]
									,"position":[{"y":Math.random()*32.0-16,"x":Math.random()*6.0-3,"z":Math.random()*-16.0}
									,{"duration":pattern*.5,"y":Math.random()*32.0-16,"x":4.0-2*yRand2,"z":-35.0}
									,{"duration":pattern*3.0,"z":2.0}]
									,"color":[{"a":0}
									,{"duration":0.5*pattern, "a":255}
									,{"duration":3.0*pattern, "a":0}]
									}]);
				}
				}	
		}
}	

// this.fullScreenNoise(0,64*pattern,50000,.1);

//this.brightnessContrast(0,pattern*64.5,0,50004,50007,0.025,0.01);
//this.distortion(0,pattern*64.5,0,50000,50002);
this.hackGlow(0,pattern*58,0,50008,50012);
this.hackGlow2(58*pattern,pattern*64,0,50008,50012);

}


Demo.prototype.distortion = function(startTime, duration, startLayer, endLayer, layer)
{
	this.loader.addAnimation ([
	{
	"start": startTime, "duration": duration
	,"layer": startLayer
	,"fbo":{"name":"fbodist","action":"begin"}
	},
	{
	"start": startTime, "duration": duration
	,"layer": endLayer,"fbo":{"name":"fbodist","action":"unbind"}
	}
	]);
	this.loader.addAnimation ([
	{
		 "start": startTime, "duration": duration
		,"image": "fbodist.color.fbo"
		,"layer": layer
		,"shader":{"name":"data/shader/distortion.fs",
			"variable":[
				 {"name":"time","value":["{return getSceneTimeFromStart()-pattern;}"]}
				,{"name":"timeMultiplier","value":[5.9]}
				,{"name":"pixelSize","value":["{return Math.random()*0.02;}",0.4]}
				,{"name":"noiseWaveSpeed","value":[-1]}
				,{"name":"noiseWaveSize","value":[40]}
				,{"name":"noiseLuminance","value":[1]}
				,{"name":"noiseAlpha","value":[0.0]}
				,{"name":"colorComponentDistortionX","value":[0.1,0.0,0.1,0.5]}
				,{"name":"colorComponentDistortionY","value":[0.1,0.0,0.1,0.5]}
				,{"name":"distortionAmount","value":["{return Sync.getSyncValue('distortionamount');}"]}
			]
			}
		}]);
}

Demo.prototype.brightnessContrast = function (startTime, duration, startLayer, endLayer, layer, brightness, contrast)
{
	this.loader.addAnimation ([
	{
	"start": startTime, "duration": duration
	,"layer": startLayer
	,"fbo":{"name":"fbobc","action":"begin"}
	},
	{
	"start": startTime, "duration": duration
	,"layer": endLayer,"fbo":{"name":"fbobc","action":"unbind"}
	}
	]);
	this.loader.addAnimation ([
	    {
	         "start": startTime, "duration":duration
	        ,"layer": layer, "image": ["fbobc.color.fbo"]
		 ,"initFunction":"{fboBcImage = imageLoadImage('fbobc.color.fbo'); setTextureSizeToScreenSize(fboBcImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fboBcImage.ptr);}"
		 ,"brightness": brightness
		 ,"contrast": contrast
		 ,"beat": beat
	     ,"shader":{
	            "name":"data/shader/brightnesscontrast.fs",
	            "variable":[
	                  {"name":"time","value":["{return getSceneTimeFromStart()-pattern;}"]}
					 ,{"name":"brightness","value":["{return Sync.getSyncValue('brightnessamount');}"]}
					 ,{"name":"contrast","value":[contrast]}
	            ]
	        }
	    }
	]);
	
	
}

Demo.prototype.edgeGlow = function (startTime, duration, startLayer, endLayer, layer)
{
	this.loader.addAnimation ([
	{
	"start": startTime, "duration": duration
	,"layer": startLayer
	,"fbo":{"name":"fboeg","action":"begin"}
	},
	{
	"start": startTime, "duration": duration
	,"layer": endLayer,"fbo":{"name":"fboeg","action":"unbind"}
	}
	]);
	this.loader.addAnimation ([
	    {
	         "start": startTime, "duration":duration
	        ,"layer": layer, "image": ["fboeg.color.fbo"]
		 ,"initFunction":"{fboegImage = imageLoadImage('fboeg.color.fbo'); setTextureSizeToScreenSize(fboegImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fboegImage.ptr);}"
	     ,"shader":{
	            "name":"data/shader/edgeglow.fs",
	            "variable":[
	                  {"name":"time","value":["{return getSceneTimeFromStart()-pattern;}"]}
	            ]
	        }
	    }
	]);
}

Demo.prototype.fullScreenNoise = function (sceneStartTime, duration, layer, alpha)
{
	this.loader.addAnimation([
    {
         "start": sceneStartTime, "duration":duration
        ,"layer": layer, "image": ["data/empty.png"]
     ,"shader":{
            "name":"data/shader/noise.fs",
            "variable":[
                  {"name":"time","value":["{return slowTime();}"]},
				  {"name":"alphaBlending","value":[alpha]}
            ]
        }
    }
]);
}

Demo.prototype.explosion = function(startTime, duration, positionX, positionY, positionZ, scale, randomScaler, colorR, colorG, colorB, startRandomScaler,durationScaler,layer)
{

	for(ie=0;ie<150;ie++)
	{
	
	cubeNumber++;
	var randomScale = Math.random();

	
				this.loader.addAnimation([
						{
						"start": startTime, "duration": duration,  "object":"cubes"+cubeNumber,"shape":{"type":"CUBE"}
						,"layer": layer
						
						,"position": [{"x":positionX+Math.random()*startRandomScaler*.2-Math.random()*startRandomScaler*.2,"y":positionY+Math.random()*startRandomScaler*.2-Math.random()*startRandomScaler*.2,"z":positionZ+Math.random()*startRandomScaler*.2-Math.random()*startRandomScaler*.2}
						,{"duration":duration*durationScaler,
						"x":positionX+Math.random()*randomScaler*3-Math.random()*randomScaler*3,
						"y":positionY+Math.random()*randomScaler*3-Math.random()*randomScaler*3,
						"z":positionZ+Math.random()*randomScaler*3-Math.random()*randomScaler*3}]
						,"scale":[{"x":scale*randomScale,"y":scale*randomScale,"z":scale*randomScale}]
						,"color":[{"r":255*colorR,"g":255*colorG,"b":255*colorB,"a":255}
						,{"duration":duration*durationScaler, "a":0}]
						,"angle": [{"degreesX":Math.random()*360,"degreesY":Math.random()*360,"degreesZ":Math.random()*360}
						,{"duration":duration*durationScaler,"degreesX":Math.random()*360,"degreesY":Math.random()*360,"degreesZ":Math.random()*360}]
						
						//---
						
					}]);
	}
}


Demo.prototype.explosion2 = function(startTime, duration, positionX, positionY, positionZ, scale, randomScaler, colorR, colorG, colorB, startRandomScaler,durationScaler)
{

	for(ie=0;ie<30;ie++)
	{
	
	cubeNumber++;
	var randomScale = Math.random();

	
				this.loader.addAnimation([
						{
						"start": startTime, "duration": duration,  "object":"cubes"+cubeNumber,"shape":{"type":"CUBE"}
						,"layer": 39100
						
						,"position": [{"x":positionX+Math.random()*startRandomScaler*.2-Math.random()*startRandomScaler*.2,"y":positionY+Math.random()*startRandomScaler*.2-Math.random()*startRandomScaler*.2,"z":positionZ+Math.random()*startRandomScaler*.2-Math.random()*startRandomScaler*.2}
						,{"duration":duration*durationScaler,
						"x":positionX+Math.random()*randomScaler*3-Math.random()*randomScaler*3,
						"y":positionY+Math.random()*randomScaler*3-Math.random()*randomScaler*3,
						"z":positionZ+Math.random()*randomScaler*3-Math.random()*randomScaler*3}]
						,"scale":[{"x":scale*randomScale,"y":scale*randomScale,"z":scale*randomScale}]
						,"color":[{"r":255*colorR,"g":255*colorG,"b":255*colorB,"a":255}
						,{"duration":duration*durationScaler, "a":0}]
						,"angle": [{"degreesX":Math.random()*360,"degreesY":Math.random()*360,"degreesZ":Math.random()*360}
						,{"duration":duration*durationScaler,"degreesX":Math.random()*360,"degreesY":Math.random()*360,"degreesZ":Math.random()*360}]
						
						//---
						
					}]);
	}
}


Demo.prototype.hackGlow = function (startTime, duration, startLayer, endLayer, layer)
{
	this.loader.addAnimation ([
	{
	"start": startTime, "duration": duration
	,"layer": startLayer
	,"fbo":{"name":"fbohg","action":"begin"}
	},
	{
	"start": startTime, "duration": duration
	,"layer": endLayer,"fbo":{"name":"fbohg","action":"unbind"}
	}
	]);
	this.loader.addAnimation ([
	    {
	         "start": startTime, "duration":duration
	        ,"layer": layer, "image": ["fbohg.color.fbo"]
		 ,"initFunction":"{fbohgImage = imageLoadImage('fbohg.color.fbo'); setTextureSizeToScreenSize(fbohgImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fbohgImage.ptr);}"
	     ,"shader":{
	            "name":"data/shader/hackglow.fs",
	            "variable":[
	                  {"name":"time","value":["{return getSceneTimeFromStart()-pattern;}"]}
					
	            ]
	        }
	    }
	]);
}

Demo.prototype.hackGlow2 = function (startTime, duration, startLayer, endLayer, layer)
{
	this.loader.addAnimation ([
	{
	"start": startTime, "duration": duration
	,"layer": startLayer
	,"fbo":{"name":"fbohg","action":"begin"}
	},
	{
	"start": startTime, "duration": duration
	,"layer": endLayer,"fbo":{"name":"fbohg","action":"unbind"}
	}
	]);
	this.loader.addAnimation ([
	    {
	         "start": startTime, "duration":duration
	        ,"layer": layer, "image": ["fbohg.color.fbo"]
		 ,"initFunction":"{fbohgImage = imageLoadImage('fbohg.color.fbo'); setTextureSizeToScreenSize(fbohgImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fbohgImage.ptr);}"
	     ,"shader":{
	            "name":"data/shader/hackglowin.fs",
	            "variable":[
	                  {"name":"time","value":["{return getSceneTimeFromStart()-pattern;}"]}
					
	            ]
	        }
	    }
	]);
}

function slowTime()
{

if (getSceneTimeFromStart()-pattern	> prevTime+.1)
	{
		prevTime=getSceneTimeFromStart()-pattern;
		return getSceneTimeFromStart()-pattern;
	}
	else
	return prevTime;

}


function perFrameCalculations()
{

	while (Input.hasEvents())
	{
		var event = Input.pollEvent();
		if (event.type == Input.type.KEYUP)
		{
			if (event.keyboard.symbol == Input.Keyboard.symbol.KEY_1)
			{
			prevRandTime=0;
			prevTime=0;
			}
		}
	}
	
if (getSceneTimeFromStart()-pattern	> prevRandTime+.1)
	{
		prevRandTime=getSceneTimeFromStart()-pattern;
	
		for (i=0;i<slowRandomValue.length;i++)
			slowRandomValue[i]=Math.random();
	}
 
}

function getSlowRandom(n,range)
{
	if(slowRandomTarget[n]==null)
		slowRandomTarget[n]=(slowRandomValue[n]*range)

	slowRandomTarget[n]=slowRandomTarget[n]+.005*((slowRandomValue[n]*range)-slowRandomTarget[n]);
	

	 print("range"+range);
		
return slowRandomTarget[n];
}

function getsyncValue()
{
	  screenPrint("syncorder "+syncOrder);
 
	if(getSceneTimeFromStart()-pattern>syncTime[syncOrder])
	{
		syncOrder++;
    }
	return syncOrder;

}
