if(`pluginInfo -q -l Xfrog4Maya`==1){
if(!`scriptedPanel -exists xfvpScriptedPanel`){
	if (!`selectionConnection -exists "XfObjectSelectionConnection"`) {
		selectionConnection "XfObjectSelectionConnection";
		global proc outScriptCallback(string $array[])
		{
			if(`window -exists "XfrogVisor"`){
				string $item = `itemFilter -bt Tropism -bt Branch -bt CurveNurbs -bt Hydra -bt Phyllotaxis -bt Variation -bt nurbsCurve -bt XfrogTransform`;
				outlinerEditor -edit -filter $item "XfObjectOutliner";
			}
			if(`outlinerEditor -exists "XfPanelObjectOutliner"`){
				string $item = `itemFilter -bt Tropism -bt Branch -bt CurveNurbs -bt Hydra -bt Phyllotaxis -bt Variation -bt nurbsCurve -bt XfrogTransform`;
				outlinerEditor -edit -filter $item "XfPanelObjectOutliner";
			}
			
			string $objName;
			for($i=0; $i<`size($array)`; $i++){
				$objName = $array[$i];
			}

			int $type = 0;
			string $shapes[] = `listRelatives -shapes -fullPath $objName`;
			for ($j=0; $j<`size($shapes)`; $j++){
				if (`objectType $shapes[$j]`=="Branch") $type = 1;
				if (`objectType $shapes[$j]`=="Hydra") $type = 2;
				if (`objectType $shapes[$j]`=="Phyllotaxis") $type = 2;
				if (`objectType $shapes[$j]`=="Variation") $type = 3;
			}
			if (`objectType $objName`=="Branch") $type = 1;
			if (`objectType $objName`=="Hydra") $type = 2;
			if (`objectType $objName`=="Phyllotaxis") $type = 2;
			if (`objectType $objName`=="Variation") $type = 3;

			string $connects[];
			string $selName = `selectionConnection`;
			int $usedSelection = 0;
				if ($type>0){			// all XFObjs
					int $count = 1;
					if ($type ==3){		// Variation
						$count = `getAttr ($objName+".childCount")`;
					}
					for ($j=0; $j<$count; $j++){
					if( catchQuiet ($connects = `connectionInfo -dfs ($objName+".outChildTranslation["+$j+"]")`)) $connects={};
					if(`size($connects)`>0){
						string $conInput[];
						tokenize($connects[0], ".", $conInput);
						string $childs[] =`listRelatives -children -fullPath $conInput[0]`;
						if (`size($childs)`>0){
							selectionConnection -edit -select $childs[0] $selName;
							$usedSelection = 1;
						}
					}
				}
			}
			if ($type==1){			// Branch
				if( catchQuiet ($connects = `connectionInfo -dfs ($objName+".outShapeTranslation[0]")`)) $connects={};
				if(`size($connects)`>0){
					string $conInput[];
					tokenize($connects[0], ".", $conInput);
					string $childs[] =`listRelatives -children -fullPath $conInput[0]`;
					if (`size($childs)`>0){
						selectionConnection -edit -select $childs[0] $selName;
						$usedSelection = 1;
					}
				}
				if( catchQuiet ($connects = `connectionInfo -dfs ($objName+".outHeadTranslation[0]")`)) $connects={};
				if(`size($connects)`>0){
					string $conInput[];
					tokenize($connects[0], ".", $conInput);
					string $childs[] =`listRelatives -children -fullPath $conInput[0]`;
					if (`size($childs)`>0){
						selectionConnection -edit -select $childs[0] $selName;
						$usedSelection = 1;
					}
				}
				
				if( catchQuiet ($connects = `connectionInfo -dfs ($objName+".outMesh[0]")`)) $connects={};
				if(`size($connects)`>0){
					string $conInput[];
					tokenize($connects[0], ".", $conInput);
					string $parents[] =`listRelatives -parent -fullPath $conInput[0]`;
					if (`size($parents)`>0){
						selectionConnection -edit -select $parents[0] $selName;
						$usedSelection = 1;
					}
				}
				
				if( catchQuiet ($connects = `connectionInfo -dfs ($objName+".outMesh[1]")`)) $connects={};
				if(`size($connects)`>0){
					string $conInput[];
					tokenize($connects[0], ".", $conInput);
					string $parents[] =`listRelatives -parent -fullPath $conInput[0]`;
					if (`size($parents)`>0){
						selectionConnection -edit -select $parents[0] $selName;
						$usedSelection = 1;
					}
				}
				
				if( catchQuiet ($connects = `connectionInfo -dfs ($objName+".outMesh[2]")`)) $connects={};
				if(`size($connects)`>0){
					string $conInput[];
					tokenize($connects[0], ".", $conInput);
					string $parents[] =`listRelatives -parent -fullPath $conInput[0]`;
					if (`size($parents)`>0){
						selectionConnection -edit -select $parents[0] $selName;
						$usedSelection = 1;
					}
				}
			}
			if ($usedSelection!=0 && `outlinerEditor -exists "XfrogPrimitivesOutliner"`) outlinerEditor -edit -mainListConnection $selName "XfrogPrimitivesOutliner";
			if ($usedSelection!=0 && `outlinerEditor -exists "XfrogPanelPrimitivesOutliner"`) outlinerEditor -edit -mainListConnection $selName "XfrogPanelPrimitivesOutliner";
		}
		selectionConnection -edit -addScript outScriptCallback "XfObjectSelectionConnection";
	}
	
	if(!`scriptedPanelType -exists xfvpScriptedPanelType`) {
		scriptedPanelType
			-ccb xfvpCreateCallback
			-icb xfvpInitCallback
			-acb xfvpAddCallback
			-rcb xfvpRemoveCallback
			-dcb xfvpDeleteCallback
			-scb xfvpSaveStateCallback
			-unique true
			xfvpScriptedPanelType;
	}
		
	global proc xfvpCreateCallback(string $panelName) {}
	global proc xfvpInitCallback(string $panelName) {
		if(`outlinerEditor -exists "XfPanelObjectOutliner"`){
			string $item = `itemFilter -bt Tropism -bt Branch -bt CurveNurbs -bt Hydra -bt Phyllotaxis -bt Variation -bt nurbsCurve -bt XfrogTransform`;
			outlinerEditor -edit -filter $item "XfPanelObjectOutliner";
		}
	}
	global proc xfvpAddCallback(string $panelName) {
	
		string $variationChildCommand = "string $currentlySelectedObjects[] = `ls -long -selection`; if (`size($currentlySelectedObjects)` == 2) { string $currentObject = $currentlySelectedObjects[1];																	\n";
		$variationChildCommand		 += "if (`objectType($currentObject)` == \"transform\") { string $currentObjectChildren[] = `listRelatives -children $currentObject`; if (`size($currentObjectChildren)` > 0) $currentObject = $currentObjectChildren[0]; }				\n";
		$variationChildCommand		 += "if (`objectType($currentObject)` == \"Variation\") {																																												\n";
		$variationChildCommand		 += "	int $variationChildCount = `getAttr ($currentObject + \".childCount\")`; int $lowestFreeChild = -1;																																\n";
		$variationChildCommand		 += "	for ($i=0; $i < $variationChildCount; $i++) {																																													\n";
		$variationChildCommand		 += "		if (!`connectionInfo -is ($currentObject + \".outChildParameters[\" + $i + \"]\")`) {																																		\n";
		$variationChildCommand		 += "		if (!`connectionInfo -id ($currentObject + \".inMesh[\" + $i + \"]\")`) {																																					\n";
		$variationChildCommand		 += "		if (!`connectionInfo -id ($currentObject + \".inNurbs[\" + $i + \"]\")`) {																																					\n";
		$variationChildCommand		 += "		if (!`connectionInfo -id ($currentObject + \".inSubdiv[\" + $i + \"]\")`) { $lowestFreeChild = $i; }}}} if ($lowestFreeChild >= 0) $i = $variationChildCount;																\n";
		$variationChildCommand		 += "	} if ($lowestFreeChild >= 0) XFConnectChild $lowestFreeChild; else error \"No free child-slot found for Variation\"; }	else { XFConnectChild 0; }}	else error \"One or more objects given by argument not found!\";			\n";
		
		string $variationShapeCommand = "string $currentlySelectedObjects[] = `ls -long -selection`; if (`size($currentlySelectedObjects)` == 2) { string $currentObject = $currentlySelectedObjects[1];																	\n";
		$variationShapeCommand		 += "if (`objectType($currentObject)` == \"transform\") { string $currentObjectChildren[] = `listRelatives -children $currentObject`; if (`size($currentObjectChildren)` > 0) $currentObject = $currentObjectChildren[0]; }				\n";
		$variationShapeCommand		 += "if (`objectType($currentObject)` == \"Variation\") { error \"Illegal Parameter!\"; } else { XFConnectChild 1; }}	else error \"One or more objects given by argument not found!\";												\n";
		
		string $variationHeadCommand  = "string $currentlySelectedObjects[] = `ls -long -selection`; if (`size($currentlySelectedObjects)` == 2) { string $currentObject = $currentlySelectedObjects[1];																	\n";
		$variationHeadCommand		 += "if (`objectType($currentObject)` == \"transform\") { string $currentObjectChildren[] = `listRelatives -children $currentObject`; if (`size($currentObjectChildren)` > 0) $currentObject = $currentObjectChildren[0]; }				\n";
		$variationHeadCommand		 += "if (`objectType($currentObject)` == \"Variation\") { error \"Illegal Parameter!\"; } else { XFConnectChild 2; }}	else error \"One or more objects given by argument not found!\";												\n";
	
		string $formLayout = `formLayout`;
		string $columnLayout = `columnLayout -rowSpacing 0 -adjustableColumn true`;
			string $frameLayout = `frameLayout -collapsable true -collapse false -label "Xfrog4Maya Control Center"`;
				string $formLayoutCtrl = `formLayout`;
					string $button1 = `button -label "Delete" -command "delete;"`;
					string $button2 = `button -label "Free" -command "XFFreeObject;"`;
					string $button3 = `button -label "Show Input" -command "XFInputVisibility -show;"`;
					string $button4 = `button -label "Hide Input" -command "XFInputVisibility -hide;"`;
					string $button5 = `button -label "Select Mesh" -command "XFSelect -mesh -replace;"`;
					string $button6 = `button -label "Select Obj" -command "XFSelect -object -replace;"`;
					string $button7 = `button -label "Child" -command $variationChildCommand`;
					string $button8 = `button -label "Shape" -command $variationShapeCommand`;
					string $button9 = `button -label "Head" -command $variationHeadCommand`;
					string $button10 = `button -label "Update" -command "XFUpdateObject;"`;

					formLayout -edit
						-attachForm $button1 "top" 1
						-attachForm $button1 "bottom" 1
						-attachPosition $button1 "left" 0 2
						-attachPosition $button1 "right" 0 10

						-attachForm $button2 "top" 1
						-attachForm $button2 "bottom" 1
						-attachPosition $button2 "left" 0 10
						-attachPosition $button2 "right" 0 18

						-attachForm $button3 "top" 1
						-attachForm $button3 "bottom" 1
						-attachPosition $button3 "left" 0 20
						-attachPosition $button3 "right" 0 30

						-attachForm $button4 "top" 1
						-attachForm $button4 "bottom" 1
						-attachPosition $button4 "left" 0 30
						-attachPosition $button4 "right" 0 40

						-attachForm $button5 "top" 1
						-attachForm $button5 "bottom" 1
						-attachPosition $button5 "left" 0 42
						-attachPosition $button5 "right" 0 52

						-attachForm $button6 "top" 1
						-attachForm $button6 "bottom" 1
						-attachPosition $button6 "left" 0 52
						-attachPosition $button6 "right" 0 62

						-attachForm $button7 "top" 1
						-attachForm $button7 "bottom" 1
						-attachPosition $button7 "left" 0 64
						-attachPosition $button7 "right" 0 72

						-attachForm $button8 "top" 1
						-attachForm $button8 "bottom" 1
						-attachPosition $button8 "left" 0 72
						-attachPosition $button8 "right" 0 80

						-attachForm $button9 "top" 1
						-attachForm $button9 "bottom" 1
						-attachPosition $button9 "left" 0 80
						-attachPosition $button9 "right" 0 88

						-attachForm $button10 "top" 1
						-attachForm $button10 "bottom" 1
						-attachPosition $button10 "left" 0 90
						-attachPosition $button10 "right" 0 98

						$formLayoutCtrl;
				setParent ..;
			setParent ..;
		setParent ..;
		
		string $columnLayout2 = `columnLayout -rowSpacing 0 -adjustableColumn true`;
			string $frameLayout2 = `frameLayout -collapsable true -collapse false -label "Xfrog4Maya Copy Control"`;
				string $formLayoutCtrl2 = `formLayout`;
					string $cbutton1 = `button -label "Enable" -command "global int $XfrogCopyAllowed = 12345;"`;
					string $cbutton2 = `button -label "Disable" -command "global int $XfrogCopyAllowed = 0;"`;
					string $ctext3 = `textField -h 10 -en false -ed false "XfVisorPanelDestinationClipboard"`;
					string $cmenu4 = `optionMenu -h 10 "XfVisorPanelDestinationType"`;
						menuItem -data 1 -label "Copy";
						menuItem -data 2 -label "Move";
					optionMenu -e -select 1 $cmenu4;
					string $ccmd5 = "intField -e -en false -value 0 \"XfVisorPanelDestinationChildNumber\"; int $selOffset = `optionMenu -q -sl \"XfVisorPanelDestinationMenu\"`; if ($selOffset == 1) intField -e -en true \"XfVisorPanelDestinationChildNumber\";";
					string $cmenu5 = `optionMenu -h 10 "XfVisorPanelDestinationMenu"`;
						menuItem -data 1 -label "Child/Path";
						menuItem -data 2 -label "Shape";
						menuItem -data 3 -label "Head";
						menuItem -data 4 -label "Next";
					optionMenu -e -select 4 -cc $ccmd5 $cmenu5;
					string $ctext6 = `intField -h 10 -en false -ed true -minValue 0 -value 0 "XfVisorPanelDestinationChildNumber"`;
					string $ccmd7 = "string $selectionArray[] = `ls -long -selection`; if (`size($selectionArray)` == 1) textField -e -text $selectionArray[0] \"XfVisorPanelDestinationClipboard\";";
					string $cbutton7 = `button -label "Copy" -command $ccmd7`;
					string $ccmd8    = "string $selectionArray[] = `ls -long -selection`; ";
					$ccmd8			+= "string $selectionSource = `textField -q -text \"XfVisorPanelDestinationClipboard\"`; ";
					$ccmd8			+= "int $selectionType = `optionMenu -q -sl \"XfVisorPanelDestinationType\"`-1; ";
					$ccmd8			+= "if (`size($selectionSource)` > 0) { ";
					$ccmd8			+= "	if (`size($selectionArray)` == 0) { ";
					$ccmd8			+= "		XFCopy $selectionSource $selectionType;";
					$ccmd8			+= "	} else if (`size($selectionArray)` == 1){ ";
					$ccmd8			+= "		int $destinationType = `optionMenu -q -sl \"XfVisorPanelDestinationMenu\"`-1; ";
					$ccmd8			+= "		if ($destinationType == 0) { ";
					$ccmd8			+= "			int $destinationNumber = `intField -q -value \"XfVisorPanelDestinationChildNumber\"`; ";
					$ccmd8			+= "			XFCopy $selectionSource $selectionArray[0] $selectionType $destinationType $destinationNumber;";
					$ccmd8			+= "		} else {";
					$ccmd8			+= "			XFCopy $selectionSource $selectionArray[0] $selectionType $destinationType;";
					$ccmd8			+= "		}";
					$ccmd8			+= "	}";
					$ccmd8			+= "}";
					string $cbutton8 = `button -label "Paste" -command $ccmd8`;
					
					formLayout -edit
						-attachForm $cbutton1 "top" 1
						-attachForm $cbutton1 "bottom" 1
						-attachPosition $cbutton1 "left" 0 2
						-attachPosition $cbutton1 "right" 0 10

						-attachForm $cbutton2 "top" 1
						-attachForm $cbutton2 "bottom" 1
						-attachPosition $cbutton2 "left" 0 10
						-attachPosition $cbutton2 "right" 0 18

						-attachForm $ctext3 "top" 1
						-attachForm $ctext3 "bottom" 1
						-attachPosition $ctext3 "left" 0 20
						-attachPosition $ctext3 "right" 0 50

						-attachForm $cmenu4 "top" 1
						-attachForm $cmenu4 "bottom" 1
						-attachPosition $cmenu4 "left" 0 51
						-attachPosition $cmenu4 "right" 0 60

						-attachForm $cmenu5 "top" 1
						-attachForm $cmenu5 "bottom" 1
						-attachPosition $cmenu5 "left" 0 61
						-attachPosition $cmenu5 "right" 0 70

						-attachForm $ctext6 "top" 1
						-attachForm $ctext6 "bottom" 1
						-attachPosition $ctext6 "left" 0 71
						-attachPosition $ctext6 "right" 0 76

						-attachForm $cbutton7 "top" 1
						-attachForm $cbutton7 "bottom" 1
						-attachPosition $cbutton7 "left" 0 78
						-attachPosition $cbutton7 "right" 0 88

						-attachForm $cbutton8 "top" 1
						-attachForm $cbutton8 "bottom" 1
						-attachPosition $cbutton8 "left" 0 88
						-attachPosition $cbutton8 "right" 0 98

						$formLayoutCtrl2;
				setParent ..;
			setParent ..;
		setParent ..;
		
		string $item = `itemFilter -bt Tropism -bt Branch -bt CurveNurbs -bt Hydra -bt Phyllotaxis -bt Variation -bt nurbsCurve -bt XfrogTransform`;
		string $outliner4 = `outlinerEditor`;		// hidden, just used to catch selected elements for the primitives-outliner
		outlinerEditor -edit
			-mainListConnection "modelList"
			-selectionConnection "XfObjectSelectionConnection"
			-showShapes false
			-showAttributes false
			-showConnected false
			-showAnimCurvesOnly false
			-autoExpand false
			-showDagOnly true
			-ignoreDagHierarchy false
			-expandConnections false
			-showCompounds true
			-showNumericAttrsOnly false
			-highlightActive true
			-autoSelectNewObjects false
			-doNotSelectNewObjects false
			-transmitFilters false
			-showSetMembers true
			-setFilter defaultSetFilter
			$outliner4; 
		string $paneLayout = `paneLayout -configuration "vertical3"`;
		string $outliner3 = `outlinerEditor`;			// global ref-outliner
		outlinerEditor -edit
			-mainListConnection "worldList"
			-selectionConnection "modelList"
			-showShapes false
			-showAttributes false
			-showConnected false
			-showAnimCurvesOnly false
			-autoExpand false
			-showDagOnly true
			-ignoreDagHierarchy false
			-expandConnections false
			-showCompounds true
			-showNumericAttrsOnly false
			-highlightActive true
			-autoSelectNewObjects false
			-doNotSelectNewObjects false
			-transmitFilters false
			-showSetMembers true
			-setFilter defaultSetFilter
			$outliner3;
		string $outliner = "XfPanelObjectOutliner";
		if(!`outlinerEditor -exists "XfPanelObjectOutliner"`) $outliner = `outlinerEditor "XfPanelObjectOutliner"`;	// XFObj-only-outliner
		else {
			deleteUI -editor $outliner;
			$outliner = `outlinerEditor "XfPanelObjectOutliner"`;
		}
		outlinerEditor -edit
			-mainListConnection "worldList"
			-selectionConnection "modelList"
			-showShapes false
			-showAttributes false
			-showConnected false
			-showAnimCurvesOnly false
			-autoExpand false
			-showDagOnly true
			-ignoreDagHierarchy false
			-expandConnections false
			-showCompounds true
			-showNumericAttrsOnly false
			-highlightActive true
			-autoSelectNewObjects false
			-doNotSelectNewObjects false
			-transmitFilters false
			-showSetMembers true
			-setFilter defaultSetFilter
			$outliner;
		outlinerEditor -edit -filter $item $outliner;
		string $outliner2 = "XfrogPanelPrimitivesOutliner";
		if(!`outlinerEditor -exists "XfrogPanelPrimitivesOutliner"`) $outliner2 = `outlinerEditor "XfrogPanelPrimitivesOutliner"`;
		else {
			deleteUI -editor $outliner2;
			$outliner2 = `outlinerEditor "XfrogPanelPrimitivesOutliner"`;
		}
		string $nullSel = `selectionConnection`;
		outlinerEditor -edit
			-mainListConnection $nullSel	
			-selectionConnection "modelList"
			-showShapes false
			-showAttributes false
			-showConnected false
			-showAnimCurvesOnly false
			-autoExpand true
			-showDagOnly true
			-ignoreDagHierarchy false
			-expandConnections false
			-showCompounds true
			-showNumericAttrsOnly false
			-highlightActive true
			-autoSelectNewObjects false
			-doNotSelectNewObjects false
			-transmitFilters false
			-showSetMembers true
			-setFilter defaultSetFilter
			$outliner2;
			
		formLayout -edit
			-attachForm $columnLayout "top" 1
			-attachForm $columnLayout "left" 1
			-attachForm $columnLayout "right" 1
			
			-attachControl $columnLayout2 "top" 1 $columnLayout
			-attachForm $columnLayout2 "left" 1
			-attachForm $columnLayout2 "right" 1
			
			-attachControl $paneLayout "top" 1 $columnLayout2
			-attachForm $paneLayout "left" 1
			-attachForm $paneLayout "right" 1
			-attachForm $paneLayout "bottom" 1

			-attachPosition $outliner4 "left" 0 0
			-attachPosition $outliner4 "right" 0 0
			-attachPosition $outliner4 "top" 0 0
			-attachPosition $outliner4 "bottom" 0 0
			
				$formLayout;
	}
	global proc xfvpRemoveCallback(string $panelName) {}
	global proc xfvpDeleteCallback(string $panelName) {}
	global proc xfvpSaveStateCallback(string $panelName) {}
	
	scriptedPanel -unParent -type xfvpScriptedPanelType -label "Xfrog4Maya" xfvpScriptedPanel;
}}
