<?xml version="1.0" encoding="win1251"?>
<rmml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="L:\collaborative-nir\program\Cscl3DWS\rmml\RMML.xsd">
	<styles name="TableTitleStyle" fontWeight="bold" textAlign="center" fontSize="16" fontFamily="Arial" color = "#BA2F1A"/>
	<composition name="CBackground" class="CResizablePaper">
		<image _name="lt" src=":rmgr:frames/infoframe.png">
			<script>this.crop(0,0,12,12);</script>
		</image>
		<image _name="ct" src=":rmgr:frames/infoframe.png">
			<script>this.crop(12,0,1,12);</script>
		</image>
		<image _name="rt" src=":rmgr:frames/infoframe.png">
			<script>this.crop(13,0,3,12);</script>
		</image>
		<image _name="lc" src=":rmgr:frames/infoframe.png">
			<script>this.crop(0,12,12,1);</script>
		</image>
		<image _name="cc" src=":rmgr:frames/infoframe.png">
			<script>this.crop(12,12,1,1);</script>
		</image>
		<image _name="rc" src=":rmgr:frames/infoframe.png">
			<script>this.crop(13,12,3,1);</script>
		</image>
		<image _name="lb" src=":rmgr:frames/infoframe.png">
			<script>this.crop(0,13,12,3);</script>
		</image>
		<image _name="cb" src=":rmgr:frames/infoframe.png">
			<script>this.crop(12,13,1,3);</script>
		</image>
		<image _name="rb" src=":rmgr:frames/infoframe.png">
			<script>this.crop(13,13,3,3);</script>
		</image>
	</composition>

	<composition name="CTarget" class="CResizablePaper">
		<image _name="lt" src=":rmgr:frames/targetramka.png">
			<script>this.crop(0,0,1,1);</script>
		</image>
		<image _name="ct" src=":rmgr:frames/targetramka.png">
			<script>this.crop(1,0,1,1);</script>
		</image>
		<image _name="rt" src=":rmgr:frames/targetramka.png">
			<script>this.crop(2,0,1,1);</script>
		</image>
		<image _name="lc" src=":rmgr:frames/targetramka.png">
			<script>this.crop(0,1,1,1);</script>
		</image>
		<image _name="cc" src=":rmgr:frames/targetramka.png">
			<script>this.crop(1,1,1,1);</script>
		</image>
		<image _name="rc" src=":rmgr:frames/targetramka.png">
			<script>this.crop(2,1,1,1);</script>
		</image>
		<image _name="lb" src=":rmgr:frames/targetramka.png">
			<script>this.crop(0,2,1,1);</script>
		</image>
		<image _name="cb" src=":rmgr:frames/targetramka.png">
			<script>this.crop(1,2,1,1);</script>
		</image>
		<image _name="rb" src=":rmgr:frames/targetramka.png">
			<script>this.crop(2,2,1,1);</script>
		</image>
	</composition>

	<composition name="CTableDragTarget" useHandCursor="false">
		<composition name="bckgr" class="CBackground"/>
		<composition name="TargetPos" class="CTarget" visible="false" y="30"/>
		<text name="Title" style="TableTitleStyle" y="10"/>
		<script><![CDATA[
			this.imCount = 0;
			function init(width, height, title)
			{
				this.bckgr.resize(width, height);
				if (title != undefined)
				{
					this.Title.value = title;
				}
				if (this.Title.width > width)
				{
					this.Title.width = width - 10;
					this.Title.height = 40;
					this.TargetPos.y = 50;
					parent.notOneString = true;
				}
				this.Title.x = (width-this.Title.width)/2;
			}
			function addImage(src)
			{
				var im = new Image;
				im.name = "im"+this.imCount++;
				im.src = src;
				im.parent = this;
				im.x = this.TargetPos.x + (this.TargetPos.width-im.width)/2;
				im.y = this.TargetPos.y;
				this.TargetPos.y+=(im.height+10);
			}

			function changeImage(src)
			{
				if (this.im == undefined)
				{
					var im = new Image;
					im.name = "im";
					im.parent = this;
				}
				this.im.src = src;
				this.im.x = this.TargetPos.x;
				this.im.y = this.TargetPos.y;
				this.im.width = this.TargetPos.realWidth;
				this.im.height = this.TargetPos.realHeight;
			}

			function showTargetPos()
			{
				var width = parent.DragItem.im.getMediaSize().width;
				var height = parent.DragItem.im.getMediaSize().height;
				if (parent.DragItem.im.getMediaSize().width > (this.bckgr.width - 6))
				{
					width = this.bckgr.width - 6;
					height = Math.round(width / parent.DragItem.im.getMediaSize().width * parent.DragItem.im.getMediaSize().height);
				}
				else if (parent.DragItem.im.getMediaSize().height > (this.bckgr.height - this.TargetPos.y - 5))
				{
					height = this.bckgr.height - this.TargetPos.y - 5;
					width = Math.round(height / parent.DragItem.im.getMediaSize().height * parent.DragItem.im.getMediaSize().width);

				}
				this.TargetPos.resize(width,height);
				this.TargetPos.realWidth = width;
				this.TargetPos.realHeight = height;
				this.TargetPos.x = (this.bckgr.width - width)/2 - 1;
				this.TargetPos.show();
			}
		]]></script>
	</composition>

	<button name="CTargetZone" depth="-100" useHandCursor="false">
		<script>
			this.id = 0;
		</script>
		<script event="onRollOver">
			trace("onRollOver");
			if (parent.drag)
			{
				trace(this.id+"@@@@@   "+eval("parent.target"+this.id));
				parent.selectedTarget = eval("parent.target"+this.id);
				parent.selectedTarget.showTargetPos();
			}
		</script>
		<script event="onRollOut">
			trace("onRollOut");
			if (parent.selectedTarget != null)
			{
				parent.selectedTarget.TargetPos.hide();
				parent.selectedTarget = null;
			}
		</script>
	</button>

	<composition name="CDragItem" class="CDraggableComposition" depth="-10">
		<image name="im" src=""/>
		<script><![CDATA[
			function init(src,rightPos)
			{
				this.rightPos=rightPos;
				this.im.src = src;
				this.im.width = this.im.getMediaSize().width;
				this.im.height = this.im.getMediaSize().height;
				this.addHotspot(im);
			}
			
			this.acceptMoveBy = function(dx, dy)
			{
				var obj = new Object;
				obj.x = dx;
				obj.y = dy;
				if( this._x + this._width + dx > 1000)
					obj.x = 1000 - (this._x + this._width);
				if( this._x + dx < 10)
					obj.x = -this._x;
				if( this._y + this._height + dy > 580)
					obj.y = 580 - (this._y + this._height);
				if( this._y + dy < 30)
					obj.y = -this._y;
				return obj;
			}
		]]></script>
		<script event="onDragStart">
			parent.onDragStart(this);
		</script>
		<script event="onDragEnd"><![CDATA[
			this.x = this.homeX;
			this.y = this.homeY;
			parent.onDragEnd(this);
		]]></script>
	</composition>

	<composition name="CDragTable" userEvents="OnSuccessDrag">
		<composition name="chintText" class="CHint" visible="true">
				<text name="itext" width="360">Перетащите формулу в соответствующую ячейку</text>
		</composition>
		<composition name="DragItem" class="CDragItem"/>
		<script><![CDATA[
			this.selectedTarget = null;
			this.numDragItems = 0;
			this.srcDragItems = new Array;
			this.posDragItems = new Array;
			this.smallSrcDragItems = new Array;
			this.drag = false;
			this.columnsNumber = 0;
			this.startY = 0;
			this.topSpace = 0;
			this.notOneString = false;
			function addDragItem(src,pos,smallSrc)
			{		trace('1--------------');
				this.srcDragItems.push(src);
				this.posDragItems.push(pos);
				if (smallSrc != undefined)
					this.smallSrcDragItems.push(smallSrc);
				this.setDragItem(this.numDragItems);
				this.numDragItems++;
			}

			function setDragItem(id)
			{
				trace('2---------');
				trace("!!!!!!!!!!!!!!!!"+id);
				this.DragItem.init(this.srcDragItems[id],this.posDragItems[id]);
				this.DragItem.id=id;
				this.DragItem.x = (this.maxWidth-this.DragItem.width)/2;
				this.DragItem.homeX = (this.maxWidth-this.DragItem.width)/2;
				this.DragItem.y = this.startY;
				this.DragItem.homeY = this.startY;
			}

			function addColumns(width,height,num, names, dragItemSpace)
			{trace('3---------');
				var columnWidth = 0;
				if (dragItemSpace == undefined)
					dragItemSpace = 120;
				var xpos = 0;
				this.realWidth = width;
				this.realHeight = height;
				this.maxWidth = width;
				this.startY = 0;
				width-=((num-1)*5);
				for (var ii = 0; ii<num; ii++)
				{
					var col = new Composition;
					col.name = "target"+ii;
					col.id = ii;
					col._class = "CTableDragTarget";
					col.parent = this;
					col.init(width/num,height - dragItemSpace,names[ii]);
					col.x = xpos;
					col.y = dragItemSpace;
					var colbtn = new Button;
					colbtn.name = "targetZone"+ii;
					colbtn._class = "CTargetZone";
					colbtn.parent = this;
					colbtn.id = ii;
					colbtn.x = xpos;
					colbtn.y = dragItemSpace;
					colbtn.width = width/num;
					colbtn.height = height - dragItemSpace;
					xpos+=(width/num+5);
					this.columnsNumber++;
				}
				if (this.notOneString)
				{
					for (var ii = 0; ii<num; ii++)
					{
						eval("this.target"+ii+".TargetPos.y = 50;");
					}
				}
				this.chintText.x = (width - this.chintText.width) / 2;
				this.chintText.y = height + 5;
			}

			function onDragStart()
			{trace('4---------');
				this.drag = true;
			}

			function onDragEnd(item)
			{trace('5---------');
				if (this.selectedTarget != null && item.rightPos[this.selectedTarget.id] == 1)
				{
					var src = this.smallSrcDragItems[item.id];
						if (this.smallSrcDragItems[item.id] == undefined)
							src = item.im.src;
						this.selectedTarget.addImage(src);
					item.rightPos[this.selectedTarget.id] = 0;
					var pp = false;
					for (var jj = 0; jj < this.columnsNumber; jj++)
					{
						if (item.rightPos[jj] == 1)
							pp = true;
					}
					if (!pp)
					{
						this.numDragItems--;
						if(this.numDragItems != 0)
							this.setDragItem(this.numDragItems-1);
						else
						{
							item.im.enabled = false;
							for (var ii = 0; ii < this.columnsNumber; ii++)
							{
								eval("this.target"+ii+".init(this.realWidth/this.columnsNumber,this.realHeight-this.topSpace);");
								eval("this.target"+ii+".y = this.topSpace;");
							}
							item.parent = null;
						}
						fireEvent("OnSuccessDrag");
					}
				}
				this.drag = false;
				if (this.selectedTarget != null)
				{
					this.selectedTarget.TargetPos.hide();
					this.selectedTarget = null;
				}
			}
		]]></script>
	</composition>
	<styles name="LabelTextStyle"  fontSize="18" fontWeight="bold" color = "#16416E"/><!-- color = "#0069A5"/> -->

	<composition name="CDragTablePract">
		<text name="questTitle" style="LabelTextStyle">Осталось:</text>
		<text name="answTitle" style="LabelTextStyle">Правильно:</text>
		<text name="questCount" style="LabelTextStyle"/>
		<text name="answCount" style="LabelTextStyle">0</text>

		<image name="questions" src=":rmgr:frames/counter.png">
			<script><![CDATA[
				this.crop(0,0,400,75);
			]]></script>
		</image>

		<image name="answers" src=":rmgr:frames/counter.png">
			<script><![CDATA[
				this.crop(0,0,400,0);
			]]></script>
		</image>

		<composition name="chintText" class="CHint" visible="true">
				<text name="itext" width="360">Перетащите формулу в соответствующую ячейку</text>
		</composition>
		<composition name="DragItem" class="CDragItem"/>
		<script><![CDATA[
			this.selectedTarget = null;
			this.numDragItems = 0;
			this.questNum = 0;
			this.answNum = 0;
			this.srcDragItems = new Array;
			this.smallSrcDragItems = new Array;
			this.posDragItems = new Array;
			this.drag = false;
			this.columnsNumber = 0;
			this.dragItemStartY = 64;
			this.DragItem.y = this.dragItemStartY;
			this.DragItem.homeY = this.dragItemStartY;
			this.columnsStartY = 0;
			this.notOneString = false;
			this.maxWidth = 0;
			this.notOne = false;

			function addDragItem(src,pos,smallSrc)
			{		trace('1--------------');
				this.srcDragItems.push(src);
				this.smallSrcDragItems.push(smallSrc);
				this.posDragItems.push(pos);
				this.setDragItem(Math.round(Math.random()*(this.numDragItems)));
				this.numDragItems++;
/*				for (var jj=0; pos[jj] != undefined; jj++)
				{
					if (pos[jj] == 1)
					{*/
						this.questNum++;

						this.chintText.y = this.columnsStartY+this.questNum*3+5;
						this.answTitle.y = this.chintText.y - 5 - this.answTitle.height;
						this.answCount.y = this.chintText.y - 5 - this.answTitle.height;

						this.questCount.value = this.questNum;
						this.questions.crop(0,0,400,this.questNum*3);
						this.answers.visible=false;

						this.questions.y = this.dragItemStartY - this.questions.height - 10;
						this.answers.y = this.chintText.y - 5 - this.answers.height;

						this.questTitle.y = this.questions.y;
						this.questCount.y = this.questTitle.y;
					//}
				//}
			}

			function setDragItem(id)
			{
				trace('2---------');
				trace("!!!!!!!!!!!!!!!!"+id);
				this.DragItem.init(this.srcDragItems[id],this.posDragItems[id]);
				this.DragItem.id = id;
				this.DragItem.x = (this.maxWidth-this.DragItem.width)/2;
				this.DragItem.homeX = (this.maxWidth-this.DragItem.width)/2;
			}

			function addColumns(width,height,num, names, dragItemSpace)
			{trace('3---------');
				var columnWidth = 0;
				if (dragItemSpace != undefined)
					this.dragItemSpace = dragItemSpace;
				if (this.dragItemSpace == undefined)
					this.dragItemSpace = 170;
				if (this.columnsStartY == 0)
					this.columnsStartY = this.dragItemSpace+30;
				if (this.maxWidth < width)
					this.maxWidth = width;
				var xpos = (this.maxWidth - width) / 2;
				width-=((num-1)*5);
				for (var ii = 0; ii<num; ii++)
				{
					var col = new Composition;
					col.name = "target"+(ii+this.columnsNumber);
					col.id = (ii+this.columnsNumber);
					col._class = "CTableDragTarget";
					col.parent = this;
					col.init(width/num,height,names[ii]);
					col.x = xpos;
					col.y = this.columnsStartY;
					var colbtn = new Button;
					colbtn.name = "targetZone"+(ii+this.columnsNumber);
					colbtn._class = "CTargetZone";
					colbtn.parent = this;
					colbtn.id = (ii+this.columnsNumber);
					colbtn.x = xpos;
					colbtn.y = this.columnsStartY;
					colbtn.width = width/num;
					colbtn.height = height;
					xpos+=(width/num+5);
				}
				if (this.notOneString)
				{
					for (var ii = 0; ii<num; ii++)
					{
						eval("this.target"+ii+".TargetPos.y = 50;");
					}
				}
				this.columnsNumber += num;
				this.columnsStartY = this.columnsStartY + height + 5;
				this.chintText.x = (this.maxWidth - this.chintText.width) / 2;
				this.chintText.y = this.columnsStartY+80;
				this.questions.x = (this.maxWidth - this.questions.width) / 2;
				this.questTitle.x = this.questions.x - 140 ;
				this.answers.x = (this.maxWidth - this.answers.width) / 2;
				this.answTitle.x = this.answers.x - 145 ;
				this.answTitle.y = this.chintText.y - 5 - this.answTitle.height;
				this.answCount.y = this.chintText.y - 5 - this.answTitle.height;
				this.answCount.x = this.answers.x - 30;
				this.questCount.x = this.questions.x - 40;
			}

			function onDragStart()
			{trace('4---------');
				this.drag = true;
			}

			function onDragEnd(item)
			{trace('5---------');
				if (this.selectedTarget != null)
				{
					if (item.rightPos[this.selectedTarget.id] == 1)
					{
						trace(this.smallSrcDragItems[item.id]+" ################# "+item.im.src);
						var src = this.smallSrcDragItems[item.id];
						if (this.smallSrcDragItems[item.id] == undefined)
							src = item.im.src;
						this.selectedTarget.changeImage(src);
						item.rightPos[this.selectedTarget.id] = 0;
						var pp = false;
						for (var jj = 0; jj < this.columnsNumber; jj++)
						{
							if (item.rightPos[jj] == 1)
							{
								pp = true;
								this.notOne = true;
							}
						}
						if (!pp)
						{
							this.notOne = false;
							if(this.numDragItems > 1)
							{
								var num = item.id;
								var k = 0;
								for (var i = 0; i<num; i++)
								{
									this.srcDragItems[k] = this.srcDragItems[i];
									this.posDragItems[k] = this.posDragItems[i];
									this.smallSrcDragItems[k] = this.smallSrcDragItems[i];
									k++;
								}
								for (i = num+1; i<(this.numDragItems); i++)
								{
									this.srcDragItems[k] = this.srcDragItems[i];
									this.posDragItems[k] = this.posDragItems[i];
									this.smallSrcDragItems[k] = this.smallSrcDragItems[i];
									k++;
								}
								this.srcDragItems.length--;
								this.numDragItems--;
							}
							this.questNum--;
							this.answNum++;
							this.questions.crop(0,0,400,this.questNum*3);
							if (this.questNum==0)	{this.questions.height=0;}

							this.questCount.value = this.questNum;
							this.answers.crop(0,0,400,this.answNum*3);
							this.answers.visible=true;

							this.answers.y = this.chintText.y - 5 - this.answers.height;
							this.answCount.value = this.answNum;
						}
					}
					if (!notOne)
						if (this.questNum > 0)
						{
							trace("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RESET");
							this.setDragItem(Math.round(Math.random()*(this.numDragItems-1)));
						}
						else
						{
							item.im.enabled = false;
							item.parent = null;
						}
				}
				this.drag = false;
				if (this.selectedTarget != null)
				{
					this.selectedTarget.TargetPos.hide();
					this.selectedTarget = null;
				}
			}
		]]></script>
	</composition>
	<composition name="CAnswersRom" visible="false" depth="-100">
		<script>
			this.itemsCount = 0;
			function addItem(item,x,y)
			{
				this.itemsCount++;
				item.name="item" + this.itemsCount;
				item.parent = this;
				item.x = x - item.width / 2;
				item.y = y - item.height / 2;
				item.depth = -1;
				item.show();
			}
		</script>
	</composition>
	<composition name="CDragRom">
		<image name="imTitle" y="165" x="90"/>
		<animation name="anhelp" src=":rmgr:interactive/dragHelp.fln" playing="true" loop="true"/>
		<composition name="hintText" class="CHint" visible="true" y="450">
			<text name="itext" width="310"></text>
			<script>
				this.x = (parent.width - this.itext.width) / 2 + 50;
			</script>
		</composition>
		<composition name="target0">
			<composition name="TargetPos" class="CTarget" visible="false"/>
			<image name="im" src=""/>
			<script>
				this.maxWidth = 0;
				this.maxHeight = 0;
				function init(x,y,width,height)
				{
					this.x = x;
					this.y = y;
					this.maxWidth = width;
					this.maxHeight = height;
				}

				function showTargetPos()
				{
					this.TargetPos.resize(parent.DragItem.im.getMediaSize().width, parent.DragItem.im.getMediaSize().height);
					this.TargetPos.x = (this.maxWidth - parent.DragItem.im.getMediaSize().width)/2;
					this.TargetPos.y = (this.maxHeight - parent.DragItem.im.getMediaSize().height)/2;
					this.TargetPos.show();
				}
			</script>
		</composition>
		<button name="TargetZone" class="CTargetZone"/>
		<script><![CDATA[
			this.dragItemsCount = 0;
			this.drag = false;
			this.DragItem = null;

			function initTargetZone(x,y,width,height)
			{
				this.TargetZone.x = x;
				this.TargetZone.y = y;
				this.TargetZone.width = width;
				this.TargetZone.height = height;
				this.target0.init(x,y,width,height);
				this.anhelp.x = x + (width - this.anhelp.width) / 2;
				this.anhelp.y = y + (height - this.anhelp.height) / 2;
			}

			function addDragItem(src,x,y)
			{
				this.dragItemsCount++;
				var dragItem = new Composition;
				dragItem.name = "DragItem" + this.dragItemsCount;
				dragItem._class = "CDragItem";
				dragItem.parent = this;
				dragItem.x = x - dragItem.width / 2;
				dragItem.homeX = x - dragItem.width / 2;
				dragItem.y = y - dragItem.height / 2;
				dragItem.homeY = y - dragItem.height / 2;
				dragItem.id = this.dragItemsCount;
				eval("this.DragItem"+this.dragItemsCount+".init(src);");

				var aRom = new Composition;
				aRom.name = "Answers" + this.dragItemsCount;
				aRom._class = "CAnswersRom";
				aRom.parent = this;
			}

			function onDragStart(DragItem)
			{
				if (this.DragItem != null)
				{
					this.DragItem.x = this.DragItem.homeX;
					this.DragItem.y = this.DragItem.homeY;
					this.DragItem.enabled = true;
					eval("this.Answers"+this.DragItem.id+".hide();");
				}
				this.DragItem = DragItem;
				this.imTitle.y = 165;
				this.anhelp.show();
				this.drag = true;
			}

			function onDragEnd()
			{
				this.target0.TargetPos.hide();
				this.drag = false;
				if (this.selectedTarget != null)
				{
					this.anhelp.hide();
					this.imTitle.y = this.imTitle.y - 25;
					/*this.target0.im.src = this.DragItem.im.src;
					this.target0.im.width = this.DragItem.im.width;
					this.target0.im.height = this.DragItem.im.height;
					this.target0.im.x = this.target0.TargetPos.x;
					this.target0.im.y = this.target0.TargetPos.y;
					this.target0.im.show();*/
					this.DragItem.x = this.target0.TargetPos.x + this.target0.x;
					this.DragItem.y = this.target0.TargetPos.y + this.target0.y;
					this.DragItem.enabled = false;
					for (var jj = 1; eval("this.Answers"+jj) != undefined; jj++)
					{
						eval("this.Answers"+jj+".hide();");
					}
					eval("this.Answers"+this.DragItem.id+".show();");

				}
			}
		]]></script>
	</composition>

	<composition name="CDragTarget">
		<composition name="bckgr" class="CBackground"/>
		<composition name="TargetPos" class="CTarget" visible="false"/>
		<text name="Title" style="TableTitleStyle" y="10"/>
		<script><![CDATA[
			function init(width, height, title, type)
			{
				this.bckgr.resize(width, height);
				this.TargetPos.resize(width-2, height-2);
				if (title != undefined)
				{
					this.Title.value = title;
				}
				if (this.Title.width > width)
				{
					this.Title.width = width - 10;
					this.Title.height = 35;
					parent.notOneString = true;
				}
				this.Title.x = (width-this.Title.width)/2;
				this.Title.y = (height-this.Title.height)/2;
				this.imPos = type;
			}			
			function setImage(src)
			{
				var x = this.bckgr.x + this.bckgr.width / 2;
				var y = this.bckgr.y + this.bckgr.height / 2;
				if (this.im == undefined)
				{
					var im = new Image;
					im.name = "im";
					im.parent = this;					
				}
				this.im.src = src;
				switch(this.imPos)
				{
					case "top": y -= (this.bckgr.height / 2 + 10 + this.im.height); x -= (this.im.width / 2); break;
					case "bottom": y += (this.bckgr.height / 2 + 10); x -= (this.im.width / 2); break;
					case "left": x -= (this.bckgr.width / 2 + 10 + this.im.width); y -= (this.im.height / 2); break;
					case "right": x += (this.bckgr.width / 2 + 10); y -= (this.im.height / 2); break;
				}
				this.im.x = x;
				this.im.y = y;
			}
			function showTargetPos()
			{
				this.TargetPos.show();			
			}
		]]></script>
	</composition>
	
	<composition name="CDragTable2">	
		<composition name="DragItem" class="CDragItem"/>
		<script><![CDATA[
			this.selectedTarget = null;
			this.numDragItems = 0;
			this.numTargets = 1;
			this.srcDragItems = new Array;
			this.smallSrcDragItems = new Array;
			this.posDragItems = new Array;
			this.drag = false;
			this.dragItemPosX = 0;
			this.dragItemPosY = 0;
			
			function addDragItem(src, pos, smallSrc)
			{
				this.srcDragItems.push(src);
				this.posDragItems.push(pos);
				this.smallSrcDragItems.push(smallSrc);
				this.setDragItem(Math.round(Math.random()*(this.numDragItems)));
				this.numDragItems++;
			}
			
			function setDragItemPos(x,y)
			{
				this.dragItemPosX = x;
				this.dragItemPosY = y;
			}
			
			function setDragItem(id)
			{
				this.DragItem.init(this.srcDragItems[id],this.posDragItems[id]);
				this.DragItem.id = id;
				this.DragItem.x = this.dragItemPosX - this.DragItem.width / 2;
				this.DragItem.homeX = this.dragItemPosX - this.DragItem.width / 2;
				this.DragItem.y = this.dragItemPosY - this.DragItem.height / 2;
				this.DragItem.homeY = this.dragItemPosY - this.DragItem.height / 2;
			}			
			
			function addTarget(name, impos, x, y, width, height)
			{
				var target = new Composition;
				target.name = "target"+this.numTargets;
				target._class = "CDragTarget";
				target.parent = this;
				target.id = this.numTargets;
				target.init(width,height,name,impos);
				target.imPos = impos;
				target.x = x;
				target.y = y;
				var targetZone = new Button;
				targetZone.name = "targetZone"+this.numTargets;
				targetZone._class = "CTargetZone";
				targetZone.parent = this;
				targetZone.id = this.numTargets;
				targetZone.x = x;
				targetZone.y = y;
				targetZone.width = width;
				targetZone.height = height;				
				this.numTargets++;
			}
			
			function onDragStart(dragItem)
			{
				this.drag = true;
			}
			
			function onDragEnd(item)
			{
				trace(item.rightPos+"!!!!!!!!!!!!!!!!!!!!!!!!!"+this.selectedTarget.id);
				if (this.selectedTarget != null && item.rightPos == this.selectedTarget.id)
				{
					var src = this.smallSrcDragItems[item.id];
					if (this.smallSrcDragItems[item.id] == undefined)
							src = item.im.src;
					this.selectedTarget.setImage(src);
					if(this.numDragItems > 0)
					{
						var num = item.id;
						var k = 0;
						for (var i = 0; i<num; i++)
						{
							this.srcDragItems[k] = this.srcDragItems[i];
							this.posDragItems[k] = this.posDragItems[i];
							this.smallSrcDragItems[k] = this.smallSrcDragItems[i];
							k++;
						}
						for (i = num+1; i<(this.numDragItems); i++)
						{
							this.srcDragItems[k] = this.srcDragItems[i];
							this.posDragItems[k] = this.posDragItems[i];
							this.smallSrcDragItems[k] = this.smallSrcDragItems[i];
							k++;								
						}
						this.srcDragItems.length--;
						this.smallSrcDragItems.length--;
						this.posDragItems.length--;
						this.numDragItems--;
					}
				}
				if (this.numDragItems > 0)
						this.setDragItem(Math.round(Math.random()*(this.numDragItems-1)));
        else
            item.parent = null;
				this.drag = false;
				if (this.selectedTarget != null)
				{
					this.selectedTarget.TargetPos.hide();
					this.selectedTarget = null;
				}				
			}
		]]></script>
	</composition>

</rmml>
