// Created using compCode v1.0.4
// 20170515 from composition "Pre-comp 1" in project "/p/Projects/_AE Projects/LEARN/CC17_LearnSpringyFX/TutoWater.aep"
//
// aescripts.com/compCode

compCode_20170515_121506();
function compCode_20170515_121506() {

app.beginUndoGroup("Pre-comp 1");

try {

// Create Folder hierarchy
	var solids_folder = getItem("Solids", FolderItem, app.project.rootFolder);
	if (solids_folder === null) {
		solids_folder = app.project.items.addFolder("Solids");
		solids_folder.label = 2;
	}

// Create Compositions
	var precomp1_comp = app.project.items.addComp("Pre-comp 1", 1280, 720, 1, 2.002002002002, 29.9700012207031);
		precomp1_comp.time = 0;
		precomp1_comp.bgColor = [0.97647058823529,0.97647058823529,0.97647058823529];

// Create Solid Layers
	var waterSpringConstraintCtrl_solid = getItem("water - Spring Constraint CTRL", SolidSource,  solids_folder);
	if (waterSpringConstraintCtrl_solid === null) {
		var waterSpringConstraintCtrl_tempSolid = precomp1_comp.layers.addSolid([0.58999997377396,0.66699999570847,0.9559999704361], "water - Spring Constraint CTRL", 1280, 720, 1);
			waterSpringConstraintCtrl_solid = waterSpringConstraintCtrl_tempSolid.source;
			waterSpringConstraintCtrl_solid.label = 1;
			waterSpringConstraintCtrl_solid.parentFolder = solids_folder;
		waterSpringConstraintCtrl_tempSolid.remove();
	}
	var darkGraySolid2_solid = getItem("Dark Gray Solid 2", SolidSource,  solids_folder);
	if (darkGraySolid2_solid === null) {
		var darkGraySolid2_tempSolid = precomp1_comp.layers.addSolid([0.35294100642204,0.35294100642204,0.35294100642204], "Dark Gray Solid 2", 500, 500, 1);
			darkGraySolid2_solid = darkGraySolid2_tempSolid.source;
			darkGraySolid2_solid.label = 1;
			darkGraySolid2_solid.parentFolder = solids_folder;
		darkGraySolid2_tempSolid.remove();
	}
	var royalBlueSolid2_solid = getItem("Royal Blue Solid 2", SolidSource,  solids_folder);
	if (royalBlueSolid2_solid === null) {
		var royalBlueSolid2_tempSolid = precomp1_comp.layers.addSolid([0,0.62782001495361,0.98823499679565], "Royal Blue Solid 2", 500, 200, 1);
			royalBlueSolid2_solid = royalBlueSolid2_tempSolid.source;
			royalBlueSolid2_solid.label = 1;
			royalBlueSolid2_solid.parentFolder = solids_folder;
		royalBlueSolid2_tempSolid.remove();
	}

// Working with comp "Pre-comp 1", varName "precomp1_comp";
	precomp1_comp.openInViewer();
	// Add existing Solid Layer "water - Spring Constraint CTRL", varName "waterSpringConstraintCtrl_solid";
	var waterSpringConstraintCtrl = precomp1_comp.layers.add(waterSpringConstraintCtrl_solid);
		waterSpringConstraintCtrl.label = 5;
		waterSpringConstraintCtrl.enabled = false;
		waterSpringConstraintCtrl.moveToEnd();
		waterSpringConstraintCtrl.property("ADBE Effect Parade").addProperty("Pseudo/SpringConstraintCTRL");
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0005").setValue(0);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0009").setValue([640,360]);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0010").setValue(0);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0013").setValue(100);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0014").setValue(100);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0015").setValue(100);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0018").setValue(0);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0019").setValue(0);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0020").setValue(0);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0024").setValue(9);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0025").setValue(1);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").addProperty("ADBE Angle Control");
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(2).name = "Liquid Rotation MAX";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(2).property("ADBE Angle Control-0001").setValue(60);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").addProperty("ADBE Angle Control");
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(3).name = "Liquid Twist MAX";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(3).property("ADBE Angle Control-0001").setValue(71);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").addProperty("ADBE Slider Control");
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(4).name = "Liquid Waves Amp MAX";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(4).property("ADBE Slider Control-0001").setValue(90);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").addProperty("ADBE Slider Control");
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(5).name = "Liquid Waves Size MAX";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(5).property("ADBE Slider Control-0001").setValue(43);
		waterSpringConstraintCtrl.property("ADBE Effect Parade").addProperty("ADBE Slider Control");
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(6).name = "Liquid Level";
		var waterSpringConstraintCtrlSlider = waterSpringConstraintCtrl.property("ADBE Effect Parade").property(6).property("ADBE Slider Control-0001");
			var waterSpringConstraintCtrlSlider_keyTimesArray = [1.7017017017017,1.76843510176844];
			var waterSpringConstraintCtrlSlider_valuesArray = [-1,-100];
			waterSpringConstraintCtrlSlider.setValuesAtTimes(waterSpringConstraintCtrlSlider_keyTimesArray, waterSpringConstraintCtrlSlider_valuesArray);
		waterSpringConstraintCtrl.property("ADBE Transform Group").property("ADBE Position").setValue([640,360,0]);
		waterSpringConstraintCtrl.property("ADBE Transform Group").property("ADBE Scale").setValue([100,100,100]);
		waterSpringConstraintCtrl.property("ADBE Transform Group").property("ADBE Rotate Z").setValue(0);
		waterSpringConstraintCtrl.property("ADBE Transform Group").property("ADBE Opacity").setValue(0);
	// Add existing Solid Layer "Dark Gray Solid 2", varName "darkGraySolid2_solid";
	var bottle2 = precomp1_comp.layers.add(darkGraySolid2_solid);
		bottle2.name = "bottle 2";
		bottle2.enabled = false;
		bottle2.moveToEnd();
		bottle2.property("ADBE Mask Parade").addProperty("ADBE Mask Atom");
		bottle2.property("ADBE Mask Parade").property(1).color = [0.95686274509804,0.42745098039216,0.83921568627451];
		var bottle2MaskPath = bottle2.property("ADBE Mask Parade").property(1).property("ADBE Mask Shape");
		var bottle2MaskPath_shapeVertices = [[276,88],[175,88],[176,114],[171.999984741211,259],[69,426],[382,432],[287,258],[280,123]];
		var bottle2MaskPath_shapeInTangets = [[27,17],[0,0],[-19.9999694824219,-12],[0,0],[-33,-18],[-15,31],[10,6.00003051757813],[0,0]];
		var bottle2MaskPath_shapeOutTangets = [[-27,-17],[0,0],[20,12],[0,0],[33,18],[15,-31],[-10,-6],[0,0]];
		var bottle2MaskPath_shapeClosed = true;
		createStaticShape(bottle2MaskPath, bottle2MaskPath_shapeVertices, bottle2MaskPath_shapeInTangets, bottle2MaskPath_shapeOutTangets, bottle2MaskPath_shapeClosed);
		bottle2.property("ADBE Transform Group").property("ADBE Position").setValue([250,250,0]);
		bottle2.property("ADBE Transform Group").property("ADBE Scale").setValue([100,100,100]);
	// Add existing Solid Layer "Royal Blue Solid 2", varName "royalBlueSolid2_solid";
	var water = precomp1_comp.layers.add(royalBlueSolid2_solid);
		water.name = "water";
		water.moveToEnd();
		water.trackMatteType = TrackMatteType.ALPHA;
		water.property("ADBE Effect Parade").addProperty("Pseudo/SpringyDeformersCTRL");
		water.property("ADBE Effect Parade").property(1).property("Pseudo/SpringyDeformersCTRL-0001").setValue(1);
		water.property("ADBE Effect Parade").property(1).property("Pseudo/SpringyDeformersCTRL-0003").setValue(500);
		water.property("ADBE Effect Parade").property(1).property("Pseudo/SpringyDeformersCTRL-0004").setValue(200);
		water.property("ADBE Effect Parade").addProperty("ADBE GROW BOUNDS");
		water.property("ADBE Effect Parade").property(2).name = "Liquid Grow bounds";
		water.property("ADBE Effect Parade").property(2).property("ADBE GROW BOUNDS-0001").setValue(1280);
		water.property("ADBE Effect Parade").addProperty("ADBE Geometry2");
		water.property("ADBE Effect Parade").property(3).name = "Liquid Rotation PX";
		water.property("ADBE Effect Parade").property(3).property("ADBE Geometry2-0001").setValue([250,0]);
		water.property("ADBE Effect Parade").property(3).property("ADBE Geometry2-0002").setValue([250,0]);
		water.property("ADBE Effect Parade").property(3).property("ADBE Geometry2-0007").setValue(0);
		water.property("ADBE Effect Parade").addProperty("ADBE Twirl");
		water.property("ADBE Effect Parade").property(4).name = "Liquid Twist R";
		water.property("ADBE Effect Parade").property(4).property("ADBE Twirl-0001").setValue(-3);
		water.property("ADBE Effect Parade").property(4).property("ADBE Twirl-0002").setValue(35);
		water.property("ADBE Effect Parade").property(4).property("ADBE Twirl-0003").setValue([125,133.333333333333]);
		water.property("ADBE Effect Parade").addProperty("ADBE Turbulent Displace");
		water.property("ADBE Effect Parade").property(5).name = "Liquid Waves PX";
		water.property("ADBE Effect Parade").property(5).property("ADBE Turbulent Displace-0001").setValue(5);
		water.property("ADBE Effect Parade").property(5).property("ADBE Turbulent Displace-0002").setValue(150);
		water.property("ADBE Effect Parade").property(5).property("ADBE Turbulent Displace-0003").setValue(25);
		water.property("ADBE Effect Parade").property(5).property("ADBE Turbulent Displace-0004").setValue([780,160.666666666667]);
		water.property("ADBE Effect Parade").property(5).property("ADBE Turbulent Displace-0006").setValue(0);
		water.property("ADBE Effect Parade").addProperty("ADBE Ripple");
		water.property("ADBE Effect Parade").property(6).name = "Liquid Waves PY";
		water.property("ADBE Effect Parade").property(6).property("ADBE Ripple-0001").setValue(100);
		water.property("ADBE Effect Parade").property(6).property("ADBE Ripple-0002").setValue([249.410377358491,0]);
		water.property("ADBE Effect Parade").property(6).property("ADBE Ripple-0005").setValue(44);
		water.property("ADBE Effect Parade").property(6).property("ADBE Ripple-0006").setValue(50);
		water.property("ADBE Effect Parade").property(6).property("ADBE Ripple-0007").setValue(0);
		water.property("ADBE Effect Parade").addProperty("ADBE Turbulent Displace");
		water.property("ADBE Effect Parade").property(7).name = "Liquid Waves R";
		water.property("ADBE Effect Parade").property(7).property("ADBE Turbulent Displace-0001").setValue(5);
		water.property("ADBE Effect Parade").property(7).property("ADBE Turbulent Displace-0002").setValue(150);
		water.property("ADBE Effect Parade").property(7).property("ADBE Turbulent Displace-0003").setValue(25);
		water.property("ADBE Effect Parade").property(7).property("ADBE Turbulent Displace-0004").setValue([780,160.666666666667]);
		water.property("ADBE Effect Parade").property(7).property("ADBE Turbulent Displace-0006").setValue(0);
		water.property("ADBE Effect Parade").addProperty("ADBE Tile");
		water.property("ADBE Effect Parade").property(8).name = "Liquid Level";
		water.property("ADBE Effect Parade").property(8).property("ADBE Tile-0001").setValue([250,99.4666666666667]);
		water.property("ADBE Transform Group").property("ADBE Anchor Point").setValue([250,0,0]);
		var waterPosition = water.property("ADBE Transform Group").property("ADBE Position");
			var waterPosition_keyTimesArray = [0.06673340006673,0.26693360026693,0.5005005005005,0.7007007007007,0.96763430096763,1.2012012012012];
			var waterPosition_valuesArray = [[422,449,0],[693,449,0],[317,449,0],[317,395,0],[317,591,0],[718,531,0]];
			waterPosition.setValuesAtTimes(waterPosition_keyTimesArray, waterPosition_valuesArray);
			var waterPosition_inSpatialTangents = [[-45.1666679382324,0,0],[17.5,0,0],[62.6666679382324,9,0],[0,-23.6666660308838,0],[-66.8333358764648,-22.6666660308838,0],[-66.8333358764648,10,0]];
			var waterPosition_outSpatialTangents = [[45.1666679382324,0,0],[-17.5,0,0],[-62.6666679382324,-9,0],[0,23.6666660308838,0],[66.8333358764648,22.6666660308838,0],[66.8333358764648,-10,0]];
			applySpatialTangents(waterPosition, waterPosition_keyTimesArray, waterPosition_inSpatialTangents, waterPosition_outSpatialTangents);
		var waterRotation = water.property("ADBE Transform Group").property("ADBE Rotate Z");
			var waterRotation_keyTimesArray = [0.2002002002002,0.5005005005005,1.7017017017017];
			var waterRotation_valuesArray = [61,-31,-4];
			waterRotation.setValuesAtTimes(waterRotation_keyTimesArray, waterRotation_valuesArray);
	// Add existing Solid Layer "Dark Gray Solid 2", varName "darkGraySolid2_solid";
	var bottle = precomp1_comp.layers.add(darkGraySolid2_solid);
		bottle.name = "bottle";
		bottle.moveToEnd();
		bottle.property("ADBE Mask Parade").addProperty("ADBE Mask Atom");
		bottle.property("ADBE Mask Parade").property(1).color = [0.95686274509804,0.42745098039216,0.83921568627451];
		var bottleMaskPath = bottle.property("ADBE Mask Parade").property(1).property("ADBE Mask Shape");
		var bottleMaskPath_shapeVertices = [[276,88],[175,88],[176,114],[171.999984741211,259],[69,426],[382,432],[287,258],[280,123]];
		var bottleMaskPath_shapeInTangets = [[27,17],[0,0],[-19.9999694824219,-12],[0,0],[-33,-18],[-15,31],[10,6.00003051757813],[0,0]];
		var bottleMaskPath_shapeOutTangets = [[-27,-17],[0,0],[20,12],[0,0],[33,18],[15,-31],[-10,-6],[0,0]];
		var bottleMaskPath_shapeClosed = true;
		createStaticShape(bottleMaskPath, bottleMaskPath_shapeVertices, bottleMaskPath_shapeInTangets, bottleMaskPath_shapeOutTangets, bottleMaskPath_shapeClosed);
		bottle.property("ADBE Transform Group").property("ADBE Position").setValue([260,-52,0]);
		bottle.property("ADBE Transform Group").property("ADBE Scale").setValue([70.7482993197279,70.7482993197279,100]);


	// Apply outOfRange values
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0001").setValue(3);

	// Apply parents
		bottle2.setParentWithJump(bottle);
		bottle.setParentWithJump(water);



	// Apply expressions to properties
	try {
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0009").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"drag=10-effect(\"Spring Constraint CTRL\")(\"Damping\");" + "\n" + 
				"stiffness=10-effect(\"Spring Constraint CTRL\")(\"Elasticity\");" + "\n" + 
				"try {matrix=thisComp.layer(effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\").name);} catch(err) {matrix=thisLayer;}" + "\n" + 
				"initVal=matrix.position;" + "\n" + 
				"newVal=matrix.position;" + "\n" + 
				"v=0;" + "\n" + 
				"i=0;" + "\n" + 
				"while (i<=(time-effect(\"Spring Constraint CTRL\")(\"Pseudo/SpringConstraintCTRL-0026\")) && effect(\"Spring Constraint CTRL\")(\"Use Position\")==1){" + "\n" + 
				"initVal=matrix.position.valueAtTime(i);" + "\n" + 
				"delta=sub(initVal,newVal);" + "\n" + 
				"a=delta*thisComp.frameDuration*drag;" + "\n" + 
				"v=(v+a)*((10-stiffness)/10);" + "\n" + 
				"newVal += v;" + "\n" + 
				"i += thisComp.frameDuration;" + "\n" + 
				"}" + "\n" + 
				"newVal";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0010").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"drag=10-effect(\"Spring Constraint CTRL\")(\"Damping\");" + "\n" + 
				"stiffness=10-effect(\"Spring Constraint CTRL\")(\"Elasticity\");" + "\n" + 
				"try {matrix=thisComp.layer(effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\").name);} catch(err) {matrix=thisLayer;}" + "\n" + 
				"try {" + "\n" + 
				"initVal=matrix.position;" + "\n" + 
				"newVal=matrix.position;" + "\n" + 
				"v=0;" + "\n" + 
				"i=0;" + "\n" + 
				"while (i<=(time-effect(\"Spring Constraint CTRL\")(\"Pseudo/SpringConstraintCTRL-0026\")) && effect(\"Spring Constraint CTRL\")(\"Use Position\")==1)" + "\n" + 
				"{" + "\n" + 
				"initVal=matrix.position.valueAtTime(i);" + "\n" + 
				"delta=sub(initVal,newVal);" + "\n" + 
				"a=delta*thisComp.frameDuration*drag;" + "\n" + 
				"v=(v+a)*((10-stiffness)/10);" + "\n" + 
				"newVal += v;" + "\n" + 
				"i += thisComp.frameDuration;" + "\n" + 
				"}" + "\n" + 
				"newVal[2]" + "\n" + 
				"} catch(err) {0}";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0013").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"drag=10-effect(\"Spring Constraint CTRL\")(\"Damping\");" + "\n" + 
				"stiffness=10-effect(\"Spring Constraint CTRL\")(\"Elasticity\");" + "\n" + 
				"try {matrix=thisComp.layer(effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\").name);} catch(err) {matrix=thisLayer;}" + "\n" + 
				"initVal=matrix.scale;" + "\n" + 
				"newVal=matrix.scale;" + "\n" + 
				"v=0;" + "\n" + 
				"i=0;" + "\n" + 
				"while (i<=(time-effect(\"Spring Constraint CTRL\")(\"Pseudo/SpringConstraintCTRL-0026\")) && effect(\"Spring Constraint CTRL\")(\"Use Scale\")==1)" + "\n" + 
				"{" + "\n" + 
				"initVal=matrix.scale.valueAtTime(i);" + "\n" + 
				"delta=sub(initVal,newVal);" + "\n" + 
				"a=delta*thisComp.frameDuration*drag;" + "\n" + 
				"v=(v+a)*((10-stiffness)/10);" + "\n" + 
				"newVal += v;" + "\n" + 
				"i += thisComp.frameDuration;" + "\n" + 
				"}" + "\n" + 
				"newVal[0]";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0014").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"drag=10-effect(\"Spring Constraint CTRL\")(\"Damping\");" + "\n" + 
				"stiffness=10-effect(\"Spring Constraint CTRL\")(\"Elasticity\");" + "\n" + 
				"try {matrix=thisComp.layer(effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\").name);} catch(err) {matrix=thisLayer;}" + "\n" + 
				"initVal=matrix.scale;" + "\n" + 
				"newVal=matrix.scale;" + "\n" + 
				"v=0;" + "\n" + 
				"i=0;" + "\n" + 
				"while (i<=(time-effect(\"Spring Constraint CTRL\")(\"Pseudo/SpringConstraintCTRL-0026\")) && effect(\"Spring Constraint CTRL\")(\"Use Scale\")==1)" + "\n" + 
				"{" + "\n" + 
				"initVal=matrix.scale.valueAtTime(i);" + "\n" + 
				"delta=sub(initVal,newVal);" + "\n" + 
				"a=delta*thisComp.frameDuration*drag;" + "\n" + 
				"v=(v+a)*((10-stiffness)/10);" + "\n" + 
				"newVal += v;" + "\n" + 
				"i += thisComp.frameDuration;" + "\n" + 
				"}" + "\n" + 
				"newVal[1]";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0015").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"drag=10-effect(\"Spring Constraint CTRL\")(\"Damping\");" + "\n" + 
				"stiffness=10-effect(\"Spring Constraint CTRL\")(\"Elasticity\");" + "\n" + 
				"try {matrix=thisComp.layer(effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\").name);} catch(err) {matrix=thisLayer;}" + "\n" + 
				"try {" + "\n" + 
				"initVal=matrix.scale;" + "\n" + 
				"newVal=matrix.scale;" + "\n" + 
				"v=0;" + "\n" + 
				"i=0;" + "\n" + 
				"while (i<=(time-effect(\"Spring Constraint CTRL\")(\"Pseudo/SpringConstraintCTRL-0026\")) && effect(\"Spring Constraint CTRL\")(\"Use Scale\")==1)" + "\n" + 
				"{" + "\n" + 
				"initVal=matrix.scale.valueAtTime(i);" + "\n" + 
				"delta=sub(initVal,newVal);" + "\n" + 
				"a=delta*thisComp.frameDuration*drag;" + "\n" + 
				"v=(v+a)*((10-stiffness)/10);" + "\n" + 
				"newVal += v;" + "\n" + 
				"i += thisComp.frameDuration;" + "\n" + 
				"}" + "\n" + 
				"newVal[2]" + "\n" + 
				"} catch(err) {100}";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0018").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"drag=10-effect(\"Spring Constraint CTRL\")(\"Damping\");" + "\n" + 
				"stiffness=10-effect(\"Spring Constraint CTRL\")(\"Elasticity\");" + "\n" + 
				"try {matrix=thisComp.layer(effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\").name);} catch(err) {matrix=thisLayer;}" + "\n" + 
				"try {" + "\n" + 
				"initVal=matrix(\"ADBE Transform Group\")(\"ADBE Rotate X\");" + "\n" + 
				"newVal=matrix(\"ADBE Transform Group\")(\"ADBE Rotate X\");" + "\n" + 
				"v=0;" + "\n" + 
				"i=0;" + "\n" + 
				"while (i<=time && effect(\"Spring Constraint CTRL\")(\"Use Rotation\")==1)" + "\n" + 
				"{" + "\n" + 
				"initVal=matrix(\"ADBE Transform Group\")(\"ADBE Rotate X\").valueAtTime(i);" + "\n" + 
				"delta=sub(initVal,newVal);" + "\n" + 
				"a=delta*thisComp.frameDuration*drag;" + "\n" + 
				"v=(v+a)*((10-stiffness)/10);" + "\n" + 
				"newVal += v;" + "\n" + 
				"i += thisComp.frameDuration;" + "\n" + 
				"}" + "\n" + 
				"newVal" + "\n" + 
				"} catch(err) {0}";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0019").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"drag=10-effect(\"Spring Constraint CTRL\")(\"Damping\");" + "\n" + 
				"stiffness=10-effect(\"Spring Constraint CTRL\")(\"Elasticity\");" + "\n" + 
				"try {matrix=thisComp.layer(effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\").name);} catch(err) {matrix=thisLayer;}" + "\n" + 
				"try {" + "\n" + 
				"initVal=matrix(\"ADBE Transform Group\")(\"ADBE Rotate Y\");" + "\n" + 
				"newVal=matrix(\"ADBE Transform Group\")(\"ADBE Rotate Y\");" + "\n" + 
				"v=0;" + "\n" + 
				"i=0;" + "\n" + 
				"while (i<=time && effect(\"Spring Constraint CTRL\")(\"Use Rotation\")==1)" + "\n" + 
				"{" + "\n" + 
				"initVal=matrix(\"ADBE Transform Group\")(\"ADBE Rotate Y\").valueAtTime(i);" + "\n" + 
				"delta=sub(initVal,newVal);" + "\n" + 
				"a=delta*thisComp.frameDuration*drag;" + "\n" + 
				"v=(v+a)*((10-stiffness)/10);" + "\n" + 
				"newVal += v;" + "\n" + 
				"i += thisComp.frameDuration;" + "\n" + 
				"}" + "\n" + 
				"newVal" + "\n" + 
				"} catch(err) {0}";
		waterSpringConstraintCtrl.property("ADBE Effect Parade").property(1).property("Pseudo/SpringConstraintCTRL-0020").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"drag=10-effect(\"Spring Constraint CTRL\")(\"Damping\");" + "\n" + 
				"stiffness=10-effect(\"Spring Constraint CTRL\")(\"Elasticity\");" + "\n" + 
				"try {matrix=thisComp.layer(effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\").name);} catch(err) {matrix=thisLayer;}" + "\n" + 
				"initVal=matrix(\"ADBE Transform Group\")(\"ADBE Rotate Z\");" + "\n" + 
				"newVal=matrix(\"ADBE Transform Group\")(\"ADBE Rotate Z\")" + "\n" + 
				"v=0;" + "\n" + 
				"i=0;" + "\n" + 
				"while (i<=time && effect(\"Spring Constraint CTRL\")(\"Use Rotation\")==1)" + "\n" + 
				"{" + "\n" + 
				"initVal=matrix(\"ADBE Transform Group\")(\"ADBE Rotate Z\").valueAtTime(i);" + "\n" + 
				"delta=sub(initVal,newVal);" + "\n" + 
				"a=delta*thisComp.frameDuration*drag;" + "\n" + 
				"v=(v+a)*((10-stiffness)/10);" + "\n" + 
				"newVal += v;" + "\n" + 
				"i += thisComp.frameDuration;" + "\n" + 
				"}" + "\n" + 
				"newVal";
		waterSpringConstraintCtrl.property("ADBE Transform Group").property("ADBE Position").expression = "[thisComp.width/2,thisComp.height/2]";
		waterSpringConstraintCtrl.property("ADBE Transform Group").property("ADBE Scale").expression = "[100,100]";
		waterSpringConstraintCtrl.property("ADBE Transform Group").property("ADBE Rotate Z").expression = "0";
		water.property("ADBE Effect Parade").property(2).property("ADBE GROW BOUNDS-0001").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"(effect(\"Springy Deformers CTRL\")(\"Source Size X\")+effect(\"Springy Deformers CTRL\")(\"Source Size Y\"))/2";
		water.property("ADBE Effect Parade").property(3).property("ADBE Geometry2-0001").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"transform.anchorPoint";
		water.property("ADBE Effect Parade").property(3).property("ADBE Geometry2-0002").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"transform.anchorPoint";
		water.property("ADBE Effect Parade").property(3).property("ADBE Geometry2-0007").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"springLayerName=effect(\"Springy Deformers CTRL\")(\"Spring Constraint Layer\").name;" + "\n" + 
				"baseLayer=thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\");" + "\n" + 
				"springAmount=thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Springy Position XY\")[0]-baseLayer.position[0];" + "\n" + 
				"MinInput=-360;" + "\n" + 
				"MaxInput=360;" + "\n" + 
				"MinOutput=-thisComp.layer(springLayerName).effect(\"Liquid Rotation MAX\")(1);" + "\n" + 
				"MaxOutput=thisComp.layer(springLayerName).effect(\"Liquid Rotation MAX\")(1);" + "\n" + 
				"if(Math.abs(springAmount)>0.1)" + "\n" + 
				"{linear(springAmount,MinInput, MaxInput, MinOutput, MaxOutput)-transform.rotation;}" + "\n" + 
				"else" + "\n" + 
				"{-transform.rotation}";
		water.property("ADBE Effect Parade").property(4).property("ADBE Twirl-0001").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"springLayerName=effect(\"Springy Deformers CTRL\")(\"Spring Constraint Layer\").name;" + "\n" + 
				"baseLayer=thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\");" + "\n" + 
				"springAmount=-thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Springy Rotation Z\")+baseLayer.rotation;" + "\n" + 
				"MinInput=-360;" + "\n" + 
				"MaxInput=360;" + "\n" + 
				"MinOutput=-thisComp.layer(springLayerName).effect(\"Liquid Twist MAX\")(1)*10;" + "\n" + 
				"MaxOutput=thisComp.layer(springLayerName).effect(\"Liquid Twist MAX\")(1)*10;" + "\n" + 
				"if(Math.abs(springAmount)>0.1)" + "\n" + 
				"{linear(springAmount,MinInput, MaxInput, MinOutput, MaxOutput);}" + "\n" + 
				"else" + "\n" + 
				"{0}";
		water.property("ADBE Effect Parade").property(4).property("ADBE Twirl-0002").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"(effect(\"Springy Deformers CTRL\")(\"Source Size X\")+effect(\"Springy Deformers CTRL\")(\"Source Size Y\"))/8";
		water.property("ADBE Effect Parade").property(4).property("ADBE Twirl-0003").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"transform.anchorPoint";
		water.property("ADBE Effect Parade").property(5).property("ADBE Turbulent Displace-0002").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"springLayerName=effect(\"Springy Deformers CTRL\")(\"Spring Constraint Layer\").name;" + "\n" + 
				"baseLayer=thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\");" + "\n" + 
				"springAmount=thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Springy Position XY\")[0]-baseLayer.position[0];" + "\n" + 
				"MinInput=-thisComp.width/4;" + "\n" + 
				"MaxInput=thisComp.width/4;" + "\n" + 
				"MinOutput=-thisComp.layer(springLayerName).effect(\"Liquid Waves Amp MAX\")(1);" + "\n" + 
				"MaxOutput=thisComp.layer(springLayerName).effect(\"Liquid Waves Amp MAX\")(1);" + "\n" + 
				"if(Math.abs(springAmount)>0.1)" + "\n" + 
				"{linear(springAmount,MinInput, MaxInput, MinOutput, MaxOutput);}" + "\n" + 
				"else" + "\n" + 
				"{0}";
		water.property("ADBE Effect Parade").property(5).property("ADBE Turbulent Displace-0003").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"springLayerName=effect(\"Springy Deformers CTRL\")(\"Spring Constraint Layer\").name;" + "\n" + 
				"thisComp.layer(springLayerName).effect(\"Liquid Waves Size MAX\")(1);";
		water.property("ADBE Effect Parade").property(5).property("ADBE Turbulent Displace-0004").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"transform.anchorPoint";
		water.property("ADBE Effect Parade").property(5).property("ADBE Turbulent Displace-0006").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"position.velocityAtTime( time )[0]/10+time*250;";
		water.property("ADBE Effect Parade").property(6).property("ADBE Ripple-0002").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"[transform.anchorPoint[0],0]";
		water.property("ADBE Effect Parade").property(6).property("ADBE Ripple-0005").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"springLayerName=effect(\"Springy Deformers CTRL\")(\"Spring Constraint Layer\").name;" + "\n" + 
				"thisComp.layer(springLayerName).effect(\"Liquid Waves Size MAX\")(1);";
		water.property("ADBE Effect Parade").property(6).property("ADBE Ripple-0006").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"springLayerName=effect(\"Springy Deformers CTRL\")(\"Spring Constraint Layer\").name;" + "\n" + 
				"baseLayer=thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\");" + "\n" + 
				"springAmount=Math.abs(thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Springy Position XY\")[1]-baseLayer.position[1]);" + "\n" + 
				"MinInput=-thisComp.width/4;" + "\n" + 
				"MaxInput=thisComp.width/4;" + "\n" + 
				"MinOutput=-thisComp.layer(springLayerName).effect(\"Liquid Waves Amp MAX\")(1);" + "\n" + 
				"MaxOutput=thisComp.layer(springLayerName).effect(\"Liquid Waves Amp MAX\")(1);" + "\n" + 
				"if(Math.abs(springAmount)>0.1)" + "\n" + 
				"{linear(springAmount,MinInput, MaxInput, MinOutput, MaxOutput);}" + "\n" + 
				"else" + "\n" + 
				"{0}";
		water.property("ADBE Effect Parade").property(6).property("ADBE Ripple-0007").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"position.velocityAtTime( time )[0]/10+time*250;";
		water.property("ADBE Effect Parade").property(7).property("ADBE Turbulent Displace-0002").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"springLayerName=effect(\"Springy Deformers CTRL\")(\"Spring Constraint Layer\").name;" + "\n" + 
				"baseLayer=thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Inherit Motion From\");" + "\n" + 
				"springAmount=-thisComp.layer(springLayerName).effect(\"Spring Constraint CTRL\")(\"Springy Rotation Z\")+baseLayer.rotation;" + "\n" + 
				"MinInput=-360;" + "\n" + 
				"MaxInput=360;" + "\n" + 
				"MinOutput=-thisComp.layer(springLayerName).effect(\"Liquid Waves Amp MAX\")(1)*10;" + "\n" + 
				"MaxOutput=thisComp.layer(springLayerName).effect(\"Liquid Waves Amp MAX\")(1)*10;" + "\n" + 
				"if(Math.abs(springAmount)>0.1)" + "\n" + 
				"{linear(springAmount,MinInput, MaxInput, MinOutput, MaxOutput);}" + "\n" + 
				"else" + "\n" + 
				"{0}";
		water.property("ADBE Effect Parade").property(7).property("ADBE Turbulent Displace-0003").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"" + "\n" + 
				"springLayerName=effect(\"Springy Deformers CTRL\")(\"Spring Constraint Layer\").name;" + "\n" + 
				"thisComp.layer(springLayerName).effect(\"Liquid Waves Size MAX\")(1);";
		water.property("ADBE Effect Parade").property(7).property("ADBE Turbulent Displace-0004").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"transform.anchorPoint";
		water.property("ADBE Effect Parade").property(7).property("ADBE Turbulent Displace-0006").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"position.velocityAtTime( time )[0]/10+time*250;";
		water.property("ADBE Effect Parade").property(8).property("ADBE Tile-0001").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe" + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				"springLayerName=effect(\"Springy Deformers CTRL\")(\"Spring Constraint Layer\").name;" + "\n" + 
				"[effect(\"Springy Deformers CTRL\")(\"Source Size X\")/2,effect(\"Springy Deformers CTRL\")(\"Source Size Y\")/2+thisComp.layer(springLayerName).effect(\"Liquid Level\")(1)]";
		water.property("ADBE Transform Group").property("ADBE Position").expression = "// Springy FX - created by Matthieu Fremeaux (aka FREMOX) from MotionCafe " + "\n" + 
				"// more informations on motion-cafe.com and aescripts.com" + "\n" + 
				" [value[0],transform.anchorPoint[1]+value[1]-effect(\'Springy Deformers CTRL\')(4)/2]";
	} catch (err) {}

precomp1_comp.openInViewer();
} catch(e) {
	alert(e.toString() + "\nError on line: " + e.line.toString());
}
app.endUndoGroup();


function getItem(itemName, itemInstanceName, locationObject) {
	if (locationObject.numItems > 0) {
		for (var i = 1; i <= locationObject.numItems; i ++) {
			var curItem = locationObject.item(i);
			if (curItem.name === itemName) {
				if (curItem instanceof itemInstanceName || (curItem.mainSource !== "undefined" && curItem.mainSource instanceof itemInstanceName)) {
					return curItem;
				}
			}
		}
	}
	return null;
}

function applySpatialTangents(property, keyTimesArray, inSpatialTangentsArray, outSpatialTangentsArray) {
	for (var sp = 0; sp < keyTimesArray.length; sp ++) {
		property.setSpatialTangentsAtKey(sp+1, inSpatialTangentsArray[sp], outSpatialTangentsArray[sp]);
	}
}
function createStaticShape(path, vertexArray, inTangentsArray, outTangentsArray, closed) {
	var pathValue = path.value;
		pathValue.vertices = vertexArray;
		pathValue.inTangents = inTangentsArray;
		pathValue.outTangents = outTangentsArray;
		pathValue.closed = closed;
	path.setValue(pathValue);
}
}

