global proc AEHydraTemplate( string $nodeName )
{
	editorTemplate -beginScrollLayout;
	
		// The all go into the collapsable "Parameters" section
		editorTemplate -beginLayout "Overall" -collapse false;

			// Add the default controls
			// editorTemplate -addControl "number";
			editorTemplate -addControl "radius";
			editorTemplate -addControl "ftOrder";
			editorTemplate -addControl "softInsert";
			editorTemplate -addControl "setNodeGrowth";
			editorTemplate -addControl "evaluation";
			
		editorTemplate -endLayout;
		
		editorTemplate -beginLayout "Multiplication" -collapse true;
		
			editorTemplate -beginNoOptimize;
		
			editorTemplate -addControl "updateTesselatedMesh";
			editorTemplate -addControl "updateTextures";
			editorTemplate -addControl "updateMultipliedTransforms";
			
			editorTemplate -addControl "number" "XFUpdateObject ";
			
			editorTemplate -addSeparator;
			
			editorTemplate -endNoOptimize;
				
			//Add the default controls for the Multiplication-Handling
			string $newFuncAttrib = "hydraMultNewAttrib";
			string $replaceFuncAttrib = "hydraMultReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "";
								
		editorTemplate -endLayout;

		editorTemplate -beginLayout "Standard Curve Parameters" -collapse false;
					
			//Add the default controls for the CurveParameters
			string $newFuncAttrib = "hydraCurvNewAttrib";
			string $replaceFuncAttrib = "hydraCurvReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "";
		
		editorTemplate -endLayout;
		
		/*editorTemplate -beginLayout "Extra Curve Parameters - not yet implemented" -collapse true;
							
			//Add the default controls for the ExtraCurveParameters
			//string $newFuncAttrib = "hydraExtraNewAttrib";
			//string $replaceFuncAttrib = "hydraExtraReplaceAttrib";
			//editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "";
				
		editorTemplate -endLayout;*/
		
		editorTemplate -beginLayout "Family" -collapse false;
		
			//Add the default controls for the Family-Members-Handling
			string $newFuncAttrib = "hydraFamilyNewAttrib";
			string $replaceFuncAttrib = "hydraFamilyReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "";	
						
		editorTemplate -endLayout;
		
		editorTemplate -beginLayout "Xfrog HD" -collapse true;
		
			editorTemplate -addControl "singleEvaluation";
				
			//Add the default controls for the Alternates-Handling
			string $newFuncAttrib = "hydraAlternateNewAttrib";
			string $replaceFuncAttrib = "hydraAlternateReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "clearMeshOrLink";	
								
		editorTemplate -endLayout;
		

		// Create an "Extras" section and also add controls for any
		// attributes we have not explicitly mentioned.
		editorTemplate -addExtraControls;
	editorTemplate -endScrollLayout;

	// Tell the attribute editor not to display the attributes we
	// don't care about.
	editorTemplate -suppress "caching";
	editorTemplate -suppress "nodeState";
}

global proc hydraMultNewAttrib(string $attr)
{
	hydraMultReplaceAttrib($attr);
}

global proc hydraMultReplaceAttrib(string $attr)
{
	$type = `nodeType ($attr+"number")`;
	int $end   = `size($attr)`-1;
	$node = `substring $attr 1 $end`;

	if(!`layout -exists ($type+"_multiplication_layout")`) columnLayout ($type+"_multiplication_layout");
	setParent ($type+"_multiplication_layout");

	setParent ($type+"_multiplication_layout");
	if(!`layout -exists ($type+"_multiplication_type_layout")`) rowLayout -nc 3 ($type+"_multiplication_type_layout");
	if(!`text -exists ($type+"_multiplication_type_text")`){
		setParent ($type+"_multiplication_type_layout");
		text -label ("Multiplication Type") ($type+"_multiplication_type_text");
	}
	if(!`optionMenu -exists ($type+"_multiplication_type_menu")`){
		setParent ($type+"_multiplication_type_layout");
		optionMenu ($type+"_multiplication_type_menu");
			menuItem -data 1 -label "Tesselated Mesh";
			menuItem -data 2 -label "Instance";
			menuItem -data 3 -label "Copy";
	}
	optionMenu -e -select (`getAttr ($node+".multiplyType")`+1) ($type+"_multiplication_type_menu");
		
	setParent ($type+"_multiplication_layout");
	if(!`separator -exists ($type+"_multiplication_separator2")`) 
	separator -h 10 -style "none" ($type+"_multiplication_separator2");
		
	if(!`layout -exists ($type+"_multiplication_button_layout")`) rowLayout -nc 3 ($type+"_multiplication_button_layout");
	if(!`text -exists ($type+"_multiplication_button_text")`){
		setParent ($type+"_multiplication_button_layout");
		text -label ("") ($type+"_multiplication_button_text");
	}
	if(!`button -exists ($type+"_multiplication_button")`){
			setParent ($type+"_multiplication_button_layout");
			button -l "Update" -h 20 ($type+"_multiplication_button");
	}
	
	setParent ($type+"_multiplication_layout");
	if(!`separator -exists ($type+"_multiplication_separator3")`) 
		separator -h 10 -style "none" ($type+"_multiplication_separator3");
		
	string $actionCommand;
	$actionCommand = "setAttr "+$node+".multiplyType (`optionMenu -q -select "+$type+"_multiplication_type_menu`-1);		 		\n";
	$actionCommand += "XFUpdateObject "+$node+";													";
	button -e -command $actionCommand ($type+"_multiplication_button");		
}

global proc hydraCurvNewAttrib(string $attr)
{
	hydraCurvReplaceAttrib($attr);
}

global proc hydraCurvReplaceAttrib(string $attr)
{
	$type = `nodeType ($attr+"number")`;
	int $end   = `size($attr)`-1;
	$node = `substring $attr 1 $end`;
	
	if(!`layout -exists ($type+"_curveParam_layout")`) columnLayout ($type+"_curveParam_layout");
	
	setParent ($type+"_curveParam_layout");
	if(!`layout -exists ($type+"_fan_layout")`) rowLayout -nc 3 ($type+"_fan_layout"); //fan
	if(!`text -exists ($type+"_fan_text")`){
		setParent ($type+"_fan_layout");
		text -label ("Fan") ($type+"_fan_text");
	}
	if(!`textField -exists ($type+"_fan_tf")`){
		setParent ($type+"_fan_layout");
		textField  -ed 0 -tx "<no connection>" ($type+"_fan_tf");
	}
	if(!`symbolButton -exists ($type+"_fan_button")`){
			setParent ($type+"_fan_layout");
			symbolButton -i "inArrow.xpm" -h 20 ($type+"_fan_button");
	}
		
	setParent ($type+"_curveParam_layout");
	if(!`layout -exists ($type+"_twist_layout")`) rowLayout -nc 3 ($type+"_twist_layout"); //twist
	if(!`text -exists ($type+"_twist_text")`){
		setParent ($type+"_twist_layout");
		text -label ("Twist") ($type+"_twist_text");
	}
	if(!`textField -exists ($type+"_twist_tf")`){
		setParent ($type+"_twist_layout");
		textField  -ed 0 -tx "<no connection>" ($type+"_twist_tf");
	}
	if(!`symbolButton -exists ($type+"_twist_button")`){
			setParent ($type+"_twist_layout");
			symbolButton -i "inArrow.xpm" -h 20 ($type+"_twist_button");
	}
		
	setParent ($type+"_curveParam_layout");
	if(!`layout -exists ($type+"_spin_layout")`) rowLayout -nc 3 ($type+"_spin_layout"); //spin
	if(!`text -exists ($type+"_spin_text")`){
		setParent ($type+"_spin_layout");
		text -label ("Spin") ($type+"_spin_text");
	}
	if(!`textField -exists ($type+"_spin_tf")`){
		setParent ($type+"_spin_layout");
		textField  -ed 0 -tx "<no connection>" ($type+"_spin_tf");
	}
	if(!`symbolButton -exists ($type+"_spin_button")`){
			setParent ($type+"_spin_layout");
			symbolButton -i "inArrow.xpm" -h 20 ($type+"_spin_button");
	}
		
	setParent ($type+"_curveParam_layout");
	if(!`layout -exists ($type+"_scale_layout")`) rowLayout -nc 3 ($type+"_scale_layout"); //scale
	if(!`text -exists ($type+"_scale_text")`){
		setParent ($type+"_scale_layout");
		text -label ("Scale") ($type+"_scale_text");
	}
	if(!`textField -exists ($type+"_scale_tf")`){
		setParent ($type+"_scale_layout");
		textField  -ed 0 -tx "<no connection>" ($type+"_scale_tf");
	}
	if(!`symbolButton -exists ($type+"_scale_button")`){
			setParent ($type+"_scale_layout");
			symbolButton -i "inArrow.xpm" -h 20 ($type+"_scale_button");
	}
		
	setParent ($type+"_curveParam_layout");
	if(!`layout -exists ($type+"_nodeGrowth_layout")`) rowLayout -nc 3 ($type+"_nodeGrowth_layout"); //nodeGrowth
	if(!`text -exists ($type+"_nodeGrowth_text")`){
		setParent ($type+"_nodeGrowth_layout");
		text -label ("Node Growth") ($type+"_nodeGrowth_text");
	}
	if(!`textField -exists ($type+"_nodeGrowth_tf")`){
		setParent ($type+"_nodeGrowth_layout");
		textField  -ed 0 -tx "<no connection>" ($type+"_nodeGrowth_tf");
	}
	if(!`symbolButton -exists ($type+"_nodeGrowth_button")`){
			setParent ($type+"_nodeGrowth_layout");
			symbolButton -i "inArrow.xpm" -h 20 ($type+"_nodeGrowth_button");
	}
	
	
	string $params = `connectionInfo -sfd ($attr+"fan")`;				//fan
	if(`size($params)`!=0 && `nodeType $params`=="curveEmulation"){
		string $conInput[];
		tokenize($params, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_fan_tf");
		symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_fan_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_fan_tf");
		$actionCommand  = "string $XFtempStringCurveEmulationName = `XFCreateCurveEmulation`; 								\n";
		$actionCommand += "string $XFtempStringCurveEmulationResult = `XFConnectCurveAttr $XFtempStringCurveEmulationName "+$node+" fan`;		\n";
		$actionCommand += "textField -e -tx $XFtempStringCurveEmulationResult (\""+$type+"_fan_tf\");						\n";
		$actionCommand += "symbolButton -e -i \"inArrow.xpm\" -h 20 -command (\"select \"+$XFtempStringCurveEmulationResult+\";\") "+$type+"_fan_button;	\n";
		symbolButton -e -i "addy.xpm" -h 20 -command $actionCommand ($type+"_fan_button");
	}
	$params = `connectionInfo -sfd ($attr+"twist")`;				//twist
	if(`size($params)`!=0 && `nodeType $params`=="curveEmulation"){
		string $conInput[];
		tokenize($params, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_twist_tf");
		symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_twist_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_twist_tf");
		$actionCommand  = "string $XFtempStringCurveEmulationName = `XFCreateCurveEmulation`; 								\n";
		$actionCommand += "string $XFtempStringCurveEmulationResult = `XFConnectCurveAttr $XFtempStringCurveEmulationName "+$node+" twist`;		\n";
		$actionCommand += "textField -e -tx $XFtempStringCurveEmulationResult (\""+$type+"_twist_tf\");						\n";
		$actionCommand += "symbolButton -e -i \"inArrow.xpm\" -h 20 -command (\"select \"+$XFtempStringCurveEmulationResult+\";\") "+$type+"_twist_button;	\n";
		symbolButton -e -i "addy.xpm" -h 20 -command $actionCommand ($type+"_twist_button");
	}
	$params = `connectionInfo -sfd ($attr+"spin")`;				//spin
	if(`size($params)`!=0 && `nodeType $params`=="curveEmulation"){
		string $conInput[];
		tokenize($params, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_spin_tf");
		symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_spin_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_spin_tf");
		$actionCommand  = "string $XFtempStringCurveEmulationName = `XFCreateCurveEmulation`; 								\n";
		$actionCommand += "string $XFtempStringCurveEmulationResult = `XFConnectCurveAttr $XFtempStringCurveEmulationName "+$node+" spin`;		\n";
		$actionCommand += "textField -e -tx $XFtempStringCurveEmulationResult (\""+$type+"_spin_tf\");						\n";
		$actionCommand += "symbolButton -e -i \"inArrow.xpm\" -h 20 -command (\"select \"+$XFtempStringCurveEmulationResult+\";\") "+$type+"_spin_button;	\n";
		symbolButton -e -i "addy.xpm" -h 20 -command $actionCommand ($type+"_spin_button");
	}
	$params = `connectionInfo -sfd ($attr+"scaleHydra")`;				//scale
	if(`size($params)`!=0 && `nodeType $params`=="curveEmulation"){
		string $conInput[];
		tokenize($params, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_scale_tf");
		symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_scale_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_scale_tf");
		$actionCommand  = "string $XFtempStringCurveEmulationName = `XFCreateCurveEmulation`; 								\n";
		$actionCommand += "string $XFtempStringCurveEmulationResult = `XFConnectCurveAttr $XFtempStringCurveEmulationName "+$node+" scaleHydra`;		\n";
		$actionCommand += "textField -e -tx $XFtempStringCurveEmulationResult (\""+$type+"_scale_tf\");						\n";
		$actionCommand += "symbolButton -e -i \"inArrow.xpm\" -h 20 -command (\"select \"+$XFtempStringCurveEmulationResult+\";\") "+$type+"_scale_button;	\n";
		symbolButton -e -i "addy.xpm" -h 20 -command $actionCommand ($type+"_scale_button");
	}
	$params = `connectionInfo -sfd ($attr+"nodeGrowth")`;				//nodeGrowth
	if(`size($params)`!=0 && `nodeType $params`=="curveEmulation"){
		string $conInput[];
		tokenize($params, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_nodeGrowth_tf");
		symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_nodeGrowth_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_nodeGrowth_tf");
		$actionCommand  = "string $XFtempStringCurveEmulationName = `XFCreateCurveEmulation`; 								\n";
		$actionCommand += "string $XFtempStringCurveEmulationResult = `XFConnectCurveAttr $XFtempStringCurveEmulationName "+$node+" nodeGrowth`;		\n";
		$actionCommand += "textField -e -tx $XFtempStringCurveEmulationResult (\""+$type+"_nodeGrowth_tf\");						\n";
		$actionCommand += "symbolButton -e -i \"inArrow.xpm\" -h 20 -command (\"select \"+$XFtempStringCurveEmulationResult+\";\") "+$type+"_nodeGrowth_button;	\n";
		symbolButton -e -i "addy.xpm" -h 20 -command $actionCommand ($type+"_nodeGrowth_button");
	}	
}

global proc hydraFamilyNewAttrib(string $attr)
{
	hydraFamilyReplaceAttrib($attr);
}

global proc hydraFamilyReplaceAttrib(string $attr)
{
	$type = `nodeType ($attr+"inParameters")`;
	string $objectName[];
	tokenize($attr, ".", $objectName);

	if(!`layout -exists ($type+"_children_layout")`) columnLayout ($type+"_children_layout");

	setParent ($type+"_children_layout");
	if(!`layout -exists ($type+"_parent_layout")`) rowLayout -nc 3 ($type+"_parent_layout"); //parent
	if(!`text -exists ($type+"_parent_text")`){
		setParent ($type+"_parent_layout");
		text -label ("Parent") ($type+"_parent_text");
	}
	if(!`textField -exists ($type+"_parent_tf")`){
		setParent ($type+"_parent_layout");
		textField  -ed 0 -tx "<no connection>" ($type+"_parent_tf");
	}
	if(!`symbolButton -exists ($type+"_parent_button")`){
			setParent ($type+"_parent_layout");
			symbolButton -i "inArrow.xpm" -h 20 ($type+"_parent_button");
	}
	
	setParent ($type+"_children_layout");
	if(!`layout -exists ($type+"_child_layout_row1")`) rowLayout -nc 3 ($type+"_child_layout_row1"); //child
	if(!`text -exists ($type+"_child_text")`){
		setParent ($type+"_child_layout_row1");
		text -label ("Child Object") ($type+"_child_text");
	}
	if(!`textField -exists ($type+"_child_tf")`){
		setParent ($type+"_child_layout_row1");
		textField  -ed 0 -tx "<no connection>" ($type+"_child_tf");
	}
	if(!`symbolButton -exists ($type+"_child_add_button")`){
		setParent ($type+"_child_layout_row1");
		symbolButton -i "addy.xpm" -h 20 ($type+"_child_add_button");
	}
	setParent ($type+"_children_layout");
	if(!`layout -exists ($type+"_child_layout_row2")`) rowLayout -nc 3 ($type+"_child_layout_row2");
	if(!`text -exists ($type+"_child_text2")`){
		setParent ($type+"_child_layout_row2");
		text -label ("Child Primitive") ($type+"_child_text2");
	}
	if(!`textField -exists ($type+"_child_prim_tf")`){
		setParent ($type+"_child_layout_row2");
		textField  -ed 0 -tx "<no connection>" ($type+"_child_prim_tf");
	}
	if(!`symbolButton -exists ($type+"_child_button")`){
		setParent ($type+"_child_layout_row2");
		symbolButton -i "outArrow.xpm" -h 20 ($type+"_child_button");
		if(`popupMenu -exists ($type+"_child_button_popup")`) deleteUI -menu ($type+"_child_button_popup");
		popupMenu -b 3 ($type+"_child_button_popup");
	}
	

	string $pParams;
	if( catchQuiet ($pParams = `connectionInfo -sfd ($attr+"inParameters")`)) $pParams="";			//parent
	if(`size($pParams)`!=0){
		string $conInput[];
		tokenize($pParams, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_parent_tf");
		symbolButton -e -en 1 -command ("select "+$conInput[0]+";") ($type+"_parent_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_parent_tf");
		symbolButton -e -en 0 ($type+"_parent_button");
	}
	
	string $params[];
	string $primParams[];
	setParent -menu ($type+"_child_button_popup");
	$itemCount = `popupMenu -q -numberOfItems ($type+"_child_button_popup")`;
	for($i=0; $i<$itemCount; $i++){
		deleteUI -menuItem ($type+"_child_button_popup_item_"+$i);
	}
	if( catchQuiet ($params = `connectionInfo -dfs ($attr+"outChildParameters[0]")`)) $params={};		//child
	if(`size($params)`>0){
		string $conInput[];
		tokenize($params[0], ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_child_tf");
		symbolButton -e -en 1 -command ("select "+$conInput[0]+";") ($type+"_child_button");
		for($i=0; $i<`size($params)`; $i++){
			tokenize($params[$i], ".", $conInput);
			menuItem -label $conInput[0] -command ("select "+$conInput[0]) ($type+"_child_button_popup_item_"+$i);
		}
	} else {
		textField -e -tx "<no connection>" ($type+"_child_tf");
		symbolButton -e -en 0 ($type+"_child_button");
	}
	if( catchQuiet ($primParams = `connectionInfo -dfs ($attr+"outChildTranslation[0]")`)) $primParams={};	//childPrim
	if(`size($primParams)`>0){
		string $conInput[];
		tokenize($primParams[0], ".", $conInput);
		string $childs[] =`listRelatives -children -fullPath $conInput[0]`;
		if (`size($childs)`>0){
			symbolButton -e -en 1 -command ("select "+$childs[0]+";") ($type+"_child_button");
			$childs =`listRelatives -children $conInput[0]`;
			textField -e -tx $childs[0] ($type+"_child_prim_tf");
		} else {
			textField -e -tx "<no connection>" ($type+"_child_prim_tf");
		}	
	} else {
		textField -e -tx "<no connection>" ($type+"_child_prim_tf");
	}
	string $actionCommand 	=  "string $objName = \"\";						\n";
	$actionCommand		+= "if(!catch($objName = `XFConnectChild 0`)){				\n";
	$actionCommand		+= "	textField -e -tx $objName (\""+$type+"_child_tf\");		\n";
	$actionCommand		+= "}									\n";
	$actionCommand		+= "select "+$objectName[0]+";						\n";
	symbolButton -e -command $actionCommand ($type+"_child_add_button");
}

global proc hydraAlternateNewAttrib(string $attr)
{
	hydraAlternateReplaceAttrib($attr);
}

global proc hydraAlternateReplaceAttrib(string $attr)
{
	$type = `nodeType ($attr)`;
	string $altInput[];
	tokenize($attr, ".", $altInput);
	
	if(`layout -exists ($type+"_clear_a1")`) deleteUI -layout ($type+"_clear_a1");
	if(`layout -exists ($type+"_clear_b1")`) deleteUI -layout ($type+"_clear_b1");
	
	if(!`layout -exists ($type+"_alternate_layout")`) columnLayout ($type+"_alternate_layout");
	
	setParent ($type+"_alternate_layout");
	attrControlGrp -l "Clear Child-Link" -attribute ($altInput[0] + ".clearMeshOrLink[1]") ($type+"_clear_a1");
	attrControlGrp -l "Clear Child-Native" -attribute ($altInput[0] + ".clearNative[0]") ($type+"_clear_b1");
}