
var Demo = function() {
}
var Blob2Number=2;
var maxBlob2=22;
var minBlob2=2;
	var nextNumber =3;
	var currentBlob = 0;
	var blobNumber = 0;
	var maxBlob = 17;
	var Max_cityblock =5.9999999;
	var sippeKerroin=0;
	var prevTime=0;
	var prevRandTime=0;
	var xRange = 2;
		var zRange = 360;	
	var yRange = 1080;

	var bpm = 125;
	var beat = 60/bpm;
	var pattern = beat*8;
	var tick = pattern/64;
	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 nya = [0,3,6,9,19,22,25,35,38,41,44,48,51,60,64,67,70,73,83,86,89,99,102,105,108,112,115,118,121,124];
	var nyaa = [12,28,54,76,92];

Demo.prototype.init = function()
{
	Sync.addSync(
	[
		 { "name":"Sync1", "type":"rocket" },
		 { "name":"Sync2", "type":"rocket" }
	]);
	glCullFace( GL_BACK );
	glEnable(GL_CULL_FACE);
 

		

		
		/*	this.loader.addAnimation ([
	{
		 "start": 0	, "duration": 8*pattern
		,"image": "data/spiral.png"
		,"layer": 40000


		,"scale":[{"uniform3d":1.265}]
						     ,"shader":{
						"name":"data/shader/mirrorscroll.fs",
						"variable":[
						{"name":"time","value":["{return .1*getSceneTimeFromStart()}"]},
						{"name":"distort","value":["{return 1.5+.5*(getSceneTimeFromStart()%.48)}"]}
						]
					}
		}]);					
			*/

this.loader.addAnimation([
	{
		 "start": 0*pattern, "duration": 8*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":1.0, "z":0.0}
		]
		,"position":[
		{"x":0
		,"y":0	
		,"z":12
		}]
	}]);
	
				this.loader.addAnimation([
	{
		 "start": 8*pattern, "duration": .5*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":4.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":1.0, "z":0.0}
		]
		,"position":[
		{"x":1
		,"y":4	
		,"z":4
		}]
	}]);
				this.loader.addAnimation([
	{
		 "start": 8.5*pattern, "duration": 0.5*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":1.0, "z":0.0}
		]
		,"position":[
		{"x":-6
		,"y":-6	
		,"z":-3
		}]
	}]);



					this.loader.addAnimation([
	{
		 "start": 9.0*pattern, "duration": 1*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":-1.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":-1.0, "z":0.0}
		]
		,"position":[
			 {"x":"{return Math.cos(getSceneTimeFromStart()*2)*8.0-Math.sin(getSceneTimeFromStart()*2)*8.0;}",
			 "z":"{return Math.cos(getSceneTimeFromStart()*2)*8.0+Math.sin(getSceneTimeFromStart()*2)*8.0;}"
		,"y":-5
		}]
	}]);

				this.loader.addAnimation([
	{
		 "start": 10*pattern, "duration": 0.5*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":3.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":1.0, "z":0.0}
		]
		,"position":[
		{"x":0
		,"y":3	
		,"z":-5
		}]
	}]);

				this.loader.addAnimation([
	{
		 "start": 10.5*pattern, "duration": .5*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":4.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":1.0, "z":0.0}
		]
		,"position":[
		{"x":-2
		,"y":4	
		,"z":4
		}]
	}]);
	
				this.loader.addAnimation([
	{
		 "start": 11.0*pattern, "duration": 1*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
				 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":"{return -Math.cos(getSceneTimeFromStart())*11.0-Math.sin(getSceneTimeFromStart())*25.0;}",
			 "y":"{return -Math.cos(getSceneTimeFromStart())*-11.0+Math.sin(getSceneTimeFromStart())*-25.0;}",
			 "z":0.0}
		]
		,"position":[
			 {"x":4.50, "y":-5.20, "z":-9.0}
		]
	}]);



				this.loader.addAnimation([
	{
		 "start": 12.0*pattern, "duration": .5*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":-1.0, "y":0.0, "z":1.0}
		]
		,"position":[
		{"x":0
		,"y":6.5
		,"z":0
		}]
	}]);

				this.loader.addAnimation([
	{
		 "start": 12.5*pattern, "duration": .5*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":1.0, "y":0.0, "z":0.0}
		]
		,"position":[
		{"x":0
		,"y":0	
		,"z":8
		}]
	}]);	
					this.loader.addAnimation([
	{
		 "start": 13.0*pattern, "duration": 1*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":-1.0, "z":0.0}
		]
		,"position":[
			 {"x":"{return Math.cos(getSceneTimeFromStart()*2)*7.0-Math.sin(getSceneTimeFromStart()*2)*7.0;}",
			 "z":"{return Math.cos(getSceneTimeFromStart()*2)*7.0+Math.sin(getSceneTimeFromStart()*2)*7.0;}"
		,"y":-6
		}]
	}]);
				this.loader.addAnimation([
	{
		 "start": 14*pattern, "duration": 0.5*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":-0.0, "y":1.0, "z":10.0}
		]
		,"position":[
		{"x":-6
		,"y":6	
		,"z":-1
		}]
	}]);

					this.loader.addAnimation([
	{
		 "start": 14.5*pattern, "duration": 0.5*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":3.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":1.0, "z":0.0}
		]
		,"position":[
		{"x":0
		,"y":5
		,"z":5
		}]
	}]);
	
				this.loader.addAnimation([
	{
		 "start": 15.0*pattern, "duration": 1*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
				 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":"{return -Math.cos(getSceneTimeFromStart())*11.0-Math.sin(getSceneTimeFromStart())*25.0;}",
			 "y":"{return -Math.cos(getSceneTimeFromStart())*-11.0+Math.sin(getSceneTimeFromStart())*-25.0;}",
			 "z":0.0}
		]
		,"position":[
			 {"x":4.50, "y":-5.20, "z":-8.0}
			 ,{"duration": .5*pattern,"z":-8}
			 ,{"duration": .1*pattern,"z":-3}
			 ,{"duration": .1*pattern,"z":-52}
			 ,{"duration": .3*pattern,"z":-522}
		]
	}]);

					this.loader.addAnimation([
	{
		 "start": 24.0*pattern, "duration": 2*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":-1.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":-1.0, "z":0.0}
		]
		,"position":[
			 {"x":"{return Math.cos(getSceneTimeFromStart()*2)*8.0-Math.sin(getSceneTimeFromStart()*2)*8.0;}",
			 "z":"{return Math.cos(getSceneTimeFromStart()*2)*8.0+Math.sin(getSceneTimeFromStart()*2)*8.0;}"
		,"y":-5
		}]
	}]);

				this.loader.addAnimation([
	{
		 "start": 26.0*pattern, "duration": 2*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
				 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":"{return -Math.cos(getSceneTimeFromStart())*11.0-Math.sin(getSceneTimeFromStart())*25.0;}",
			 "y":"{return -Math.cos(getSceneTimeFromStart())*-11.0+Math.sin(getSceneTimeFromStart())*-25.0;}",
			 "z":0.0}
		]
		,"position":[
			 {"x":4.50, "y":-5.20, "z":-9.0}
		]
	}]);

					this.loader.addAnimation([
	{
		 "start": 28.0*pattern, "duration": 2*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
			 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":0.0, "y":-1.0, "z":0.0}
		]
		,"position":[
			 {"x":"{return Math.cos(getSceneTimeFromStart()*2)*7.0-Math.sin(getSceneTimeFromStart()*2)*7.0;}",
			 "z":"{return Math.cos(getSceneTimeFromStart()*2)*7.0+Math.sin(getSceneTimeFromStart()*2)*7.0;}"
		,"y":-6
		}]
	}]);
	
					this.loader.addAnimation([
	{
		 "start": 30.0*pattern, "duration": 2*pattern, "camera": "Cam01"
		,"layer": 19000
		
		,"target":[
				 {"x":0.0, "y":0.0, "z":0.0}

		]
		,"up":[
			 {"x":"{return -Math.cos(getSceneTimeFromStart())*11.0-Math.sin(getSceneTimeFromStart())*25.0;}",
			 "y":"{return -Math.cos(getSceneTimeFromStart())*-11.0+Math.sin(getSceneTimeFromStart())*-25.0;}",
			 "z":0.0}
		]
		,"position":[
			 {"x":4.50, "y":-5.20, "z":-8.0}
			 ,{"duration": 1.5*pattern,"z":-8}
			 ,{"duration": .1*pattern,"z":-3}
			 ,{"duration": .1*pattern,"z":-52}
			 ,{"duration": .3*pattern,"z":-522}
		]
	}]);
	
	/*
		this.loader.addAnimation([
		{
			
		"start": 0, "duration": 18.5*pattern,
		"camera": "Cam01"
		,"layer": 19000
		,"runFunction":"{glLoadIdentity(); glRotatef(getSceneTimeFromStart()*25,0.0,0.0,1.0); }"
			}]);
			*/
			
					
		
		this.loader.addAnimation([
		{
			
		"start": 8*pattern, "duration": 8*pattern,
			
		"object":"data/lanka.obj"
	
		,"camera": "Cam01"
		,"layer": 19000
		,"scale":[{"uniform3d":.465}]
		,"position":[
			{"x":0
			,"y":0
			,"z":0}]
			
		
		}]);
		
		this.loader.addAnimation([
		{
			
		"start": 8*pattern, "duration": 8*pattern,
			
		"object":"data/4cats.obj"
	
		,"camera": "Cam01"
		,"layer": 19000
		,"scale":[{"uniform3d":.465}]
		,"position":[
			{"x":0
			,"y":"{return .25*Math.sin(15*getSceneTimeFromStart());}"
			,"z":0}]
			
		,"angle": [{
			"degreesX":"{return -55*getSceneTimeFromStart();}",
		}]
		
		}]);
		
		this.loader.addAnimation([
		{
		"start": 8*pattern, "duration": 8*pattern, "object":"data/4cats.obj"
		,"camera": "Cam01"
		,"layer": 19000
		,"scale":[{"uniform3d":.465}]
		
		,"position":[
			{"x":0
			,"y":"{return .25*Math.sin(15*getSceneTimeFromStart());}"
			,"z":0}]
	
		,"angle": [{
						"degreesY":"{return 45+55*getSceneTimeFromStart();}",
				"degreesZ":90,
		"degreesX":90

		}]
		
		}]);

			this.loader.addAnimation([
		{
			
		"start": 24*pattern, "duration": 8*pattern,
			
		"object":"data/lanka.obj"
	
		,"camera": "Cam01"
		,"layer": 19000
		,"scale":[{"uniform3d":"{return .465+Sync.getSyncValue('Sync2');}"}]
									 ,"shader":{
						"name":["data/shader/colorcycle.fs","data/shader/colorcycle.vs"],
						"variable":[
						{"name":"time","value":["{return -.1*getSceneTimeFromStart()}"]}
						]
					}	
		,"position":[
			{"x":0
			,"y":0
			,"z":0}]
			
		
		}]);
		
		this.loader.addAnimation([
		{
			
		"start": 24*pattern, "duration": 8*pattern,
			
		"object":"data/4cats.obj"
	
		,"camera": "Cam01"
		,"layer": 19000
		,"scale":[{"uniform3d":"{return .465+Sync.getSyncValue('Sync2');}"}]
		,"position":[
			{"x":0
			,"y":"{return .25*Math.sin(15*getSceneTimeFromStart());}"
			,"z":0}]
			
		,"angle": [{
	
			"degreesX":"{return -55*getSceneTimeFromStart();}",
		}]
										 ,"shader":{
						"name":["data/shader/specular.fs","data/shader/specular.vs"],
						"variable":[
						{"name":"time","value":["{return getSceneTimeFromStart()}"]}
						]
					}
					
		}]);
		
		
		this.loader.addAnimation([
		{
		"start": 24*pattern, "duration": 8*pattern, "object":"data/4cats.obj"
		,"camera": "Cam01"
		,"layer": 19000
		,"scale":[{"uniform3d":"{return .465+Sync.getSyncValue('Sync2');}"}]
		
		,"position":[
			{"x":0
			,"y":"{return .25*Math.sin(15*getSceneTimeFromStart());}"
			,"z":0}]
	
		,"angle": [{
						"degreesY":"{return 45+55*getSceneTimeFromStart();}",
				"degreesZ":90,
		"degreesX":90

		}]
										 ,"shader":{
						"name":["data/shader/specular.fs","data/shader/specular.vs"],
						"variable":[
						{"name":"time","value":["{return 3+getSceneTimeFromStart()}"]}
						]
					}
		}]);


//nyaaa
for(ii=0;ii<2;ii++)
{
	for(i=0;i<nya.length;i++)
		{
		this.loader.addAnimation ([
		{
		 "start": (ii*4+24)*pattern+nya[i]*tick*2-beat, "duration": 4*beat
		,"image": "data/nya.png"
		,"layer": 25000
		,"position": [{
			"x":1380,
			"y":160
		}
		,{"duration":4*beat,"x":-100}]
		,"scale":[{
			"y":0.7,
			"x":0.7}]
		}]);
}
	for(i=0;i<nyaa.length;i++)
	{
			 this.loader.addAnimation ([
		{
			 "start": (ii*4+24)*pattern+nyaa[i]*tick*2-beat, "duration": 4*beat
			,"image": "data/nyaa.png"
			,"layer": 25000
			,"position": [{
				"x":1380,
				"y":160
			}
		,{"duration":4*beat,"x":-100}]
			,"scale":[{
			"y":0.7,
			"x":0.7}]
					,"color":[{

				"a":255
			}]
			}]);
}		
}	

		this.loader.addAnimation ([
		{
		 "start": 23.5*pattern, "duration": .5*pattern
		,"image": "data/ka.png"
		,"layer": 25000
		,"position": [{
			"x":160,
			"y":360
		}]
		}]);
		this.loader.addAnimation ([
		{
		 "start": 23.625*pattern+5*tick, "duration": .375*pattern-5*tick
		,"image": "data/ra.png"
		,"layer": 25000
		,"position": [{
			"x":480,
			"y":360
		}]
		}]);
		this.loader.addAnimation ([
		{
		 "start": 23.75*pattern, "duration": .25*pattern
		,"image": "data/o.png"
		,"layer": 25000
		,"position": [{
			"x":800,
			"y":360
		}]
		}]);

		this.loader.addAnimation ([
		{
		 "start": 23.875*pattern, "duration": .125*pattern
		,"image": "data/ke.png"
		,"layer": 25000
		,"position": [{
			"x":1120,
			"y":360
		}]
		}]);


		
//this.distortion(0,pattern*164.5,40000,49960,50002);

this.catHeadScaler(0*pattern,16,9000);
this.catHeadDisco(4*pattern,4*pattern,13000);
this.catHeadScaler(8*pattern,32,9000);


this.rotoZoomer(16.0*pattern, 1*pattern, 14000);
this.sineCats(17.0*pattern, 1*pattern, 14000);
this.catHeadDisco2(18.0*pattern, 1*pattern, 14000);
this.tunnelOne(19*pattern,1*pattern,14000);
this.spiralCats(19*pattern,1*pattern,15000);
this.rotoZoomer(20.0*pattern, 1*pattern, 14000);
this.sineCats(21.0*pattern, 1*pattern, 14000);
this.catHeadDisco3(22.0*pattern, 1*pattern, 14000);
this.tunnelOne(23*pattern,1*pattern,14000);
this.spiralCats(23*pattern,1*pattern,15000);
this.catHeadScaler(24*pattern,64,9000);


this.showImage(0*pattern,.25*pattern,28000,"data/white.png",2.0,255,0,.25*pattern,0,640,360);
this.showImage(0.50*pattern,3.5*pattern,28000,"data/text1.png",1.0,0,.05*pattern,.1*pattern,255,640,580);
this.showImage(1.0*pattern,3.0*pattern,28000,"data/text2.png",1.0,0,.05*pattern,.1*pattern,255,640,440);
this.showImage(1.25*pattern,2.75*pattern,28000,"data/text2b.png",1.0,0,.05*pattern,.1*pattern,255,640,240);
this.showImage(1.5*pattern,2.5*pattern,28000,"data/text3.png",1.0,0,.05*pattern,.1*pattern,255,640,340);
this.showImage(2.0*pattern,2.0*pattern,28000,"data/text4.png",1.1,0,.05*pattern,.1*pattern,255,640,175);
this.showImage(0*pattern,.25*pattern,18000,"data/white.png",2.0,255,0,.25*pattern,0,640,360);
this.showImage(0.50*pattern,3.5*pattern,18000,"data/text1.png",1.0,0,.05*pattern,.1*pattern,255,640,580);
this.showImage(1.0*pattern,3.0*pattern,18000,"data/text2.png",1.0,0,.05*pattern,.1*pattern,255,640,440);
this.showImage(1.25*pattern,2.75*pattern,18000,"data/text2b.png",1.0,0,.05*pattern,.1*pattern,255,640,240);
this.showImage(1.5*pattern,2.5*pattern,18000,"data/text3.png",1.0,0,.05*pattern,.1*pattern,255,640,340);
this.showImage(2.0*pattern,2.0*pattern,18000,"data/text4.png",1.1,0,.05*pattern,.1*pattern,255,640,175);


	this.loader.addAnimation ([
	{
		 "start": 31.9*pattern	, "duration": 12.25*pattern
		,"image": "data/cat_blob_white_outline.png"
		,"layer": 36000

		,"color":[{
		
		"r":0,
		"g":0,
		"b":0,
		}]
		,"scale":[{"uniform3d":0}
		,{"duration":.8*pattern,"uniform3d":7.15}
		]
		,"angle": [{"degreesZ":"{return 3*getSceneTimeFromStart()}"}]

		}]);

				this.loader.addAnimation ([
		{
		 "start": 32.5*pattern, "duration": 100
		,"image": "data/end1.png"
		,"layer": 45000
		,"position": [{
			"x":640,
			"y":636
		}]
		}]);

				this.loader.addAnimation ([
		{
		 "start": 32.5*pattern+tick*7, "duration": 100
		,"image": "data/end2.png"
		,"layer": 45000
		,"position": [{
			"x":640,
			"y":512
		}]
		}]);

				this.loader.addAnimation ([
		{
		 "start": 32.5*pattern+tick*7*2, "duration": 100
		,"image": "data/end3.png"
		,"layer": 45000
		,"position": [{
			"x":640,
			"y":388
		}]
		}]);		
						this.loader.addAnimation ([
		{
		 "start": 32.5*pattern+tick*7*3, "duration": 100
		,"image": "data/end4.png"
		,"layer": 45000
		,"position": [{
			"x":640,
			"y":264
		}]
		}]);	
		
								this.loader.addAnimation ([
		{
		 "start": 32.5*pattern+tick*7*4, "duration": 100
		,"image": "data/end5.png"
		,"layer": 45000
		,"position": [{
			"x":640,
			"y":110
		}]
		}]);
this.hackGlow(0,160,0,20005,20008);
this.lut(0,pattern*164.5,20007,50008,50012,5.065,5.01);

	this.loader.addAnimation ([
	{
	"start": 20*pattern, "duration": 3*pattern
	,"layer": 50010
	,"fbo":{"name":"fbocrazypost","action":"begin"}
	},
	{
	"start": 20*pattern, "duration": 3*pattern
	,"layer": 50016,"fbo":{"name":"fbocrazypost","action":"unbind"}
	}
	]);

	this.loader.addAnimation ([
	    {
	         "start": 20*pattern, "duration":1*pattern
	        ,"layer": 50050, "image": ["fbocrazypost.color.fbo"]
		 ,"initFunction":"{fbocrazypostImage = imageLoadImage('fbocrazypost.color.fbo'); setTextureSizeToScreenSize(fbocrazypostImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fbocrazypostImage.ptr);}"
	     ,"shader":{
	            "name":"data/shader/mirrorscroll.fs",
	            "variable":[
	                {"name":"time","value":["{return 0.1*getSceneTimeFromStart();}"]}
	
	            ]
	        }
	    }
	]);

	this.loader.addAnimation ([
	    {
	         "start": 21*pattern, "duration":1*pattern
	        ,"layer": 50050, "image": ["fbocrazypost.color.fbo"]
		 ,"initFunction":"{fbocrazypostImage = imageLoadImage('fbocrazypost.color.fbo'); setTextureSizeToScreenSize(fbocrazypostImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fbocrazypostImage.ptr);}"
	     ,"shader":{
	            "name":"data/shader/tile2.fs",
	            "variable":[
	                {"name":"time","value":["{return 1*getSceneTimeFromStart();}"]}
	
	            ]
	        }
	    }
	]);	
	
		this.loader.addAnimation ([
	    {
	         "start": 22*pattern, "duration":1*pattern
	        ,"layer": 50050, "image": ["fbocrazypost.color.fbo"]
		 ,"initFunction":"{fbocrazypostImage = imageLoadImage('fbocrazypost.color.fbo'); setTextureSizeToScreenSize(fbocrazypostImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fbocrazypostImage.ptr);}"
	     ,"shader":{
	            "name":"data/shader/mirrorscroll2.fs",
	            "variable":[
	                {"name":"time","value":["{return 0.1*getSceneTimeFromStart();}"]}
	
	            ]
	        }
	    }
	]);	
	
//this.postTile(pattern*24,pattern*24, 50010, 50014,55000);

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

Demo.prototype.spiralCats = function(startTime, duration, layer)
{
for(i=minBlob2;i<maxBlob2;i++)
 {
this.loader.addAnimation([
    {
"start": startTime, "duration":duration

,"layer": layer, "image": ["data/cat_head.png"]
,"runFunction":"{increaseBlob2(maxBlob2);}"
,"position": [{
"x":"{return rotatedX(640,360,11*getBlob2Number(),Math.sin(23*pattern+getSceneTimeFromStart()*.25)*getBlob2Number()*1.5+1.5*(23*pattern+getSceneTimeFromStart()));}"
,"y":"{return rotatedY(640,360,11*getBlob2Number(),Math.sin(23*pattern+getSceneTimeFromStart()*.25)*getBlob2Number()*1.5+1.5*(23*pattern+getSceneTimeFromStart()));}"
}]
,"color":[{
	"r":(Math.sin(i*35+ 2) * 107 + 147),
	"g":(Math.sin(i*35+ 5) * 107 + 147),
	"b":(Math.sin(i*35+ 7) * 107 + 147)
	}]
,"scale":[{
"x":i*.015
,"y":i*.015
}]

/*,"scale":[{
"x":"{return 1.50-.25*Math.sin(8*(getBlob2Number()*.5+.75*getSceneTimeFromStart()))}"
,"y":"{return 1.50-.25*Math.sin(8*(getBlob2Number()*.5+.75*getSceneTimeFromStart()))}"
}]*/

    }]);
}
}
function rotatedX(x, y, distance, angle)
{
return Math.cos(angle) * distance - Math.sin(angle) * distance  + x;

}
function rotatedY(x, y, distance, angle)
{
return Math.sin(angle) * distance  + Math.cos(angle) * distance  + y;
}

function getBlob2Number()
{

return Blob2Number;
};

function increaseBlob2()
{
var currentBlob2=Blob2Number;
Blob2Number++
if(Blob2Number==maxBlob2)Blob2Number=minBlob2;


};

//good maxblob = 17
Demo.prototype.sineCats = function(startTime, duration, layer)
{
	 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/spiral_inverse.png"
		,"layer": 10000
		,"angle": [{"degreesZ":"{return -120*getSceneTimeFromStart()}"}]
		,"scale":[{"uniform3d":0.765}]
		,"color":[{
			"r":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
			"g":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}",
			"b":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}"
		}]
		}]);
		
 for(i=0;i<maxBlob;i++)
 {
 
this.loader.addAnimation([
    {
"start": startTime, "duration":duration

,"layer": layer, "image": ["data/walking_cat.png"]
,"runFunction":"{increaseBlob(maxBlob);}"
,"position": [{
"x":"{return -248+200*(6*(getBlobNumber()*.0975+.55*getSceneTimeFromStart())%10)}"
,"y":"{return 390+198*Math.sin(8*(getBlobNumber()*.5+.55*getSceneTimeFromStart()))}"}]
,"angle": [{"degreesZ":"{return -40*Math.sin(8*(getBlobNumber()*.5+.55*(getSceneTimeFromStart()-4)))}"}]

,"scale":[{
	"x":0.25
	,"y":0.25
}]

		,"color":[{
			"r":"{return 255-(Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127);}",
			"g":"{return 255-(Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127);}",
			"b":"{return 255-(Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127);}"
		}]

    }
]);
}
}


function getBlobNumber()
{

return blobNumber;
};

function increaseBlob(maxBlob)
{

blobNumber++
if(blobNumber==maxBlob)blobNumber=0;


};
Demo.prototype.catHeadDisco3 = function (startTime, duration, layer)
{
	
		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/cat_silhouette_2.png"
		,"layer": 20002
		,"position": [{
			"x":330,
			"y":200
		}]
				,"angle": [{
			"degreesX":"{return -55*getSceneTimeFromStart();}",
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
				,"color":[{

			"a":"{return 255-(555*(.5*getSceneTimeFromStart()%beat));}"
		}]
		}]);

		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/cat_silhouette.png"
		,"layer": 20002
		,"position": [{
			"x":330,
			"y":200
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
				,"color":[{

		"a":"{return 255-(555*(.5*(getSceneTimeFromStart()+beat)%beat));}"
		}]
		}]);
		
		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/cat_silhouette_2.png"
		,"layer": 20002
		,"position": [{
			"x":950,
			"y":400
		}]
		,"angle": [{
			"degreesZ":180,
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
		,"color":[{

			"a":"{return 255-(555*(.5*getSceneTimeFromStart()%beat));}"
		}]
		}]);

		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/cat_silhouette.png"
		,"layer": 20002
		,"position": [{
			"x":950,
			"y":400
		}]
		,"angle": [{
			"degreesZ":180,
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
				,"color":[{

		"a":"{return 255-(555*(.5*(getSceneTimeFromStart()+beat)%beat));}"
		}]
		}]);
		
 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/spiral.png"
		,"layer": 10002
		,"angle": [{"degreesZ":"{return 180*Math.sin(beat*6*getSceneTimeFromStart()%1.5)}"}]
		,"scale":[{"uniform3d":0.765}]
				,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}"
		}]
		}]);	


		
 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/spiral_inverse.png"
		,"layer": 10000
		,"angle": [{"degreesZ":"{return -120*getSceneTimeFromStart()}"}]
		,"scale":[{"uniform3d":0.765}]
				,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}"
		}]
		}]);
}

Demo.prototype.catHeadDisco2 = function (startTime, duration, layer)
{
	
		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/cat_silhouette.png"
		,"layer": 20002
		,"position": [{
			"x":380,
			"y":200
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
				,"color":[{

			"a":"{return 255-(555*(.5*getSceneTimeFromStart()%beat));}"
		}]
		}]);

		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/cat_silhouette_2.png"
		,"layer": 20002
		,"position": [{
			"x":380,
			"y":200
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
				,"color":[{

		"a":"{return 255-(555*(.5*(getSceneTimeFromStart()+beat)%beat));}"
		}]
		}]);
		
		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/cat_silhouette.png"
		,"layer": 20002
		,"position": [{
			"x":900,
			"y":200
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
				,"color":[{

			"a":"{return 255-(555*(.5*getSceneTimeFromStart()%beat));}"
		}]
		}]);

		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/cat_silhouette_2.png"
		,"layer": 20002
		,"position": [{
			"x":900,
			"y":200
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
				,"color":[{

		"a":"{return 255-(555*(.5*(getSceneTimeFromStart()+beat)%beat));}"
		}]
		}]);
		
 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/spiral.png"
		,"layer": 10002
		,"angle": [{"degreesZ":"{return 180*Math.sin(beat*6*getSceneTimeFromStart()%1.5)}"}]
		,"scale":[{"uniform3d":0.765}]
				,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}"
		}]
		}]);	


		
 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/spiral_inverse.png"
		,"layer": 10000
		,"angle": [{"degreesZ":"{return -120*getSceneTimeFromStart()}"}]
		,"scale":[{"uniform3d":0.765}]
				,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}"
		}]
		}]);
}


Demo.prototype.catHeadDisco = function (startTime, duration, layer)
{
		this.loader.addAnimation([
		{
			
		"start": startTime+pattern*3.5, "duration": pattern*.5,
			
		"object":"data/discoball.obj"
	
		,"camera": "Cam01"
		,"layer": 12000
		,"scale":[{"uniform3d":"{return 4.0+.5*Math.sin(beat*12*getSceneTimeFromStart())}"}]
		,"angle": [{"degreesY":"{return 90*getSceneTimeFromStart()}"}]
		,"position":[
			{"x":0
			,"y":0
			,"z":"{return -2.0}"}]
					 ,"shader":{
						"name":["data/shader/colorcycle.fs","data/shader/colorcycle.vs"],
						"variable":[
						{"name":"time","value":["{return .1*getSceneTimeFromStart()}"]}
						]
					}		
		
		}]);
		 this.loader.addAnimation ([
	{
		 "start": startTime+3.5*pattern	, "duration": pattern*.5
		,"image": "data/cat_silhouette.png"
		,"layer": 20002
		,"position": [{
			"x":340,
			"y":200
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}
		,{"duration": .5*pattern,"x":1,"y":1}]
				,"color":[{
				"a":255}
				,{"duration": .5*pattern,"a":0}]
		}]);

		 this.loader.addAnimation ([
	{
		 "start": startTime+3.5*pattern	, "duration": pattern*.5
		,"image": "data/cat_silhouette_2.png"
		,"layer": 20002
		,"position": [{
			"x":940,
			"y":200
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}
		,{"duration": .5*pattern,"x":1,"y":1}]
				,"color":[{
				"a":255}
				,{"duration": .5*pattern,"a":0}]
		}]);
		
	this.loader.addAnimation([
		{
			
		"start": startTime, "duration": duration-pattern*.5,
			
		"object":"data/discoball.obj"
	
		,"camera": "Cam01"
		,"layer": 12000
		,"scale":[{"uniform3d":"{return 2.0+.5*Math.sin(beat*12*getSceneTimeFromStart())}"}]
		,"angle": [{"degreesY":"{return 90*getSceneTimeFromStart()}"}]
		,"position":[
			{"x":6
			,"y":4
			,"z":"{return -2.0}"}]
					 ,"shader":{
						"name":["data/shader/colorcycle.fs","data/shader/colorcycle.vs"],
						"variable":[
						{"name":"time","value":["{return .1*getSceneTimeFromStart()}"]}
						]
					}		
		
		}]);

	this.loader.addAnimation([
		{
			
		"start": startTime, "duration": duration -pattern*.5,
			
		"object":"data/discoball.obj"
	
		,"camera": "Cam01"
		,"layer": 12000
		,"scale":[{"uniform3d":"{return 2.0+.5*Math.sin(beat*3+beat*12*getSceneTimeFromStart())}"}]
		,"angle": [{"degreesY":"{return -90*getSceneTimeFromStart()}"}]
		,"position":[
			{"x":-6
			,"y":4
			,"z":-3}]
					 ,"shader":{
						"name":["data/shader/colorcycle.fs","data/shader/colorcycle.vs"],
						"variable":[
						{"name":"time","value":["{return -.1*getSceneTimeFromStart()}"]}
						]
					}		
		
		}]);

this.loader.addAnimation([
		{
			
		"start": startTime, "duration": duration -pattern*.5,
			
		"object":"data/discoball.obj"
	
		,"camera": "Cam01"
		,"layer": 12000
		,"scale":[{"uniform3d":"{return 2.0+.5*Math.sin(beat*9+beat*12*getSceneTimeFromStart())}"}]
		,"angle": [{"degreesY":"{return 90*getSceneTimeFromStart()}"}]
		,"position":[
			{"x":6
			,"y":-4
			,"z":"{return -2.0}"}]
					 ,"shader":{
						"name":["data/shader/colorcycle.fs","data/shader/colorcycle.vs"],
						"variable":[
						{"name":"time","value":["{return .1*getSceneTimeFromStart()}"]}
						]
					}		
		
		}]);

	this.loader.addAnimation([
		{
			
		"start": startTime, "duration": duration -pattern*.5,
			
		"object":"data/discoball.obj"
	
		,"camera": "Cam01"
		,"layer": 12000
		,"scale":[{"uniform3d":"{return 2.0+.5*Math.sin(beat*6+beat*12*getSceneTimeFromStart())}"}]
		,"angle": [{"degreesY":"{return -90*getSceneTimeFromStart()}"}]
		,"position":[
			{"x":-6
			,"y":-4
			,"z":-3}]
					 ,"shader":{
						"name":["data/shader/colorcycle.fs","data/shader/colorcycle.vs"],
						"variable":[
						{"name":"time","value":["{return -.1*getSceneTimeFromStart()}"]}
						]
					}		
		
		}]);
		

		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration -pattern*.5
		,"image": "data/cat_silhouette.png"
		,"layer": 20002
		,"position": [{
			"x":640,
			"y":200
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
				,"color":[{

			"a":"{return 255-(555*(.5*getSceneTimeFromStart()%beat));}"
		}]
		}]);

		 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration -pattern*.5
		,"image": "data/cat_silhouette_2.png"
		,"layer": 20002
		,"position": [{
			"x":640,
			"y":200
		}]
		,"scale":[{
		"y":0.8325,
		"x":0.8325}]
				,"color":[{

		"a":"{return 255-(555*(.5*(getSceneTimeFromStart()+beat)%beat));}"
		}]
		}]);
		
 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/spiral.png"
		,"layer": 10002
		,"angle": [{"degreesZ":"{return 180*Math.sin(beat*6*getSceneTimeFromStart()%1.5)}"}]
		,"scale":[{"uniform3d":0.765}]
				,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}"
		}]
		}]);	


		
 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/spiral_inverse.png"
		,"layer": 10000
		,"angle": [{"degreesZ":"{return -120*getSceneTimeFromStart()}"}]
		,"scale":[{"uniform3d":0.765}]
				,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}"
		}]
		}]);
}
Demo.prototype.rotoZoomer = function (startTime, duration, layer, imageName)
{
	 this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": duration
		,"image": "data/spiral_inverse.png"
		,"layer": 10000
		,"angle": [{"degreesZ":"{return -120*getSceneTimeFromStart()}"}]
		,"scale":[{"uniform3d":0.765}]
				,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}"
		}]
		}]);
	this.loader.addAnimation ([
	{
		 "start": startTime, "duration": duration
		,"image": "data/cat_head.png"
		,"layer": layer
		,"scale":[{"uniform3d":4.0}]
		,"angle": [{"degreesZ":"{return -144*getSceneTimeFromStart()}"}]
		,"shader":{
			"name":"data/shader/tile.fs",
			"variable":[
				{"name":"time","value":["{return 4*getSceneTimeFromStart()}"]}
			]
		}

	}]);	
}

Demo.prototype.showImage = function (startTime, duration, layer, imagename, imagescale,startAlpha,fadeIn,fadeOut,imageColor,positionX,positionY)
{
		this.loader.addAnimation([
		{
		"start": startTime, "duration": duration, "image": imagename
		,"layer": layer
		,"scale":[{"uniform3d":imagescale*2}
		,{"duration": fadeIn*2,"uniform3d":imagescale}]
		,"angle": [{"degreesZ":"{return 5*Math.sin(5*getSceneTimeFromStart())}"}]
		,"position":[
		{"x":positionX
		,"y":positionY
		}]
		,"color": [{"r":imageColor,"g":imageColor,"b":imageColor,
		"a":startAlpha}
		,{"duration": fadeIn,"a":255}
		,{"duration": duration-fadeIn-fadeOut,"a":255}
		,{"duration": fadeOut,"a":0}]
		}]);
}	
		
	Demo.prototype.tunnelOne = function (startTime, duration, layer)
{
				this.loader.addAnimation([
					{
					"start": startTime, "end": startTime+duration, "image": ["data/rainbowheart.png"]
					,"layer": layer
					

					,"scale": [{"x":2.5,"y":2.5,"z":-21}]
						     ,"shader":{
						"name":"data/shader/tunnel.fs",
						"variable":[
						{"name":"time","value":["{return 2.12*getSceneTimeFromStart()}"]},
						{"name":"distort","value":.1}
						]
					}
					}]);
}
	
Demo.prototype.catHeadScaler = function (startTime, duration, layer)
{
	for(i=0;i<9;i++)
	{
	this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": .85*pattern
		,"image": "data/cat_blob_white_outline.png"
		,"layer": layer-36+i*2

		,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}"
		}]
		,"scale":[{"uniform3d":9.15-(1*i)}
		,{"duration":1.5*pattern*((2*i+i)*.08),"uniform3d":9.15}
		]
		,"angle": [{"degreesZ":i*72+72}]

		}]);	

	this.loader.addAnimation ([
	{
		 "start": startTime	, "duration": .85*pattern
		,"image": "data/cat_blob_white_outline.png"
		,"layer": layer-35+i*2

		,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}"
		}]
		,"scale":[{"uniform3d":8.65-(1*i)}
		,{"duration":1.5*pattern*(2*i*.08),"uniform3d":9.15}
		]
		,"angle": [{"degreesZ":i*72+36+72}]

		}]);	

	}
	for(i=0;i<duration;i++)
{

		this.loader.addAnimation ([
	{
		 "start": startTime+i*.96	, "duration": .85*pattern
		,"image": "data/cat_blob_white_outline.png"
		,"layer": layer+i

		,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 0) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 2) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 4) * 127 + 127;}"
		}]
		,"scale":[{"uniform3d":.15}
		,{"duration":1.5*pattern,"uniform3d":9.15}]
		,"angle": [{"degreesZ":i*72}]

		}]);	
	
		this.loader.addAnimation ([
	{
		 "start": startTime+.48+i*.96	, "duration": .85*pattern
		,"image": "data/cat_blob_white_outline.png"
		,"layer": layer+i

		,"color":[{
		
		"r":"{return Math.sin(getSceneTimeFromStart()*5+ 7) * 127 + 127;}",
		"g":"{return Math.sin(getSceneTimeFromStart()*5+ 5) * 127 + 127;}",
		"b":"{return Math.sin(getSceneTimeFromStart()*5+ 3) * 127 + 127;}"
		}]
		,"scale":[{"uniform3d":.015}
		,{"duration":1.5*pattern,"uniform3d":9.15}]
		,"angle": [{"degreesZ":36+i*72}]

		}]);		
}
}
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":[.0]}
				,{"name":"pixelSize","value":[.21,2.21]}
				,{"name":"noiseWaveSpeed","value":[0]}
				,{"name":"noiseWaveSize","value":[0]}
				,{"name":"noiseLuminance","value":[1]}
				,{"name":"noiseAlpha","value":[0.0]}
				,{"name":"colorComponentDistortionX","value":[0.05,0.0,0.25,0.0]}
				,{"name":"colorComponentDistortionY","value":[0.05,0.0,0.25,0.0]}
				,{"name":"distortionAmount","value":[0.505]}
			]
			}
		}]);
}

Demo.prototype.lut = function (startTime, duration, startLayer, endLayer, layer)
{
	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
	
		 ,"initFunction":"{fboBcImage = imageLoadImage('fbobc.color.fbo'); setTextureSizeToScreenSize(fboBcImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fboBcImage.ptr);}"
	        ,"layer": layer, "image": ["fbobc.color.fbo","data/2dlut.png"]
	     ,"shader":{
	            "name":"data/shader/lut.fs",
	            "variable":[
				{"name":"lut","type":"int","value":[1]}
	            ]
	        }
	    }
	]);
	
	
}

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.edgeDetect = function (startTime, duration, startLayer, endLayer, layer)
{
	this.loader.addAnimation ([
	{
	"start": startTime, "duration": duration
	,"layer": startLayer
	,"fbo":{"name":"fboed","action":"begin"}
	},
	{
	"start": startTime, "duration": duration
	,"layer": endLayer,"fbo":{"name":"fboed","action":"unbind"}
	}
	]);
	this.loader.addAnimation ([
	    {
	         "start": startTime, "duration":duration
	        ,"layer": layer, "image": ["fboed.color.fbo"]
		 ,"initFunction":"{fboedImage = imageLoadImage('fboed.color.fbo'); setTextureSizeToScreenSize(fboedImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fboedImage.ptr);}"
	     ,"shader":{
	            "name":"data/shader/edgedetect.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)
{

	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": 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*4-Math.random()*randomScaler*4,
						"z":positionZ+Math.random()*randomScaler*3-Math.random()*randomScaler*3+40}]
						,"scale":[{"uniform3d":0}
						,{"duration":duration*durationScaler, "uniform3d":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)
{
randomScaler=randomScaler*3;
	for(ie=0;ie<10;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()*randomScaler*3-Math.random()*randomScaler*3,
						"y":positionY+Math.random()*randomScaler*2+15,
						"z":positionZ+Math.random()*randomScaler*1-Math.random()*randomScaler*1}
						,{"duration":duration*durationScaler,
						"x":positionX+Math.random()*randomScaler*3-Math.random()*randomScaler*3,
						"y":positionY-150+Math.random()*randomScaler*1,
						"z":positionZ+Math.random()*randomScaler*1-Math.random()*randomScaler*1}]
						,"scale":[{"uniform3d":scale*randomScale*.9}
						,{"duration":duration*durationScaler, "uniform3d":scale*randomScale*.25}]
						,"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.explosion3 = function(startTime, duration, positionX, positionY, positionZ, scale, randomScaler, colorR, colorG, colorB, startRandomScaler,durationScaler)
{

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

	
				this.loader.addAnimation([
						{
						"start": startTime, "duration": duration,  "object":"cubes"+cubeNumber,"shape":{"type":"CUBE"}
						,"layer": 21500
						
						,"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+1,
						"z":positionZ+Math.random()*randomScaler*1-Math.random()*randomScaler*1}]
						,"scale":[{"uniform3d":1}
						,{"duration":duration*durationScaler, "uniform3d":scale*randomScale*.9}]
						,"color":[{"r":255*colorR,"g":255*colorG,"b":255*colorB,"a":0}
						,{"duration":3, "r":255*colorR,"g":255*colorG,"b":255*colorB,"a":255}
						,{"duration":duration*durationScaler*.90, "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.explosion4 = function(startTime, duration, positionX, positionY, positionZ, scale, randomScaler, colorR, colorG, colorB, startRandomScaler,durationScaler)
{

	for(ie=0;ie<50;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*4-Math.random()*randomScaler*4,
						"z":positionZ+Math.random()*randomScaler*3-Math.random()*randomScaler*3-10}]
						,"scale":[{"uniform3d":0}
						,{"duration":duration*durationScaler, "uniform3d":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.postTile = 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","data/lut.png"]
		 ,"initFunction":"{fbohgImage = imageLoadImage('fbohg.color.fbo'); setTextureSizeToScreenSize(fbohgImage.ptr); }"
		 ,"runFunction":"{setTextureSizeToScreenSize(fbohgImage.ptr);}"
	     ,"shader":{
	            "name":"data/shader/fsulut.fs",
	            "variable":[
	                  {"name":"time","value":["{return getSceneTimeFromStart()-pattern;}"]}
					  ,{"name":"texLUT","type":"int","value":[1]}
	            ]	
	           
	        }
	    }
	]);
}
	
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;}"]}
					,{"name":"multiplier","value":["{return Sync.getSyncValue('Sync1');}"]}	
	            ]
	        }
	    }
	]);
}


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 getNextNumber(maxVal)
{
		nextNumber++;
	if(nextNumber>maxVal)nextNumber=1;
	return nextNumber;
}

function getNumber()
{
	return nextNumber;
}

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

}


