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

			// Add the default controls
			editorTemplate -addControl "min";
			editorTemplate -addControl "max";
			editorTemplate -addControl "expression";
			
		editorTemplate -endLayout;
		
		/*editorTemplate -beginLayout "CurveParam" -collapse true;
		
			AEaddRampControl "cv";
		
		editorTemplate -endLayout;*/

		editorTemplate -beginLayout "Point Parameters" -collapse true;
					
			//Add the default controls for the PointParameters
			string $newFuncAttrib = "ppNewAttrib";
			string $replaceFuncAttrib = "ppReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "pp";
		
		editorTemplate -endLayout;
		
		editorTemplate -beginLayout "Point Parameters Visualization" -collapse false;
		
			//Add the default controls for the PointParameters
			string $newFuncViz = "ppNewViz";
			string $replaceFuncViz = "ppReplaceViz";
			editorTemplate -callCustom $newFuncViz $replaceFuncViz "showCurve";
			
		editorTemplate -endLayout;
		
		editorTemplate -beginLayout "Family" -collapse false;
				
			//Add the default controls for the Family-Members-Handling
			string $newFuncAttrib = "emuFamilyNewAttrib";
			string $replaceFuncAttrib = "emuFamilyReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "bcd";	
								
		editorTemplate -endLayout;
		
		editorTemplate -beginLayout "Xfrog HD" -collapse true;
				
			//Add the default controls for the Alternates-Handling
			string $newFuncAttrib = "emuAlternateNewAttrib";
			string $replaceFuncAttrib = "emuAlternateReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "alternateCurvs";	
								
		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 "min";
	editorTemplate -suppress "max";
	editorTemplate -suppress "showCurve";
	editorTemplate -suppress "pp";
	editorTemplate -suppress "caching";
	editorTemplate -suppress "nodeState";
}

global proc ppNewAttrib(string $attr)
{
	ppReplaceAttrib($attr);
}

global proc ppReplaceAttrib(string $attr)
{
	int $end   = `size($attr)`-3;
	string $node = `substring $attr 1 $end`;
	string $type = `objectType $node`;
	string $helper;
	int $numCVs = `getAttr ($node+".CVCount")`;
	int $lastCV = `getAttr ($node+".lastCV")`;
	int $numControls = 0;
	int $numElements = 0;
	
	$helper=$type+"_"+$numControls+"_frame";

	//while(`layout -exists $helper`){
	while(	`layout -exists ($type+"_"+$numControls+"_frame")`
	
		&& `control -exists ($type+"_"+$numControls+"_x_control")`
		&& `control -exists ($type+"_"+$numControls+"_x_label")`
		&& `control -exists ($type+"_"+$numControls+"_x_button")`
		&& `layout -exists ($type+"_"+$numControls+"_x_layout")`
		
		&& `control -exists ($type+"_"+$numControls+"_y_control")`
		&& `control -exists ($type+"_"+$numControls+"_y_label")`
		&& `control -exists ($type+"_"+$numControls+"_y_button")`
		&& `layout -exists ($type+"_"+$numControls+"_y_layout")`
		
		&& `control -exists ($type+"_"+$numControls+"_t1x_control")`
		&& `control -exists ($type+"_"+$numControls+"_t1x_label")`
		&& `control -exists ($type+"_"+$numControls+"_t1x_button")`
		&& `layout -exists ($type+"_"+$numControls+"_t1x_layout")`
		
		&& `control -exists ($type+"_"+$numControls+"_t1y_control")`
		&& `control -exists ($type+"_"+$numControls+"_t1y_label")`
		&& `control -exists ($type+"_"+$numControls+"_t1y_button")`
		&& `layout -exists ($type+"_"+$numControls+"_t1y_layout")`
		
		&& `control -exists ($type+"_"+$numControls+"_t2x_control")`
		&& `control -exists ($type+"_"+$numControls+"_t2x_label")`
		&& `control -exists ($type+"_"+$numControls+"_t2x_button")`
		&& `layout -exists ($type+"_"+$numControls+"_t2x_layout")`
		
		&& `control -exists ($type+"_"+$numControls+"_t2y_control")`
		&& `control -exists ($type+"_"+$numControls+"_t2y_label")`
		&& `control -exists ($type+"_"+$numControls+"_t2y_button")`
		&& `layout -exists ($type+"_"+$numControls+"_t2y_layout")`
		
		&& `control -exists ($type+"_"+$numControls+"_typ_control")`
		&& `control -exists ($type+"_"+$numControls+"_typ_label")`
		&& `layout -exists ($type+"_"+$numControls+"_typ_layout")`){
		
			$numControls++;
			//$helper=$type+"_"+$numControls+"_frame";	
	}
	while(	`layout -exists ($type+"_"+$numControls+"_frame")`
		
		|| `control -exists ($type+"_"+$numControls+"_x_control")`
		|| `control -exists ($type+"_"+$numControls+"_x_label")`
		|| `control -exists ($type+"_"+$numControls+"_x_button")`
		|| `layout -exists ($type+"_"+$numControls+"_x_layout")`

		|| `control -exists ($type+"_"+$numControls+"_y_control")`
		|| `control -exists ($type+"_"+$numControls+"_y_label")`
		|| `control -exists ($type+"_"+$numControls+"_y_button")`
		|| `layout -exists ($type+"_"+$numControls+"_y_layout")`

		|| `control -exists ($type+"_"+$numControls+"_t1x_control")`
		|| `control -exists ($type+"_"+$numControls+"_t1x_label")`
		|| `control -exists ($type+"_"+$numControls+"_t1x_button")`
		|| `layout -exists ($type+"_"+$numControls+"_t1x_layout")`

		|| `control -exists ($type+"_"+$numControls+"_t1y_control")`
		|| `control -exists ($type+"_"+$numControls+"_t1y_label")`
		|| `control -exists ($type+"_"+$numControls+"_t1y_button")`
		|| `layout -exists ($type+"_"+$numControls+"_t1y_layout")`

		|| `control -exists ($type+"_"+$numControls+"_t2x_control")`
		|| `control -exists ($type+"_"+$numControls+"_t2x_label")`
		|| `control -exists ($type+"_"+$numControls+"_t2x_button")`
		|| `layout -exists ($type+"_"+$numControls+"_t2x_layout")`

		|| `control -exists ($type+"_"+$numControls+"_t2y_control")`
		|| `control -exists ($type+"_"+$numControls+"_t2y_label")`
		|| `control -exists ($type+"_"+$numControls+"_t2y_button")`
		|| `layout -exists ($type+"_"+$numControls+"_t2y_layout")`

		|| `control -exists ($type+"_"+$numControls+"_typ_control")`
		|| `control -exists ($type+"_"+$numControls+"_typ_label")`
		|| `layout -exists ($type+"_"+$numControls+"_typ_layout")`){

			$numElements++;
			//$helper=$type+"_"+$numControls+"_frame";	
	}
	for($i=$numControls; $i<$numElements; $i++){

		$helper=$type+"_"+$i+"_x_control";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_x_label";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_x_button";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_x_layout";
		if (`layout -exists $helper`) deleteUI -layout $helper;

		$helper=$type+"_"+$i+"_y_control";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_y_label";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_y_button";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_y_layout";
		if (`layout -exists $helper`) deleteUI -layout $helper;

		$helper=$type+"_"+$i+"_t1x_control";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t1x_label";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t1x_button";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t1x_layout";
		if (`layout -exists $helper`) deleteUI -layout $helper;

		$helper=$type+"_"+$i+"_t1y_control";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t1y_label";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t1y_button";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t1y_layout";
		if (`layout -exists $helper`) deleteUI -layout $helper;

		$helper=$type+"_"+$i+"_t2x_control";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t2x_label";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t2x_button";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t2x_layout";
		if (`layout -exists $helper`) deleteUI -layout $helper;

		$helper=$type+"_"+$i+"_t2y_control";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t2y_label";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t2y_button";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_t2y_layout";
		if (`layout -exists $helper`) deleteUI -layout $helper;

		$helper=$type+"_"+$i+"_typ_control";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_typ_label";
		if (`control -exists $helper`) deleteUI -control $helper;
		$helper=$type+"_"+$i+"_typ_layout";
		if (`layout -exists $helper`) deleteUI -layout $helper;

		$helper=$type+"_"+$i+"_frame";
		if (`layout -exists $helper`) deleteUI -layout $helper;

	}
	
	
	
	if($numControls>$numCVs)
		for($i=$numCVs; $i<$numControls; $i++){

			$helper=$type+"_"+$i+"_x_control";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_x_label";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_x_button";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_x_layout";
			if (`layout -exists $helper`) deleteUI -layout $helper;

			$helper=$type+"_"+$i+"_y_control";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_y_label";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_y_button";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_y_layout";
			if (`layout -exists $helper`) deleteUI -layout $helper;

			$helper=$type+"_"+$i+"_t1x_control";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t1x_label";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t1x_button";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t1x_layout";
			if (`layout -exists $helper`) deleteUI -layout $helper;

			$helper=$type+"_"+$i+"_t1y_control";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t1y_label";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t1y_button";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t1y_layout";
			if (`layout -exists $helper`) deleteUI -layout $helper;

			$helper=$type+"_"+$i+"_t2x_control";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t2x_label";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t2x_button";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t2x_layout";
			if (`layout -exists $helper`) deleteUI -layout $helper;

			$helper=$type+"_"+$i+"_t2y_control";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t2y_label";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t2y_button";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_t2y_layout";
			if (`layout -exists $helper`) deleteUI -layout $helper;

			$helper=$type+"_"+$i+"_typ_control";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_typ_label";
			if (`control -exists $helper`) deleteUI -control $helper;
			$helper=$type+"_"+$i+"_typ_layout";
			if (`layout -exists $helper`) deleteUI -layout $helper;

			$helper=$type+"_"+$i+"_frame";
			if (`layout -exists $helper`) deleteUI -layout $helper;
			
    		}
    	else if($numCVs>$numControls)
    		for($i=$numControls; $i<$numCVs; $i++){
    			$helper = $type+"_"+$i+"_frame";
    			frameLayout -label ("Point_"+$i) -borderStyle "etchedIn" -font "obliqueLabelFont" -collapsable true -collapse true $helper;
    			columnLayout;
    			
    				$helper=$type+"_"+$i+"_x_layout";
    				rowLayout -nc 3 $helper;
					$helper=$type+"_"+$i+"_x_label";
					text -label ("Point "+$i+" x") $helper;
					$helper=$type+"_"+$i+"_x_control";
					floatField $helper;
					$helper=$type+"_"+$i+"_x_button";
					button -label "Key" $helper;
				setParent ..;
				
				$helper=$type+"_"+$i+"_y_layout";
					rowLayout -nc 3 $helper;
					$helper=$type+"_"+$i+"_y_label";
					text -label ("Point "+$i+" y") $helper;
					$helper=$type+"_"+$i+"_y_control";
					floatField $helper;
					$helper=$type+"_"+$i+"_y_button";
					button -label "Key" $helper;
				setParent ..;
				
				$helper=$type+"_"+$i+"_t1x_layout";
					rowLayout -nc 3 $helper;
					$helper=$type+"_"+$i+"_t1x_label";
					text -label ("Point "+$i+" t1x") $helper;
					$helper=$type+"_"+$i+"_t1x_control";
					floatField $helper;
					$helper=$type+"_"+$i+"_t1x_button";
					button -label "Key" $helper;
				setParent ..;
				
				$helper=$type+"_"+$i+"_t1y_layout";
					rowLayout -nc 3 $helper;
					$helper=$type+"_"+$i+"_t1y_label";
					text -label ("Point "+$i+" t1y") $helper;
					$helper=$type+"_"+$i+"_t1y_control";
					floatField $helper;
					$helper=$type+"_"+$i+"_t1y_button";
					button -label "Key" $helper;
				setParent ..;
				
				$helper=$type+"_"+$i+"_t2x_layout";
					rowLayout -nc 3 $helper;
					$helper=$type+"_"+$i+"_t2x_label";
					text -label ("Point "+$i+" t2x") $helper;
					$helper=$type+"_"+$i+"_t2x_control";
					floatField $helper;
					$helper=$type+"_"+$i+"_t2x_button";
					button -label "Key" $helper;
				setParent ..;

				$helper=$type+"_"+$i+"_t2y_layout";
					rowLayout -nc 3 $helper;
					$helper=$type+"_"+$i+"_t2y_label";
					text -label ("Point "+$i+" t2y") $helper;
					$helper=$type+"_"+$i+"_t2y_control";
					floatField $helper;
					$helper=$type+"_"+$i+"_t2y_button";
					button -label "Key" $helper;
				setParent ..;
				
				$helper=$type+"_"+$i+"_typ_layout";
					rowLayout -nc 3 $helper;
					$helper=$type+"_"+$i+"_typ_label";
					text -label ("Point "+$i+" typ") $helper;
					$helper=$type+"_"+$i+"_typ_control";
					optionMenu $helper;
						menuItem -data 1 -label "Bezier Smooth";
						menuItem -data 2 -label "Bezier Corner";
						menuItem -data 3 -label "Classic Smooth";
						menuItem -data 4 -label "Classic Corner";
				setParent ..;
				
			setParent ..;
			setParent ..;
    		}
    		
	for($i=0; $i<$lastCV; $i++){
		if(`getAttr ($node+".pp["+$i+"].activeCV")`==1){
			int $cvId = `getAttr ($node+".pp["+$i+"].cvId")`;
			for($j=0; $j<6; $j++){
				string $subAttrib;
				switch ($j){
				case 0:
					$subAttrib = "x";
					break;
				case 1:
					$subAttrib = "y";
					break;
				case 2:
					$subAttrib = "t1x";
					break;
				case 3:
					$subAttrib = "t1y";
					break;
				case 4:
					$subAttrib = "t2x";
					break;
				case 5:
					$subAttrib = "t2y";
					break;
				default:
					$subAttrib = "";
				}
				$animName = $node+"_"+$i+"_"+$subAttrib+"_animCurve";
				$attribName = $node+".pp["+$i+"]."+$subAttrib;
				//$helper=$type+"_"+$i+"_"+$subAttrib+"_";
				$helper=$type+"_"+$cvId+"_"+$subAttrib+"_";

				$actionCommand =  "if(!`objExists "+$animName+"`){ 					\n";
				$actionCommand += "	createNode animCurveTU -n "+$animName+"; 			\n";
				$actionCommand += "	setKeyframe -v `getAttr "+$attribName+"` "+$animName+";		\n";
				$actionCommand += "	connectAttr "+$animName+".output "+$attribName+";		\n";
				$actionCommand += "} else setKeyframe -v `getAttr "+$attribName+"` "+$animName+";	\n";
				$actionCommand += "select "+$node+";							";

				button -e -command $actionCommand ($helper+"button");
				connectControl ($helper+"control") $attribName;
			}

			$helper=$type+"_"+$cvId+"_typ_control";
			connectControl $helper ($node+".pp["+$i+"].typ");

			$helper=$type+"_"+$cvId+"_";
			int $typeAttr = `getAttr ($node+".pp["+$i+"].typ")`;
			switch ($typeAttr){
				case 1:
					control -e -en 1 ($helper+"t1x_control"); 
					control -e -en 1 ($helper+"t1y_control");
					control -e -en 0 ($helper+"t2x_control");
					control -e -en 0 ($helper+"t2y_control");
					break;
				case 2:
					control -e -en 1 ($helper+"t1x_control"); 
					control -e -en 1 ($helper+"t1y_control");
					control -e -en 1 ($helper+"t2x_control");
					control -e -en 1 ($helper+"t2y_control");
					break;
				default:
					control -e -en 0 ($helper+"t1x_control"); 
					control -e -en 0 ($helper+"t1y_control");
					control -e -en 0 ($helper+"t2x_control");
					control -e -en 0 ($helper+"t2y_control");
			}

			$actionCommand =  "$helper=\""+$type+"_"+$cvId+"_\";							\n";
			$actionCommand += "int $typeAttr = `getAttr "+$node+".pp["+$i+"].typ`;					\n";
			$actionCommand += "switch ($typeAttr){									\n";
			$actionCommand += "	case 1:										\n";
			$actionCommand += "		control -e -en 1 ($helper+\"t1x_control\"); 				\n";
			$actionCommand += "		control -e -en 1 ($helper+\"t1y_control\");				\n";
			$actionCommand += "		control -e -en 0 ($helper+\"t2x_control\");				\n";
			$actionCommand += "		control -e -en 0 ($helper+\"t2y_control\");				\n";
			$actionCommand += "		break;									\n";
			$actionCommand += "	case 2:									  	\n";
			$actionCommand += "		control -e -en 1 ($helper+\"t1x_control\"); 			 	\n";
			$actionCommand += "		control -e -en 1 ($helper+\"t1y_control\");				\n";
			$actionCommand += "		control -e -en 1 ($helper+\"t2x_control\");				\n";
			$actionCommand += "		control -e -en 1 ($helper+\"t2y_control\");				\n";
			$actionCommand += "		break;									\n";
			$actionCommand += "	default:									\n";
			$actionCommand += "		control -e -en 0 ($helper+\"t1x_control\"); 				\n";
			$actionCommand += "		control -e -en 0 ($helper+\"t1y_control\");				\n";
			$actionCommand += "		control -e -en 0 ($helper+\"t2x_control\");				\n";
			$actionCommand += "		control -e -en 0 ($helper+\"t2y_control\");				\n";
			$actionCommand += "}											\n";
			optionMenu -e -cc $actionCommand ($helper+"typ_control");
		}
	}
}


global proc ppNewViz(string $attr)
{
	ppReplaceViz($attr);
}

global proc ppReplaceViz(string $attr)
{
	string $vizCurveAttr = `connectionInfo -sfd ($attr)`;
	string $vizCurve;
	int $end   = `size($attr)`-10;
	string $node = `substring $attr 1 $end`;
	string $type = `objectType $node`;
	int $siz = size($vizCurveAttr);
	if($siz==0){
		if(`animCurveEditor -exists ($type+"_ace")`) deleteUI -editor ($type+"_ace");
		if(`selectionConnection -exists ($type+"_ace_selectConn")`) deleteUI ($type+"_ace_selectConn");
		if(`layout -exists ($type+"_ace_layout")`) deleteUI -layout ($type+"_ace_layout");
		if(`toolButton -exists ($type+"_ace_moveBut")`) deleteUI -control ($type+"_ace_moveBut");
		if(`toolButton -exists ($type+"_ace_insBut")`) deleteUI -control ($type+"_ace_insBut");
		if(`symbolButton -exists ($type+"_ace_delBut")`) deleteUI -control ($type+"_ace_delBut");
		if(`symbolButton -exists ($type+"_ace_keyBut")`) deleteUI -control ($type+"_ace_keyBut");
		if(`symbolButton -exists ($type+"_ace_bakeBut")`) deleteUI -control ($type+"_ace_bakeBut");
		if(`layout -exists ($type+"_ace_buttonBar")`) deleteUI -layout ($type+"_ace_buttonBar");
	} else {
		$siz = $siz - 7;
		$vizCurve = `substring $vizCurveAttr 1 $siz`;
	
		if( !(	   `layout -exists ($type+"_ace_layout")`
			&& `animCurveEditor -exists ($type+"_ace")`
			&& `toolButton -exists ($type+"_ace_moveBut")`
			&& `toolButton -exists ($type+"_ace_insBut")`
			&& `symbolButton -exists ($type+"_ace_delBut")`
			&& `symbolButton -exists ($type+"_ace_keyBut")`
			&& `symbolButton -exists ($type+"_ace_bakeBut")`
			&& `selectionConnection -exists ($type+"_ace_selectConn")`
			&& `layout -exists ($type+"_ace_buttonBar")` )	){
			
			if(`animCurveEditor -exists ($type+"_ace")`) deleteUI -editor ($type+"_ace");
			if(`toolButton -exists ($type+"_ace_moveBut")`) deleteUI -control ($type+"_ace_moveBut");
			if(`toolButton -exists ($type+"_ace_insBut")`) deleteUI -control ($type+"_ace_insBut");
			if(`symbolButton -exists ($type+"_ace_delBut")`) deleteUI -control ($type+"_ace_delBut");
			if(`symbolButton -exists ($type+"_ace_keyBut")`) deleteUI -control ($type+"_ace_keyBut");
			if(`symbolButton -exists ($type+"_ace_bakeBut")`) deleteUI -control ($type+"_ace_bakeBut");
			if(`layout -exists ($type+"_ace_buttonBar")`) deleteUI -layout ($type+"_ace_buttonBar");
			if(`layout -exists ($type+"_ace_layout")`) deleteUI -layout ($type+"_ace_layout");
			if(`selectionConnection -exists ($type+"_ace_selectConn")`) deleteUI ($type+"_ace_selectConn");
			
			selectionConnection ($type+"_ace_selectConn");
			//paneLayout -w 200 -h 150 ($type+"_ace_layout");
			formLayout -w 200 -h 150 ($type+"_ace_layout");
				animCurveEditor -di 0 -st "none" -sv "none" -fmc ($type+"_ace_selectConn") ($type+"_ace");
				formLayout -edit
					-attachForm ($type+"_ace") "top" 1
					-attachForm ($type+"_ace") "left" 1
					-attachForm ($type+"_ace") "bottom" 1
					-attachForm ($type+"_ace") "right" 1
					($type+"_ace_layout");
			setParent ..;
			//rowLayout -nc 5 -columnWidth4 100 100 100 100 ($type+"_ace_buttonBar");
			rowLayout -nc 5 -columnWidth5 80 80 80 80 80 ($type+"_ace_buttonBar");
				toolButton -tool moveSuperContext -toolImage1 moveSuperContext "posRadial.png" ($type+"_ace_moveBut");
				toolButton -tool insertKeySuperContext -toolImage1 insertKeySuperContext "insertKnot.png" ($type+"_ace_insBut");
				symbolButton -w `toolButton -q -w ($type+"_ace_moveBut")` -h `toolButton -q -h ($type+"_ace_moveBut")` -image "detachCurve.png" -command "cutKey -clear;" ($type+"_ace_delBut");
				symbolButton -w `toolButton -q -w ($type+"_ace_moveBut")` -h `toolButton -q -h ($type+"_ace_moveBut")` -image "setKeyframe.png" ($type+"_ace_keyBut");
				symbolButton -w `toolButton -q -w ($type+"_ace_moveBut")` -h `toolButton -q -h ($type+"_ace_moveBut")` -image "fire.png" ($type+"_ace_bakeBut");
			setParent ..;
		}
			
		selectionConnection -e -clear ($type+"_ace_selectConn");		//add animCurve vor visualization and dummy-animcurve for setting the min-max-defaults
		selectionConnection -e -object $vizCurve ($type+"_ace_selectConn");
		if(!`objExists XFrog_Default_AnimCurve_Setter`){
			createNode animCurveUU -n XFrog_Default_AnimCurve_Setter;
			select $node;
		}
		setKeyframe -f 0 -v `getAttr ($node+".min")` XFrog_Default_AnimCurve_Setter;
		setKeyframe -f 100 -v `getAttr ($node+".max")` XFrog_Default_AnimCurve_Setter;
		selectionConnection -e -object XFrog_Default_AnimCurve_Setter ($type+"_ace_selectConn");
		editor -e -fmc ($type+"_ace_selectConn") ($type+"_ace");
		animCurveEditor -e -af 1 ($type+"_ace");				//set the visualization defaults 
		animCurveEditor -e -af 0 ($type+"_ace");				//remove autoframing - so no change to the animCurveEditor can be made outside this function
		
		editor -e -fmc `selectionConnection -obj $vizCurve` ($type+"_ace");
		if(`selectionConnection -exists ($type+"_ace_selectConn")`) deleteUI ($type+"_ace_selectConn");					//remove the selection Connection-references - needed, otherwse maya would crash for some reason
		selectionConnection ($type+"_ace_selectConn");
		
		$actionCommand =  "int $lastCV = `getAttr "+$node+".lastCV`; 						\n";
		$actionCommand += "for($i = 0; $i<$lastCV; $i++){							\n";
		$actionCommand += "	if(`getAttr (\""+$node+".pp[\"+$i+\"].activeCV\")`==1){				\n";
		$actionCommand += "		for($j=0; $j<6; $j++){							\n";
		$actionCommand += "			string $subAttrib;						\n";
		$actionCommand += "			switch ($j){							\n";
		$actionCommand += "			case 0:								\n";
		$actionCommand += "				$subAttrib = \"x\";					\n";
		$actionCommand += "				break;							\n";
		$actionCommand += "			case 1:								\n";
		$actionCommand += "				$subAttrib = \"y\";					\n";
		$actionCommand += "				break;							\n";
		$actionCommand += "			case 2:								\n";
		$actionCommand += "				$subAttrib = \"t1x\";					\n";
		$actionCommand += "				break;							\n";
		$actionCommand += "			case 3:								\n";
		$actionCommand += "				$subAttrib = \"t1y\";					\n";
		$actionCommand += "				break;							\n";
		$actionCommand += "			case 4:								\n";
		$actionCommand += "				$subAttrib = \"t2x\";					\n";
		$actionCommand += "				break;							\n";
		$actionCommand += "			case 5:								\n";
		$actionCommand += "				$subAttrib = \"t2y\";					\n";
		$actionCommand += "				break;							\n";
		$actionCommand += "			default:							\n";
		$actionCommand += "				$subAttrib = \"\";					\n";
		$actionCommand += "			}								\n";
		$actionCommand += "			$animName = \""+$node+"_\"+$i+\"_\"+$subAttrib+\"_animCurve\";	\n";
		$actionCommand += "			$attribName = \""+$node+".pp[\"+$i+\"].\"+$subAttrib;		\n";
		$actionCommand += "			if(!`objExists $animName`){ 					\n";
		$actionCommand += "				createNode animCurveTU -n $animName; 			\n";
		$actionCommand += "				setKeyframe -v `getAttr $attribName` $animName;		\n";
		$actionCommand += "				connectAttr ($animName+\".output\") $attribName; 	\n";
		$actionCommand += "			}								\n";
		$actionCommand += "			else setKeyframe -v `getAttr $attribName` $animName;		\n";
		$actionCommand += "		}									\n";
		$actionCommand += "	}										\n";
		$actionCommand += "}											\n"; 
		$actionCommand += "select "+$node+";									";
		symbolButton -e -command $actionCommand ($type+"_ace_keyBut");
		
		symbolButton -e -command ("getAttr "+$node+".expressionDummy;") ($type+"_ace_bakeBut");
	}
}

global proc emuFamilyNewAttrib(string $attr)
{
	emuFamilyReplaceAttrib($attr);
}

global proc emuFamilyReplaceAttrib(string $attr)
{
	$type = `nodeType ($attr)`;
	
	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");
	}
	
	string $params[];
	if( catchQuiet ($params = `connectionInfo -dfs ($attr)`)) $params={};	//parent
	if(`size($params)`!=0){
		string $conInput[];
		tokenize($params[0], ".", $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");
	}
}

global proc emuAlternateNewAttrib(string $attr)
{
	emuAlternateReplaceAttrib($attr);
}

global proc emuAlternateReplaceAttrib(string $attr)
{
	$type = `nodeType ($attr)`;
	string $altInput[];
	tokenize($attr, ".", $altInput);
	
	string $parentName[];
	string $checklist[] = `listConnections -d on -s off -sh on ($altInput[0]+".bcd")`;
	int $typeMatch = 0;
	int $end   = `size($checklist)`;
	for($i=0; $i<$end; $i++){
		if (`nodeType ($checklist[$i])` == "curveEmulation") $typeMatch++;
		else $parentName = `listRelatives -parent ($checklist[$i])`;
	}
	if ($typeMatch <= 0 && `size($parentName)` > 0) {
		
		int $freePlug = -1;
		if(!`layout -exists ($type+"_alternate_layout")`) columnLayout ($type+"_alternate_layout");
		
		setParent ($type+"_alternate_layout");
		if(!`layout -exists ($type+"_alternate_line_layout")`) rowLayout -nc 3 ($type+"_alternate_line_layout"); //alternate
		if(!`text -exists ($type+"_alternate_fill")`){
			setParent ($type+"_alternate_line_layout");
			text -label ("") ($type+"_alternate_fill");
		}
		if(!`text -exists ($type+"_alternate_text")`){
			setParent ($type+"_alternate_line_layout");
			text -label ("Generate alternate") -align "right" ($type+"_alternate_text");
		}
		if(!`symbolButton -exists ($type+"_alternate_button")`){
				setParent ($type+"_alternate_line_layout");
				symbolButton -i "addy.xpm" -h 20 ($type+"_alternate_button");
		}
	
		string $altlist[] = `listConnections -d off -s on -p on -c on ($attr)`;
		int $altCount  = `size($altlist)`/2;
		int $altIterate=0;
		while(`layout -exists ($type+"_alternate_"+$altIterate+"_layout1")`){
			$altIterate++;	
		}
		if($altCount>$altIterate){	// create additional lines
			for($i=$altIterate; $i<$altCount; $i++){
				setParent ($type+"_alternate_layout");
				rowLayout -nc 3 ($type+"_alternate_"+$i+"_layout1");
				text -label ("Offset "+$i) ($type+"_alternate_"+$i+"_text1");
				textField  -ed 1 -tx "" ($type+"_alternate_"+$i+"_offset_tf");
				text -label ("") ($type+"_alternate_"+$i+"_fill");
				setParent ($type+"_alternate_layout");
				rowLayout -nc 3 ($type+"_alternate_"+$i+"_layout2");
				text -label ("Alternate "+$i) ($type+"_alternate_"+$i+"_text2");
				textField  -ed 0 -tx "<no connection>" ($type+"_alternate_"+$i+"_tf");
				symbolButton -i "inArrow.xpm" -h 20 ($type+"_alternate_"+$i+"_switch_button");
			}
		}
		if($altCount<$altIterate){	// delete unneeded lines
			for($i=$altCount; $i<$altIterate; $i++){
				deleteUI -control ($type+"_alternate_"+$i+"_text1");
				deleteUI -control ($type+"_alternate_"+$i+"_offset_tf");
				deleteUI -control ($type+"_alternate_"+$i+"_fill");
				deleteUI -control ($type+"_alternate_"+$i+"_text2");
				deleteUI -control ($type+"_alternate_"+$i+"_tf");
				deleteUI -control ($type+"_alternate_"+$i+"_switch_button");
				deleteUI -layout ($type+"_alternate_"+$i+"_layout1");
				deleteUI -layout ($type+"_alternate_"+$i+"_layout2");
			}
		}
		for($i=0; $i<$altCount; $i++){
			string $conInput[];
			tokenize($altlist[$i*2], "[", $conInput);
			string $inputOffset = "["+$conInput[(`size($conInput)`-1)];
			text -e -label ("Offset "+$inputOffset) ($type+"_alternate_"+$i+"_text1");
			text -e -label ("Alternate "+$inputOffset) ($type+"_alternate_"+$i+"_text2");
			string $changeCommand = "setAttr (\"" + $altInput[0] + ".alternateOffs" + $inputOffset + "\") -type \"string\" (`textField -q -tx (\"" + $type + "_alternate_" + $i + "_offset_tf\")`);\n";
			string $changeValue = `getAttr ($altInput[0] + ".alternateOffs" + $inputOffset)`;
			string $conInput[];
			tokenize($altlist[$i*2+1], ".", $conInput);
			textField -e -tx $conInput[0] ($type+"_alternate_"+$i+"_tf");
			textField -e -tx ($changeValue) -cc ($changeCommand) ($type+"_alternate_"+$i+"_offset_tf");
			symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_alternate_"+$i+"_switch_button");
			if ($freePlug < 0) {
				string $freelist[] = `listConnections -d off -s on ($altInput[0]+".alternateCurvs["+$i+"]")`;
				if (`size($freelist)` <= 0) $freePlug = $i;
			}
		}
		if ($freePlug < 0) $freePlug = $altCount;
		
		string $actionCommand 	=  "string $objName = \"\";																						\n";
		$actionCommand			+= "if(!catch($objName = `XFCreateCurveEmulation`)){															\n";
		$actionCommand			+= "	$objName = `rename ($objName) (\"" + $altInput[0] + "_alternate_" + $freePlug + "\")`;					\n";
		$actionCommand			+= "	string $parNames[] = `parent ($objName) (\"" + $parentName[0] + "\")`;									\n";
		$actionCommand			+= "	$objName = $parNames[0];																				\n";
		$actionCommand			+= "	connectAttr ($objName+\".bcd\") (\"" + $altInput[0] + ".alternateCurvs[" + $freePlug + "]\");			\n";
		$actionCommand			+= "	select (\"" + $altInput[0] + "\");																		\n";
		$actionCommand			+= "}																											\n";
		symbolButton -e -command $actionCommand ($type+"_alternate_button");
				
	} else {
		if(`layout -exists ($type+"_alternate_line_layout")`) {
			deleteUI -control ($type+"_alternate_fill");
			deleteUI -control ($type+"_alternate_text");
			deleteUI -control ($type+"_alternate_button");
			deleteUI -layout ($type+"_alternate_line_layout");
			int $altIterate=0;
			while(`layout -exists ($type+"_alternate_"+$altIterate+"_layout1")`){
					$altIterate++;	
			}
			for($i=0; $i<$altIterate; $i++){
				deleteUI -control ($type+"_alternate_"+$i+"_text1");
				deleteUI -control ($type+"_alternate_"+$i+"_offset_tf");
				deleteUI -control ($type+"_alternate_"+$i+"_fill");
				deleteUI -control ($type+"_alternate_"+$i+"_text2");
				deleteUI -control ($type+"_alternate_"+$i+"_tf");
				deleteUI -control ($type+"_alternate_"+$i+"_switch_button");
				deleteUI -layout ($type+"_alternate_"+$i+"_layout1");
				deleteUI -layout ($type+"_alternate_"+$i+"_layout2");
			}
		}
	}
}
