var Scene = (function() {
	var lerp = function(s, e, p) {
		return s - ((s - e) * p);
	}

	return {
		id: getIdForLastLoadedScript(),
		load: function()
		{
			this.frame = 0;
			this.scene = new THREE.Scene();
/*
			var ambient = new THREE.AmbientLight( 0xffffff );
			this.scene.add( ambient );
/*
			var dirLight = new THREE.DirectionalLight( 0xffffff, 0.125 );
			dirLight.position.set( 0, 10, -20 ).normalize();
			dirLight.color.setHSL( 0.1, 0.7, 0.7 );
			this.scene.add( dirLight );
*//*
			var light = new THREE.PointLight( 0xffffff, 1.5, 4500 );
			light.color.setHSL( 0.55, 0.9, 0.5 );
			light.position.set( -10, 10, -10 );
			this.scene.add( light );
*/
			this.axishelper = new THREE.AxisHelper(5);
			this.scene.add(this.axishelper);

			/*
			var light = new THREE.HemisphereLight( 0xffffff, 0x000000, .5 );
			light.position.y = 100;
			this.scene.add( light );
			*/
/*
			this.light2 = new THREE.PointLight(0xffffff, 1, 1000);
			//this.light2.castShadow = true;
			this.light2.position.set(50,50,50);
			this.scene.add(this.light2);
*/

			this.flame = new THREE.Fire();
			this.scene.add(this.flame);
/*
			this.lightSource = new THREE.PointLight( 0xF4D93E, 1, 30 );
			this.lightSource.position.y = 5;
			this.scene.add(this.lightSource);	
*/
			/*
			this.skyGeo = new THREE.SphereGeometry(1000, 30,30);
			this.skyMat = new THREE.MeshBasicMaterial({
				color: 0xd1f2e9,
				side: THREE.DoubleSide
			});
			this.sky = new THREE.Mesh(this.skyGeo, this.skyMat);
			*/
			//this.scene.add(this.sky);

			var mat = new THREE.MeshPhongMaterial({ 
				color: 0xffffff, 
				ambient: 0x111111,
				emissive: 0x000000
			});


			this.test1 = new THREE.Mesh(new THREE.BoxGeometry(100, .1, 100), mat);
			this.scene.add(this.test1);
			/*
			this.test2 = new THREE.Mesh(new THREE.BoxGeometry(10,10,10), mat);
			this.test3 = new THREE.Mesh(new THREE.BoxGeometry(7,7,7), mat);

			this.test2.position.set(10,0,0);
			this.test2.rotation.set(deg2rad(45),deg2rad(45),deg2rad(45));

			this.test3.position.set(0,5,0);
			this.test3.rotation.set(deg2rad(45),deg2rad(45),deg2rad(45));

			this.scene.add(this.test1);
			this.scene.add(this.test2);
			this.scene.add(this.test3);
			*/

			


			this.composer = new THREE.EffectComposer(renderer);

			this.camera = new THREE.PerspectiveCamera(45, 16/9, 1, 300);
			this.camera.position.z = -50;
			this.camera.position.y = 10;
			this.camera.lookAt(new THREE.Vector3(0, 10, 0));

			this.controls = new THREE.OrbitControls( this.camera );
			this.controls.addEventListener('change',render);

			//var material = new THREE.MeshPhongMaterial( { ambient: 0x333333, color: 0xffffff, specular: 0xffffff, shininess: 50 } )
			
			this.renderPass = new THREE.RenderPass(this.scene, this.camera);
			this.composer.addPass(this.renderPass);
/*
			this.blurPass1 = new THREE.ShaderPass(THREE.VerticalBlurShader);
			this.blurPass1.uniforms["v"].value = 1 / wHeight;
			this.composer.addPass(this.blurPass1);

			this.blurPass2 = new THREE.ShaderPass(THREE.HorizontalBlurShader);
			this.blurPass2.uniforms["h"].value = 1 / wWidth;
			this.composer.addPass(this.blurPass2);
*/

/*
			this.depthShader = THREE.ShaderLib[ "depthRGBA" ];
			this.depthUniforms = THREE.UniformsUtils.clone( this.depthShader.uniforms );

			this.depthMaterial = new THREE.ShaderMaterial({
				fragmentShader: this.depthShader.fragmentShader,
				vertexShader: this.depthShader.vertexShader,
				uniforms: this.depthUniforms
			});
			this.depthMaterial.blending = THREE.NoBlending;

			this.depthTarget = new THREE.WebGLRenderTarget( wWidth, wHeight, {
				minFilter: THREE.NearestFilter,
				magFilter: THREE.NearestFilter,
				format: THREE.RGBAFormat
			});
*/

			this.composer.addPass(final_pass);
		},

		render: function(time, percent) 
		{
			this.flame.animate(time);
/*						
			this.controls.update();

			this.scene.overrideMaterial = this.depthMaterial;
			renderer.render( this.scene, this.camera, this.depthTarget );

			this.scene.overrideMaterial = null;
*/			
			this.composer.render();

			
			//this.camera.position.set(Math.sin(time)*25,10,Math.cos(time)*25);
			//this.camera.lookAt(new THREE.Vector3(0,0,0));

		}
	};
})();

var scenes = scenes || [];
scenes[Scene.id] = Scene;

