
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 swordSyncPattern = [
	1,
	1,
	1,
	1,
	
	1,
	0,
	0,
	0,
	
	1,
	0,
	0,
	0,
	
	0,
	0,
	0,
	0,

	1,
	0,
	1,
	0,
	
	1,
	0,
	0,
	0,
	
	1,
	0,
	0,
	0,
	
	0,
	0,
	0,
	0,

	1,
	1,
	0,
	1,
	
	1,
	0,
	0,
	0,
	
	1,
	0,
	0,
	0,
	1,
	0,
	0,
	0,

	1,
	1,
	1,
	1,
	1,
	0,
	0,
	0,
	1,
	1,
	1,
	1,
	1,
	0,
	0,
	0
	
	]
	var syncTime = [
		,13*pattern+beat
		];
	


Demo.prototype.init = function()
{
	Sync.addSync(
	[
		 { "name":"tunneldistort", "type":"rocket" }
		 ,{ "name":"distortionamount", "type":"rocket"}
		  ,{ "name":"brightnessamount", "type":"rocket"}
		   ,{ "name":"contrastamount", "type":"rocket"}
		  ,{ "name":"Mirror1", "type":"rocket"}
		  ,{ "name":"Mirror2", "type":"rocket"}
		  ,{ "name":"Mirror3", "type":"rocket"}
		  ,{ "name":"Mirror4", "type":"rocket"}
		  ,{ "name":"Camerax", "type":"rocket"}
		  ,{ "name":"Cameray", "type":"rocket"}
		  ,{ "name":"Cameraz", "type":"rocket"}  
		  ,{ "name":"Cameraz", "type":"rocket"}  
		  
		  ,{ "name":"CameraTargetz", "type":"rocket"}  
		  ,{ "name":"CameraTargety", "type":"rocket"}  
		  ,{ "name":"CameraTargetx", "type":"rocket"} 
		  ,{ "name":"CastleDisplaceAmount", "type":"rocket"}  		  
	]);
	//0-9999 fbo0k
	//10000-19999 fbo10k
	//20000-29999 fbo20k
	//30000-39999 fbo30k

		this.loader.addAnimation ([
	{
		 "start": 0*pattern, "duration": 55*pattern
		,"image": "data/vignette.png"
		,"layer": 99999

	}]);
	
/*
	this.loader.addAnimation([
    {
         "start": 0, "duration":260
        ,"layer": 5, "image": ["data/empty.png"]
		,"scale":[{"x":1.75,"y":1.75}]

     ,"shader":{
            "name":"data/shader/testshader.fs",
            "variable":[
                  {"name":"time","value":["{return getSceneTimeFromStart();}"]},
		
            ]
        }
    }
]);
*/

//texts



	this.loader.addAnimation([
    {
         "start": 0, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text1.png"]
		,"scale":[{"x":1.5,"y":1.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 2*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text2.png"]
		,"scale":[{"x":1.5,"y":1.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 12*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text3.png"]
		,"scale":[{"x":2.5,"y":2.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"color":[{"r":0.0,"g":0.0,"b":0.0,"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 14*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text4.png"]
		,"scale":[{"x":2.5,"y":2.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"color":[{"r":0.0,"g":0.0,"b":0.0,"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 14*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text4.png"]
		,"scale":[{"x":2.5,"y":2.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"color":[{"r":0.0,"g":0.0,"b":0.0,"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 28*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text5.png"]
		,"scale":[{"x":3.5,"y":3.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"position":[
		{"x":640
		,"y":540
		}]
		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);


	this.loader.addAnimation([
    {
         "start": 30*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text6.png"]
		,"scale":[{"x":3.5,"y":3.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"position":[
		{"x":640
		,"y":540
		}]
		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);


	this.loader.addAnimation([
    {
         "start": 32*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text7.png"]
		,"scale":[{"x":3.5,"y":3.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"position":[
		{"x":640
		,"y":540
		}]
		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);


	this.loader.addAnimation([
    {
         "start": 34*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text8.png"]
		,"scale":[{"x":3.5,"y":3.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"position":[
		{"x":640
		,"y":540
		}]
		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]			
    }
]);

	this.loader.addAnimation([
    {
         "start": 36*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text10.png"]
		,"scale":[{"x":2.5,"y":2.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 38*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text9.png"]
		,"scale":[{"x":2.5,"y":2.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]
		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 48*pattern, "duration":2*pattern
        ,"layer": 49951, "image": ["data/text11.png"]
		,"scale":[{"x":3.5,"y":3.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]

		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 50*pattern, "duration":4*pattern
        ,"layer": 49951, "image": ["data/text12.png"]
		,"scale":[{"x":3.5,"y":3.5}
		,{"duration":2*pattern,"x":1.3,"y":1.3}]

		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 52*pattern, "duration":4*pattern
        ,"layer": 49951, "image": ["data/text15.png"]
		,"scale":[{"x":4.5,"y":4.5}
		,{"duration":2*pattern,"x":2.3,"y":2.3}]

		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);

	this.loader.addAnimation([
    {
         "start": 54*pattern, "duration":4*pattern
        ,"layer": 49951, "image": ["data/text14.png"]
		,"scale":[{"x":4.5,"y":4.5}
		,{"duration":2*pattern,"x":2.3,"y":2.3}]
		,"color":[{"a":0.0}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":0.5*pattern,"a":255}
		,{"duration":1.0*pattern,"a":0}]
    }
]);


	this.loader.addAnimation([
	{
		 "start": 4*pattern, "duration": 8*pattern, "camera": "Cam01"
		,"layer": 22001
		,"target":[
		{"x":"{return Sync.getSyncValue('CameraTargetx');}"
		,"y":"{return Sync.getSyncValue('CameraTargety');}"
		,"z":"{return Sync.getSyncValue('CameraTargetz');}"
		}]
		,"up":[ {"x":0.0, "y":"{return getSceneTimeFromStart();}", "z":"{return 2*Math.sin(getSceneTimeFromStart());}"}
		]
				,"position":[
		{"x":"{return Sync.getSyncValue('Camerax');}"
		,"y":"{return Sync.getSyncValue('Cameray');}"
		,"z":"{return Sync.getSyncValue('Cameraz');}"
		}]
	}]);

		this.loader.addAnimation([
	{
		 "start": 16*pattern, "duration": 4*pattern, "camera": "Cam01"
		,"layer": 22001
		,"target":[
		{"x":"{return Sync.getSyncValue('CameraTargetx');}"
		,"y":"{return Sync.getSyncValue('CameraTargety');}"
		,"z":"{return Sync.getSyncValue('CameraTargetz');}"
		}]
		,"up":[ {"x":15.0, "y":"{return getSceneTimeFromStart();}", "z":"{return 2*Math.sin(getSceneTimeFromStart());}"}
		]
				,"position":[
		{"x":"{return Sync.getSyncValue('Camerax');}"
		,"y":"{return Sync.getSyncValue('Cameray');}"
		,"z":"{return Sync.getSyncValue('Cameraz');}"
		}]
	}]);


	
		this.loader.addAnimation([
	{
		 "start": 20*pattern, "duration": 4*pattern, "camera": "Cam01"
		,"layer": 22001
		,"target":[
		{"x":"{return Sync.getSyncValue('CameraTargetx');}"
		,"y":"{return Sync.getSyncValue('CameraTargety');}"
		,"z":"{return Sync.getSyncValue('CameraTargetz');}"
		}]
		,"up":[ {"x":180.0, "y":"{return getSceneTimeFromStart();}", "z":"{return 2*Math.sin(getSceneTimeFromStart());}"}
		]
				,"position":[
		{"x":"{return Sync.getSyncValue('Camerax');}"
		,"y":"{return Sync.getSyncValue('Cameray');}"
		,"z":"{return Sync.getSyncValue('Cameraz');}"
		}]
	}]);
	
	
				
					
				this.loader.addAnimation([
					{
					"start": 4*pattern, "duration": 8*pattern, "object":"data/lightning_ball.obj"
					,"camera": "Cam01"
					,"layer": 22001
					,"position":[
					{"x":32
					,"y":2
					,"z":-2.75
					}]
					,"angle": [{"degreesX":"{return getSceneTimeFromStart()*25.5}","degreesY":"{return getSceneTimeFromStart()*25}","degreesZ":"{return getSceneTimeFromStart()*25.5}"}]
					
			        ,"shader":{
					"name":["data/shader/heightmap.fs","data/shader/heightmap.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*1.0}"]}
					,{"name":"diffuseScrollSpeed","value":[.5]}
					,{"name":"displaceAmount","value":[7]}
					]
					}

					}]);
					
				this.loader.addAnimation([
					{
					"start": 4*pattern, "duration": 8*pattern, "object":"data/ugly_castle2.obj"
					,"camera": "Cam01"
					,"layer": 22001
			        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}					
					}]);


					
		this.loader.addAnimation([
			{
		 "start": 0*pattern, "duration": 4*pattern, "camera": "Cam02"
		,"layer": 22001
		,"target":[
		{"x":0
		,"y":0
		,"z":0
		}]
		,"up":[
		{"x":0
		,"y":1
		,"z":0
		}]
				,"position":[
		{"x":0
		,"y":0
		,"z":15
		}]
	}]);
	
	
		this.loader.addAnimation([
			{
		 "start": 12*pattern, "duration": 4*pattern, "camera": "Cam02"
		,"layer": 22001
		,"target":[
		{"x":0
		,"y":0
		,"z":0
		}]
		,"up":[
		{"x":0
		,"y":1
		,"z":0
		}]
				,"position":[
		{"x":0
		,"y":0
		,"z":15
		}]
	}]);
	
			this.loader.addAnimation([
			{
		 "start": 24*pattern, "duration": 8*pattern, "camera": "Cam02"
		,"layer": 22001
		,"target":[
		{"x":0
		,"y":0
		,"z":0
		}]
		,"up":[
		{"x":0
		,"y":1
		,"z":0
		}]
				,"position":[
		{"x":0
		,"y":0
		,"z":15
		}]
	}]);
	/*
	this.loader.addAnimation([
    {
         "start": 8*pattern, "duration":4*pattern
        ,"layer": 25000, "image": {"name":"data/interceptor.ogv", "video":{"speed":0.2} }
		,"scale":[{"x":1.5,"y":1.5}]
		,"color":[{"r":255,"g":255,"b":255,"a":25}]

		
    }
]);
	*/

				this.loader.addAnimation([
					{
					"start": 12*pattern, "duration": 4*pattern, "object":"data/lightning_ball.obj"
					,"camera": "Cam02"
					,"layer": 22001
					,"position":[
					{"x":0
					,"y":0
					,"z":0
					}]
					,"angle": [{"degreesX":"{return getSceneTimeFromStart()*25.5}","degreesY":"{return getSceneTimeFromStart()*25}","degreesZ":"{return getSceneTimeFromStart()*25.5}"}]
					
			        ,"shader":{
					"name":["data/shader/heightmap.fs","data/shader/heightmap.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*1.0}"]}
					,{"name":"diffuseScrollSpeed","value":[.5]}
					,{"name":"displaceAmount","value":[7]}
					]
					}

					}]);
	
				this.loader.addAnimation([
					{
					"start": 16*pattern, "duration": 8*pattern, "object":"data/ugly_castle2.obj"
					,"camera": "Cam01"
					,"layer": 22001
			        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}					
					}]);
					
					
				this.loader.addAnimation([
					{
					"start": 24*pattern, "duration": 4*pattern, "image": ["data/noise.png"]
					,"layer": 22000
					

					,"scale": [{"x":0.1,"y":-2,"z":-11}]
						     ,"shader":{
						"name":"data/shader/tunnel.fs",
						"variable":[
						{"name":"time","value":["{return 10+getSceneTimeFromStart();}"]}
						]
					}
					}]);

									this.loader.addAnimation([
					{
					"start": 24*pattern, "duration": 4*pattern, "object":"data/SWORD.obj"
					,"camera": "Cam02"
					,"layer": 22005
				,"angle": [{"degreesX":90,"degreesY":0,"degreesZ":0}
				,{"duration":4*pattern,"degreesZ":360}]
				,"position":[
				{"x":0
				,"y":-7
				,"z":0
		}
		,{"duration":4*pattern,"y":5}]
				,"scale": [
					{"x":.75
					,"y":.75
					,"z":.75
		}]
					}]);
					
				this.loader.addAnimation([
					{
					"start": 36*pattern, "duration": 4*pattern, "image": ["data/firetexture2.png"]
					,"layer": 21001
					

					,"scale": [{"x":2,"y":1,"z":1}]
						     ,"shader":{
						"name":"data/shader/tunnel2.fs",
						"variable":[
						{"name":"time","value":["{return 10+getSceneTimeFromStart()*.1;}"]}
						]
					}
					}]);
					
for(i=0;i<60;i++)
{
	var randomY=Math.random()*1720;
	var randomZ=.05+Math.random();
	var yTarget=randomY-(500*randomZ);
	
	this.loader.addAnimation([
    {
         "start": 36*pattern, "duration":4*pattern
		 ,"perspective":"2d"
        ,"layer": 22001, "image": ["data/woman_silhouette.png"]
		,"color":[{"r":0.0,"g":0.0,"b":0.0}]
		,"scale":[{"x":0.4*randomZ,"y":-0.5*randomZ}]
				,"position":[
		{"x":Math.random()*1480
		,"y":randomY

		}
		,{"duration":4*pattern,"y":yTarget}]
    }])
}



				this.loader.addAnimation([
					{
					"start": 28*pattern, "duration": 8*pattern, "image": ["data/noise.png","data/noise.png"]
					,"layer": 21001
					
					,"position":[
					{"x":640
					,"y":540
					}]
					,"scale": [{"x":-5,"y":5,"z":1}]
						     ,"shader":{
						"name":"data/shader/fire.fs",
						"variable":[
						{"name":"time","value":["{return 10+getSceneTimeFromStart();}"]}
						]
					}
					}]);

				this.loader.addAnimation([
					{
					"start": 48*pattern, "duration": 8*pattern, "image": ["data/noise.png","data/noise.png"]
					,"layer": 21001
					
					,"position":[
					{"x":640
					,"y":540
					}]
					,"scale": [{"x":-5,"y":5,"z":1}]
						     ,"shader":{
						"name":"data/shader/fire.fs",
						"variable":[
						{"name":"time","value":["{return 10+getSceneTimeFromStart();}"]}
						]
					}
					}]);				
		this.loader.addAnimation([
	{
		 "start": 28*pattern, "duration": 8*pattern, "camera": "Cam01"
		,"layer": 22001
		,"target":[
		{"x":"{return Sync.getSyncValue('CameraTargetx');}"
		,"y":"{return Sync.getSyncValue('CameraTargety');}"
		,"z":"{return Sync.getSyncValue('CameraTargetz');}"
		}]
		,"up":[ {"x":0.0, "y":"{return getSceneTimeFromStart();}", "z":"{return 2*Math.sin(getSceneTimeFromStart());}"}
		]
				,"position":[
		{"x":"{return Sync.getSyncValue('Camerax');}"
		,"y":"{return Sync.getSyncValue('Cameray');}"
		,"z":"{return Sync.getSyncValue('Cameraz');}"
		}]
	}]);


				this.loader.addAnimation([
					{
					"start": 28*pattern , "duration": 8*pattern, "object":"data/swordhill.obj"
					,"camera": "Cam01"
					,"layer": 22001
	
					,"angle": [{"degreesX":-90,"degreesY":0,"degreesZ":35}
					,{"duration":8*pattern,"degreesZ":360}]
			        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}					
					}]);
										this.loader.addAnimation([
					{
					"start": 40*pattern, "duration": 8*pattern, "object":"data/ugly_castle2.obj"
					,"camera": "Cam01"
					,"layer": 22001
			        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}					
					}]);



					
						this.loader.addAnimation([
	{
		 "start": 40*pattern, "duration": 8*pattern, "camera": "Cam01"
		,"layer": 22001
		,"target":[
		{"x":"{return Sync.getSyncValue('CameraTargetx');}"
		,"y":"{return Sync.getSyncValue('CameraTargety');}"
		,"z":"{return Sync.getSyncValue('CameraTargetz');}"
		}]
		,"up":[ {"x":"{return 0.15*Math.sin(getSceneTimeFromStart());}", "y":0.1, "z":0.0}
		]
				,"position":[
		{"x":"{return Sync.getSyncValue('Camerax');}"
		,"y":"{return Sync.getSyncValue('Cameray');}"
		,"z":"{return Sync.getSyncValue('Cameraz');}"
		}]
	}]);
	
			this.loader.addAnimation([
	{
		 "start": 48*pattern, "duration": 16*pattern, "camera": "Cam02"
		,"layer": 22001
		,"target":[
		{"x":"{return Sync.getSyncValue('CameraTargetx');}"
		,"y":"{return Sync.getSyncValue('CameraTargety');}"
		,"z":"{return Sync.getSyncValue('CameraTargetz');}"
		}]
		,"up":[ {"x":0.0, "y":"{return getSceneTimeFromStart();}", "z":"{return 2*Math.sin(getSceneTimeFromStart());}"}
		]
				,"position":[
		{"x":"{return Sync.getSyncValue('Camerax');}"
		,"y":"{return Sync.getSyncValue('Cameray');}"
		,"z":"{return Sync.getSyncValue('Cameraz');}"
		}]
	}]);					
				this.loader.addAnimation([
					{
					"start": 48*pattern , "duration": 8*pattern, "object":"data/swordman1.obj"
					,"camera": "Cam02"
					,"layer": 22001
					,"position":[
					{"x":0
					,"y":0
					,"z":0
					}]
					,"angle": [{"degreesX":-90,"degreesY":0,"degreesZ":0}]
			        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}					
					}]);
									this.loader.addAnimation([
					{
					"start": 48*pattern , "duration": 8*pattern, "object":"data/swordman2.obj"
					,"camera": "Cam01"
					,"layer": 22001
						,"angle": [{"degreesX":-90,"degreesY":0,"degreesZ":0}]
			        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}					
					}]);
					

									this.loader.addAnimation([
					{
					"start": 56*pattern , "duration": 8*pattern, "object":"data/badskull.obj"
					,"camera": "Cam02"
					,"layer": 22001
					,"position":[
					{"x":3.5
					,"y":1.2
					,"z":8
					}
					,{"duration":2*pattern,"z":6}]
					,"angle": [{"degreesX":-90,"degreesY":0,"degreesZ":"{return getSceneTimeFromStart()*421}"}]
			        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}					
					}]);

									this.loader.addAnimation([
					{
					"start": 56*pattern , "duration": 8*pattern, "object":"data/sword.obj"
					,"camera": "Cam02"
					,"layer": 22001
					,"scale":[{"x":0.15,"y":0.15,"z":0.15}]
					,"position":[
					{"x":3.5
					,"y":-3.2
					,"z":8
					}
					,{"duration":2*pattern,"z":6}]
					,"angle": [{"degreesX":-90,"degreesY":0,"degreesZ":"{return getSceneTimeFromStart()*421}"}]
			        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}					
					}]);					
/*	
				this.loader.addAnimation([
					{
					"start": 24*pattern , "duration": 8*pattern, "object":"data/ugly_castle2.obj"
					,"camera": "Cam01"
					,"layer": 22001
			        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}					
					}]);
*/
					/*					
for(ii=0;ii<4;ii++)
{
	for(i=0;i<64;i++)
	{
		if(swordSyncPattern[i]==1)
		{
			this.loader.addAnimation([
				{
					"start": 24*pattern+i*tick+ii*pattern*2, "duration": 1*pattern, "object":"data/SWORD.obj"
					,"camera": "Cam02"
					,"layer": 22001
								        ,"shader":{
					"name":["data/shader/heightmap_camera_fsu.fs","data/shader/heightmap_camera_fsu.vs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.5}"]}
					,{"name":"diffuseScrollSpeed","value":[0]}
					,{"name":"displaceAmount","value":["{return Sync.getSyncValue('CastleDisplaceAmount');}"]}
					]
					}
					,"angle": [{"degreesX":70,"degreesY":Math.random()*50-25,"degreesZ":0}]
					,"position":[
					{"x":Math.random()*20.0-10
					,"y":2
					,"z":-20
					}
					,{"duration":pattern,"z":55}]
					,"scale": [
					{"x":.35
					,"y":.35
					,"z":.35
					}]
					}]);
		}
	}	
}
*/		
// this.fullScreenNoise(0,64*pattern,50000,.1);

	this.loader.addAnimation ([
	{
	"start": 0, "duration": 240
	,"layer": 0
	,"fbo":{"name":"fbo0k","action":"begin"}
	},
	{
	"start": 0, "duration": 240
	,"layer": 9999,"fbo":{"name":"fbo0k","action":"unbind"}
	}
	]);

	this.loader.addAnimation ([
	{
	"start": 0, "duration": 240
	,"layer": 10000
	,"fbo":{"name":"fbo10k","action":"begin"}
	},
	{
	"start": 0, "duration": 240
	,"layer": 19999,"fbo":{"name":"fbo10k","action":"unbind"}
	}
	]);

	this.loader.addAnimation ([
	{
	"start": 0, "duration": 240
	,"layer": 20000
	,"fbo":{"name":"fbo20k","action":"begin"}
	},
	{
	"start": 0, "duration": 240
	,"layer": 29999,"fbo":{"name":"fbo20k","action":"unbind"}
	}
	]);

	this.loader.addAnimation ([
	{
	"start": 0, "duration": 240
	,"layer": 30000
	,"fbo":{"name":"fbo10k","action":"begin"}
	},
	{
	"start": 0, "duration": 240
	,"layer": 39999,"fbo":{"name":"fbo30k","action":"unbind"}
	}
	]);	

	this.loader.addAnimation ([
	{
		 "start": 0, "duration": 12*pattern
		,"image": "fbo20k.color.fbo"
		,"layer": 40105

	}]);
		this.loader.addAnimation ([
	{
		 "start": 12*pattern, "duration": 4*pattern
		,"image": "fbo20k.color.fbo"
		,"layer": 40105
				 ,"shader":{
					"name":["data/shader/radialblur2.fs"]
					,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.6}"]}
					]					
					}
	}]);
	
	this.loader.addAnimation ([
	{
		 "start": 24*pattern, "duration": 4*pattern
		,"image": "fbo20k.color.fbo"
		,"layer": 40105
				 ,"shader":{
					"name":["data/shader/radialblur.fs"]
					,"variable":[
					{"name":"time","value":[0.5]}
					]					
					}
	}]);

		this.loader.addAnimation ([
	{
		 "start": 16*pattern, "duration": 8*pattern
		,"image": "fbo20k.color.fbo"
		,"layer": 40105
				 ,"shader":{
					"name":["data/shader/mirrorscroll.fs"]
										,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.0001}"]}
					,{"name":"value1","value":["{return Sync.getSyncValue('Mirror1');}"]}
					,{"name":"value2","value":["{return Sync.getSyncValue('Mirror2');}"]}
					,{"name":"value3","value":["{return Sync.getSyncValue('Mirror3');}"]}
					,{"name":"value4","value":["{return Sync.getSyncValue('Mirror4');}"]}
					]
					}
	}]);

		this.loader.addAnimation ([
	{
		 "start": 24*pattern, "duration": 4*pattern
		,"image": "fbo20k.color.fbo"
		,"layer": 40105

	}]);
	this.loader.addAnimation ([
	{
		 "start": 28*pattern, "duration": 8*pattern
		,"image": "fbo20k.color.fbo"
		,"layer": 40105
		/*
,"shader":{
					"name":["data/shader/mirrorscroll.fs"]
										,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.0001}"]}
					,{"name":"value1","value":["{return Sync.getSyncValue('Mirror1');}"]}
					,{"name":"value2","value":["{return Sync.getSyncValue('Mirror2');}"]}
					,{"name":"value3","value":["{return Sync.getSyncValue('Mirror3');}"]}
					,{"name":"value4","value":["{return Sync.getSyncValue('Mirror4');}"]}
					]
					} */
	}]);	

		this.loader.addAnimation ([
	{
		 "start": 36*pattern, "duration": 4*pattern
		,"image": "fbo20k.color.fbo"
		,"layer": 40105
		/*
				 ,"shader":{
					"name":["data/shader/edgedetect2.fs"]
					,"variable":[
					{"name":"time","value":[0.1]}
					]					
					}
					*/
	}]);
	
		this.loader.addAnimation ([
	{
		 "start": 40*pattern, "duration": 8*pattern
		,"image": "fbo20k.color.fbo"
		,"layer": 40105
		
				 ,"shader":{
					"name":["data/shader/mirrorscroll.fs"]
										,"variable":[
					{"name":"time","value":["{return getSceneTimeFromStart()*.0001}"]}
					,{"name":"value1","value":["{return Sync.getSyncValue('Mirror1');}"]}
					,{"name":"value2","value":["{return Sync.getSyncValue('Mirror2');}"]}
					,{"name":"value3","value":["{return Sync.getSyncValue('Mirror3');}"]}
					,{"name":"value4","value":["{return Sync.getSyncValue('Mirror4');}"]}
					]
					}

	}]);

		this.loader.addAnimation ([
	{
		 "start": 48*pattern, "duration": 16*pattern
		,"image": "fbo20k.color.fbo"
		,"layer": 40105

	}]);	
this.edgeDetect(0*pattern,pattern*64.5,40000,49920,49950);
this.distortion(0,pattern*64.5,49940,49960,50002);
this.brightnessContrast(0,pattern*64.5,50001,50004,50007,0.065,0.11);

this.hackGlow(0,pattern*64,50006,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.2]}
				,{"name":"noiseWaveSpeed","value":[-1]}
				,{"name":"noiseWaveSize","value":[40]}
				,{"name":"noiseLuminance","value":[1]}
				,{"name":"noiseAlpha","value":[0.0]}
				,{"name":"colorComponentDistortionX","value":[0.05,0.01,0.01,0.5]}
				,{"name":"colorComponentDistortionY","value":[0.1,0.01,0.01,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":["{return Sync.getSyncValue('contrastamount');}"]}
	            ]
	        }
	    }
	]);
	
	
}

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*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;}"]}
					
	            ]
	        }
	    }
	]);
}
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;

}
