<?xml version="1.0"?>
<rmml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="L:\collaborative-nir\program\Cscl3DWS\rmml\RMML.xsd">
	<!--
Example.
You can use Add function with string or image arrays, string and image objects
Function onSelected -

<composition _name="Selection1" _class="cVSelection">
<script>
	_x=189;
	_y=415;
	Add(new Array("1234","12222223"));

	function onSelected(itemNum, item)
	{
		trace("itemNum"+itemNum);
		hide_sel();
	}
</script>
</composition>
-->
	<composition _name="cSelection" _visible="false">
		<text _name="pathStub" value="eval(ENVRPATH)" visible="false" />
		<script><![CDATA[
		this.autoHide = false;
		this.autoHideDelay = 2000;
		this.vertical = 0; 						// Vertical selection?
		this.iPartWidth=0;
		this.iPartHeight=0;
		this.iNumOfItems=1;
// thickness of the lines
		this.iLThck=1;
// distance from selected background margins to the margins of the items
		szIMrgsW=2;
		szIMrgsH=1;
// distance from the selected background margins to the lines
		szSBLMrgsW=1;
		szSBLMrgsH=1;
// distance from the background margins to the lines
		szLMrgsW=1;
		szLMrgsH=1;
// distance from background margins to the margins of the selection background
		szSMrgsW=szSBLMrgsW+iLThck+szLMrgsW;
		szSMrgsH =szSBLMrgsH+iLThck+szLMrgsH;
// distance between the items ??
		szBetsW=8;
		szBetsH=8;
		bSelected=false;
// number of selected item (0..)
		iSelItemNum=0;
		bInSelZone=false;


		this.aItems = new Array;

		function Add(undefineObject)
		{
		if (typeof(undefineObject) == "object")
			{ if (undefineObject instanceof Array)
				{
					if (typeof(undefineObject[0])=="string")
						AddItemsText(undefineObject);
					else
						AddItemsObject(undefineObject);
					AddItems();
				}
				else
				{ AddItem(undefineObject);
				}
			}
		}

        function Clear()
        {
			var length=aItems.length;
			for (i=0; i<length; i++)
			aItems.pop();
		}


        function AddItem(object)
        { if (typeof(object) == "string")
			{
				AddTextItem(object);
			}
		  if (typeof(object) == "object")
			{
				AddObjectItem(object);
			}
		}

        function AddItemsText(array)
        {
			trace("AddItemsText");
			this.iNumOfItems=array.length;
			this.iIMaxW=0;
			this.iIMaxH=0; // maximum height of the items

			for (i=0; i<iNumOfItems; i++ )
			{
				//var VText = AddTextItem(array[i]);
				this.AddItem(array[i]);
			}

		}

		function AddTextItem(item)
        {
			var VText = new Text;
			VText.parent=this;
			VText.value=item;
			VText.style=stlTxPreview;
			VText.depth=-105;
			VText._height=VText.getMediaSize().height;
			VText._width=VText.getMediaSize().width;
			VText._visible=true;
			VText.enabled = false;
			VText.benabled = true;
			iIW=VText._width;
			iIH = VText._height;
			aItems.push(VText);
			if (iIW > this.iIMaxW) {this.iIMaxW=iIW;}
			if (iIH > this.iIMaxH){this.iIMaxH=iIH;}
			return VText;
		}

        function AddItemsObject(array)
        {
			this.iNumOfItems=array.length;
			this.iIMaxW=0;
			this.iIMaxH=0; // maximum height of the items

			for (i=0; i<iNumOfItems; i++ )
			{
				//this.AddObjectItem( array[i]);
				this.AddItem(array[i]);
			}
		}

		function AddObjectItem(item)
        {
			aItems.push(item)
			var rItem=item;
			if( rItem != null)
			rItem.benabled = true;
			iIW=rItem._width;
			iIH = rItem._height;
			if (iIW > this.iIMaxW) {this.iIMaxW=iIW;}
			if (iIH > this.iIMaxH){this.iIMaxH=iIH;}
		}

        function AddItems()
        {
// Select line
			imSelBck._x=szSMrgsW;
			imSelBck._y=szSMrgsH;
			imSelBck._width=iIMaxW+szIMrgsW*2;
			imSelBck._height=iIMaxH+szIMrgsH*2;

			iPartWidth=imSelBck._width+szSBLMrgsW*2+iLThck;
			iPartHeight=imSelBck._height+szSBLMrgsH*2+iLThck;

			if(vertical)
				{ imBCK._width=imSelBck._width+szSMrgsW*2;
				  imBCK._height=iPartHeight*iNumOfItems+(szLMrgsH+iLThck)*2-iLThck;
				}
			else{
				 imBCK._width=iPartWidth*iNumOfItems+(szLMrgsW+iLThck)*2-iLThck;
				 imBCK._height=imSelBck._height+szSMrgsH*2;
			}

			imRUC._x=imBCK._width-imRUC._width;
			imLDC._y=imBCK._height-imLDC._height;
			imRDC._x=imBCK._width-imRDC._width;
			imRDC._y=imBCK._height-imRDC._height;

			// create and move bets
			for (i=0; i<iNumOfItems; i++)
			{	if(vertical)
				  {
					// left bet
					var lBet = new Image;
					lBet._name="imLB"+(i+1);
					//lBet.src="rmgr:Select\imLB.png";
					lBet.src=this.pathStub.value + "Select\\imLB.png";
					lBet._depth=-100;
					lBet._y=iPartHeight*(i+1)-(lBet._height/2)+szSMrgsH-2;

					// right bet
					var rBet = new Image;
					rBet._name="imRB"+(i+1);
					//rBet.src="rmgr:Select\imRB.png";
					rBet.src=this.pathStub.value + "Select\\imRB.png";
					rBet._depth=-100;
					rBet._x=imBCK._width-rBet._width;
			  }
			  else
			  {
					// up bet
					var uBet = new Image;
					uBet._name="imUB"+(i+1);
					//uBet.src="rmgr:Select\imUB.png";
					uBet.src=this.pathStub.value + "Select\\imUB.png";
					uBet._depth=-100;
					uBet._x=iPartWidth*(i+1)-(uBet._width/2)+szSMrgsW-2;

					// down bet
					var dBet = new Image;
					dBet._name="imDB"+(i+1);
					//dBet.src="rmgr:Select\imDB.png";
					dBet.src=this.pathStub.value + "Select\\imDB.png";
					dBet._depth=-100;
					dBet._x=uBet._x;
					dBet._y=imBCK._height-dBet._height;
			  }
			}
			MoveItems();
		}

    // move items
		function MoveItems()
		{
trace("----------MoveItems-----------------\n");
			for (i=0; i<iNumOfItems; i++)
			{   rItem=aItems[i];
				if(vertical)
				{
					rItem._y=szSMrgsH+i*iPartHeight+(iPartHeight-rItem._height)/2-1;
					rItem._x=imBCK._width/2-rItem._width/2;
				}
				else
				{
					rItem._x=szSMrgsW+i*iPartWidth+(iPartWidth-rItem._width)/2;
					rItem._y=imBCK._height/2-rItem._height/2;
				}
				if (rItem instanceof Image && rItem.parent!=this)
				{
					rItem._x+=_x;
					rItem._y+=_y;
				 }
				 else
				 { 	//rItem._y-=7 ;
					//rItem._x+=7 ;
				 }
				  rItem._depth=-105;

			}
		}

  function UpdateInSel() {
    iInSelNum=0;
    if(_xmouse > 0)
    {
		  if(vertical){      iInSelNum=(_ymouse)/iPartHeight;    }
		 else		  {      iInSelNum=(_xmouse)/iPartWidth;     }

		if(iInSelNum < 0)	{ iInSelNum=0;}
        if(iInSelNum > (iNumOfItems-1)){ iInSelNum=iNumOfItems-1; }
    }
    else{
      iInSelNum=iSelItemNum;
      if(!bSelected){ iInSelNum=-1; }
    }

	iInSelNum=Math.floor(iInSelNum);
    if(iInSelNum>=0 && iInSelNum<iNumOfItems && aItems[iInSelNum].benabled){
      if(vertical){
		imSelBck._y=szSMrgsH+iInSelNum*iPartHeight;
		imSelBck._visible=true
      }
      else{
		imSelBck._x=szSMrgsW+iInSelNum*iPartWidth;;
		imSelBck._visible=true
      }
    }
   else	{   imSelBck._visible=false;   }
//   imBCK.useHandCursor = imSelBck.visible;
  }

  function select(iItem) {
    iSelItemNum=iItem-1;
    bSelected=true;
    UpdateInSel();
  }

  function deselect()
   {
    bSelected=false;
    UpdateInSel();
  }

  function disable_i(item) {

				var rItem=aItems[item];
				rItem.benabled=false;
	}

  function hide_sel()
   {
    _visible=false;
			for (i=0; i<iNumOfItems; i++)
			{	var rItem=aItems[i];
				rItem._visible=false;
			}
  }

  function show_sel()
   {
    MoveItems();
	_visible=true;
	for (i=0; i<iNumOfItems; i++)
	{	var rItem=aItems[i];
		rItem._visible=true;
	}
	if( this.autoHide)
	{
		this.seqAutoHide.rewindAndPlay();
	}
  }

		]]></script>
		<button _name="deselect_item" depth="-100" x="0" enabled="false" visible="false"/>
		<styles _name="stlTxPreview" fontSize="14" fontFamily="Microsoft Sans Serif" fontWeight="bold" textAlign="eval(SELTEXTCOLOR)" color="#FFFFFF"/>
		<image _name="imBCK" src="eval(ENVRPATH+'Select\\imBCK.png')" _depth="-98"/>
		<image _name="imSelBck" src="eval(ENVRPATH+'Select\\imSelBck.png')" _depth="-99" enabled="false"/>
		<image _name="imLUC" src="eval(ENVRPATH+'Select\\imLUC.png')" _depth="-100"/>
		<image _name="imRUC" src="eval(ENVRPATH+'Select\\imRUC.png')" _depth="-100"/>
		<image _name="imLDC" src="eval(ENVRPATH+'Select\\imLDC.png')" _depth="-100"/>
		<image _name="imRDC" src="eval(ENVRPATH+'Select\\imRDC.png')" _depth="-100"/>
		<image _name="imRDC" src="eval(ENVRPATH+'Select\\imRDC.png')" _depth="-100"/>
		<script event="imBCK.onRollOver">
			bInSelZone=true;
			UpdateInSel();
	 </script>
		<script event="onMouseUp">
			fireEvent("imBCK.onPress");
		</script>
		<script event="imBCK.onPress"><![CDATA[
		if(vertical)
		{
			iSelItemNum=(_ymouse)/iPartHeight;
		}
		else
		{
			iSelItemNum=(_xmouse)/iPartWidth;
		}
		iSelItemNum=Math.floor(iSelItemNum);
        bSelected=true;
		UpdateInSel();
//trace(iSelItemNum+":"+iNumOfItems+":"+aItems[iSelItemNum].benabled);
		if(iSelItemNum>=0 && iSelItemNum<iNumOfItems && aItems[iSelItemNum].benabled)
		{
			onSelected(iSelItemNum, aItems[iSelItemNum]);
		}
	 ]]></script>
		<script event="imBCK.onRollOut">
			bInSelZone=false;
			UpdateInSel();
			if( this.autoHide)
			{
				this.seqAutoHide.rewindAndPlay();
			}
	 </script>
		<script event="imBCK.onMouseMove">
			if(bInSelZone)
			{
				this.seqAutoHide.stop();
				UpdateInSel();
			}
	 </script>
	 <sequencer name="seqAutoHide">
		<script>
			this.autoHideDelay;
		</script>
		<script>
			this.hide();
		</script>
	 </sequencer>
	</composition>
	<composition _name="cVSelection" _class="cSelection" _visible="false">
		<script>
			vertical=true;
		</script>
	</composition>
</rmml>
