// LayerChain.jsx
// ©March 2008  Lloyd Alvarez  http://aescripts.com
//
// Takes selected layers and parents each one to the one above.
//
//
// 1.2 Added order preference
// 1.1 Changed parent method to parent from setParentWithJump
// 1.0 Initial Release 03/2008



var proj = app.project;
	var undoStr = "Parent Chain";

	if (proj){
		var myComp = app.project.activeItem;
		if (myComp != null && (myComp instanceof CompItem)){
			app.beginUndoGroup(undoStr);
			
			var topDown = confirm ("Would you like to parent to the layer above? Hitting No will parent to the layer below",false,"Parenting Order");
			
			var myLayers = myComp.selectedLayers;
			
			if (topDown) {
			
			for (i=1; i <= myLayers.length-1; i++){
				
				myLayers[i].parent = myLayers[i-1] ;
				}
			
			} else { //must be bottom up
				
			for (i=0; i < myLayers.length-1; i++){
				
				myLayers[i].parent = myLayers[i+1] ;
				}
				
				}

			
			
			app.endUndoGroup();
		} else {
			alert("Please select an active comp to use this script");
		}
	}
	else
	{
		alert("Please open a project first to use this script.");
	}
