<?xml version="1.0" encoding="UTF-8"?>
<rmml>

<composition name="rnmc_stdDraglist" class="rnmc_stdMediaGroup">
<script><![CDATA[

// ======================================================================
// 			настройки
// ======================================================================
//	порядок выстраивания объектов (vertical, horizontal)
	this.order = AUTOATTACH_BOTTOM_LEFT; //AUTOATTACH_RIGHT_TOP;
//	момент проверки правильности устаноки объекта (after, immediately)
	this.checkMode = DRAGGING_CHECK_IMMEDIATELY; //DRAGGING_CHECK_AFTER;

//	чувствительность по умолчанию
	this.sensitivity = 20;

//	скорость движения
	this.flowdelta = 15;
	
//	порядок выстраивания
	this.showOrder = null;

//	смещение элементов друг от друга
	this.offsetX = 0;
	this.offsetY = 0;
	
//	max щирина и высота из элементов объекта
	this.maxWidth = 0;
	this.maxHeight = 0;
	
//	кол-во правильных ответов и неправильных ответов (при провреке сразу - суммируются)
	this.nRight = 0;
	this.nError = 0;
//	проверялось или нет (при проверке после расстановки)
	this.checked = false;
	
//	рехультаты
	var results;
   	results = new scene.Utils.resultParam();
	results.init();
	
//	массив переставляемых элементов объекта
	this.draglist = null;

//	границы рабочей области
/*	this.minDraggingBoundX = 0;
	this.maxDraggingBoundX = Player.module.scenes.width;
	this.minDraggingBoundY = 0;
	this.maxDraggingBoundY = Player.module.scenes.height;*/

	function initFromNode(srcNode, useDelayLoad){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;
		this.draglist = new Array();

		xmlAttributeMap = srcNode.attributes;
		if (xmlAttributeMap){
			xmlAttribute = xmlAttributeMap.getNamedItem("id");
			if (xmlAttribute != null && xmlAttribute.specified){
				this.id = xmlAttribute.value;
			}
			xmlAttribute = xmlAttributeMap.getNamedItem("visible");
			if (xmlAttribute != null && xmlAttribute.specified){
				if(xmlAttribute.value.toLowerCase() == "true")
					this.visibility = OBJECT_VISIBILITY_TRUE;
				else if(xmlAttribute.value.toLowerCase() == "false")
					this.visibility = OBJECT_VISIBILITY_FALSE;
			}
		}
		
		xmlNode = srcNode.firstChild;

		while(xmlNode){

			if(xmlNode.nodeName == "param"){

			// разбор стандартных настроек
				this.parseParamNode(xmlNode);

			// разбор специфичных настроек
				xmlAttributeMap = xmlNode.attributes;
				if (xmlAttributeMap){
				//	режим проверки
					xmlAttribute =  xmlAttributeMap.getNamedItem("checkMode");
					if (xmlAttribute != null && xmlAttribute.specified){
						if(xmlAttribute.value.toLowerCase() == "after")
							this.checkMode = DRAGGING_CHECK_AFTER
						else
							this.checked = true;
					};
				//	горизонтальное либо вертикальное выстраивание
					xmlAttribute =  xmlAttributeMap.getNamedItem("order");
					if (xmlAttribute != null && xmlAttribute.specified){
						if(xmlAttribute.value.toLowerCase() == "horizontal"){
							this.order = AUTOATTACH_RIGHT_TOP;
					};
					xmlAttribute =  xmlAttributeMap.getNamedItem("offsetX");
			        if (xmlAttribute != null && xmlAttribute.specified)
        				this.offsetX = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("offsetY");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.offsetY = parseInt(xmlAttribute.value);
					}
				}
			} else if(xmlNode.nodeName == "actions"){
				this.parseActionsNode(xmlNode);

				this.onCompleteActions =
					scene.Utils.parseActionsNode(xmlNode, "onComplete");
				this.onWrongCompleteActions =
					scene.Utils.parseActionsNode(xmlNode, "onWrongComplete");
				this.onPlacedRightActions =
					scene.Utils.parseActionsNode(xmlNode, "onPlacedRight");
				this.onPlacedWrongActions =
					scene.Utils.parseActionsNode(xmlNode, "onPlacedWrong");
			} else if(xmlNode.nodeName == "effects"){
				this.parseEffectsNode(xmlNode);
			} else if(xmlNode.nodeName == "objectives"){
				this.parseObjectivesNode(xmlNode);
			} else if(xmlNode.nodeName == "conditions"){
				var conditionNode = xmlNode.firstChild;
				while(conditionNode){
					if(conditionNode.nodeName == "condition"){
						this.parseConditionNode(conditionNode);
					}
					conditionNode = conditionNode.nextSibling;
				}
				this.parseConditionNode(xmlNode);
			} else if(xmlNode.nodeName == "properties"){
				this.parsePropertiesNode(xmlNode);
			}
			
			xmlNode = xmlNode.nextSibling;
		}

		this.loadChildsObject(srcNode)

		for(var i = 0; i < this.childObjects.length; i++){
			if(this.childObjects[i].type != "rnmc_stdButton"){
			//	создаем массив переставляемых элементов				
				if(this.objectWidth > 0)
					if(this.childObjects[i].type == "rnmc_stdText" &&
					(this.childObjects[i].objectWidth > this.objectWidth || this.childObjects[i].objectWidth == 0))
						this.childObjects[i].objectWidth = this.objectWidth;
				this.draglist.push(this.childObjects[i]);
			}
		}		

		return true;
	}

	function showObject(){
		if(this.draglist){					
			//	в случайном порядке
			var tempSequence = new Array();		
			for(var i=0; i<this.draglist.length; i++)
				tempSequence.push(i);		
			this.showOrder = scene.Utils.permutateArray(tempSequence);
			tempSequence = null;
			
			for(var i=0; i<this.showOrder.length; i++){
				this.draglist[this.showOrder[i]].autoAttachTarget = null;
				
				if(i>0)
					this.draglist[this.showOrder[i]].autoAttachTarget = this.draglist[this.showOrder[i-1]].id;
				
				this.draglist[this.showOrder[i]].index = i;
				this.draglist[this.showOrder[i]].autoAttachOffsetX = this.offsetX;
				this.draglist[this.showOrder[i]].autoAttachOffsetY = this.offsetY;
				this.draglist[this.showOrder[i]].autoAttachStyle = this.order;
				this.draglist[this.showOrder[i]].draggingEnabled = true;
				this.draglist[this.showOrder[i]].showObject();
				
				if(i==0)
					this.draglist[this.showOrder[0]].setPosition(this.objectX, this.objectY);
				
				this.draglist[this.showOrder[i]].listX = this.draglist[this.showOrder[i]].objectContent.x;
				this.draglist[this.showOrder[i]].listY = this.draglist[this.showOrder[i]].objectContent.y;
				
				if(this.maxWidth < this.draglist[this.showOrder[i]].objectContent.width)
					this.maxWidth = this.draglist[this.showOrder[i]].objectContent.width;
				if(this.maxHeight < this.draglist[this.showOrder[i]].objectContent.height)
					this.maxHeight = this.draglist[this.showOrder[i]].objectContent.height;
				
				if (this.draglist[this.showOrder[i]].onPressHandlerOriginal == undefined){
					this.draglist[this.showOrder[i]].onPressHandlerOriginal = this.draglist[this.showOrder[i]].onPressHandler;
					this.draglist[this.showOrder[i]].onPressHandler = function() {						
						this.objectContent.depth -= 500;
						this.onPressHandlerOriginal();
					}
				}
				
				if (this.draglist[this.showOrder[i]].onReleaseHandlerOriginal == undefined){					
					this.draglist[this.showOrder[i]].onReleaseHandlerOriginal = this.draglist[this.showOrder[i]].onReleaseHandler;
					this.draglist[this.showOrder[i]].onReleaseHandler = function() {
						if(this.objectCaptured){
							this.objectCaptured = false;
							placeObject(this);
						}
						this.onReleaseHandlerOriginal();
					}
				}

				if (this.draglist[this.showOrder[i]].onReleaseOutsideHandlerOriginal == undefined){
					this.draglist[this.showOrder[i]].onReleaseOutsideHandlerOriginal = this.draglist[this.showOrder[i]].onReleaseOutsideHandler;
					this.draglist[this.showOrder[i]].onReleaseOutsideHandler = function() {
						if(this.objectCaptured){
							this.objectCaptured = false;
							placeObject(this);
						}
						this.onReleaseOutsideHandlerOriginal();
					}
				}				
			}	
		}				
		this.nRight = 0;
		this.nError = 0;
		results.init();
		
		rnmc_stdMediaGroup_showObject();
	}

	function hideObject(){
		if(this.draglist){
			for(var i = 0; i < this.draglist.length; i++){
				this.draglist[i].draggingEnabled = false;
				
				this.draglist[i].hideObject();
				
				this.draglist[i].onPressHandler = this.draglist[i].onPressHandlerOriginal;
				delete this.draglist[i].onPressHandlerOriginal;
				
				this.draglist[i].onReleaseHandler = this.draglist[i].onReleaseHandlerOriginal;
				delete this.draglist[i].onReleaseHandlerOriginal;
				
				this.draglist[i].onReleaseOutsideHandler = this.draglist[i].onReleaseOutsideHandlerOriginal;
				delete this.draglist[i].onReleaseOutsideHandlerOriginal;
			}
		}
		rnmc_stdMediaGroup_hideObject();		
	}

//	сброс
	function resetObject(){
//trace("#FF0000resetObject()");
	//	устанавливаем изначальное состояние объекта
		if(this.draglist){					
			//	в случайном порядке
			var tempSequence = new Array();		
			for(var i=0; i<this.draglist.length; i++)
				tempSequence.push(i);
			this.showOrder = scene.Utils.permutateArray(tempSequence);
			tempSequence = null;
			
			for(var i=0; i<this.showOrder.length; i++){
				this.draglist[this.showOrder[i]].autoAttachTarget = null;
				
				if(i>0)
					this.draglist[this.showOrder[i]].autoAttachTarget = this.draglist[this.showOrder[i-1]].id;	
								
				this.draglist[this.showOrder[i]].index = i;
				this.draglist[this.showOrder[i]].autoAttachOffsetX = this.offsetX;
				this.draglist[this.showOrder[i]].autoAttachOffsetY = this.offsetY;
				this.draglist[this.showOrder[i]].autoAttachStyle = this.order;
				this.draglist[this.showOrder[i]].draggingEnabled = true;
				this.draglist[this.showOrder[i]].showObject();
				
				if(i==0)
					this.draglist[this.showOrder[0]].setPosition(this.objectX, this.objectY);
				
				this.draglist[this.showOrder[i]].listX = this.draglist[this.showOrder[i]].objectContent.x;
				this.draglist[this.showOrder[i]].listY = this.draglist[this.showOrder[i]].objectContent.y;
			}
		}		
		this.nRight = 0;
		this.nError = 0;
		results.init();
	}

	function dispatchAction(singleAction){
		switch (singleAction[0]) {
			case "checkObject":
				this.doAction(singleAction);
				break;
			case "resetObject":
				this.doAction(singleAction);
				break;
			default:
				rnmc_stdMediaGroup_dispatchAction(singleAction);
		}
	}


//	выполняет специфичные для объекта rnmc_stdIntegration действия
	function doAction(singleAction){
//trace("integration: " + this.id + " - doAction: " + singleAction);	
		switch(singleAction[0]){	
		case "checkObject":
			this.checkObject();
			break;
		case "resetObject":
			this.resetObject();
			break;
		default:
			rnmc_stdMediaGroup_doAction(singleAction);
		};
	}

	function applyDefaultActions(dragObj, forEvent){
		switch(forEvent){
		case "onPlacedRight":
			if(this.onPlacedRightActions){
				for(var i = 0; i < this.onPlacedRightActions.length; i++){
					this.dispatchAction(this.onPlacedRightActions[i]);
				}
			}
			if(dragObj.onPlacedRightActions){
				for(var i = 0; i < dragObj.actionsList[EVENT_ON_PLACEDRIGHT].length; i++){
					this.dispatchAction(dragObj.actionsList[EVENT_ON_PLACEDRIGHT][i]);
				}
			}
			break;
		case "onPlacedWrong":
			if(this.onPlacedWrongActions){
				for(var i = 0; i < this.onPlacedWrongActions.length; i++){
					this.dispatchAction(this.onPlacedWrongActions[i]);
				}
			}
			if(dragObj.onPlacedWrongActions){
				for(var i = 0; i < dragObj.actionsList[EVENT_ON_PLACEDWRONG].length; i++){
					this.dispatchAction(dragObj.actionsList[EVENT_ON_PLACEDWRONG][i]);
				}
			}
			break;
		case "onComplete":
			if(this.onCompleteActions){
				for(var i = 0; i < this.onCompleteActions.length; i++){
					this.dispatchAction(this.onCompleteActions[i]);
				}
			}
			break;
		case "onWrongComplete":
			if(this.onWrongCompleteActions){
				for(var i = 0; i < this.onWrongCompleteActions.length; i++){
					this.dispatchAction(this.onWrongCompleteActions[i]);
				}
			}
			break;
		}
	}

	function moveTo(dragObj, xDest, yDest){
		if(dragObj.newEffect)
			dragObj.newEffect.updateSequencer.playing = false
		else{
			dragObj.newEffect = new Composition();
			dragObj.newEffect._class = "rnmc_stdEffect";
			dragObj.newEffect.parent = dragObj;
			dragObj.newEffect.effectDelta = this.flowdelta;
			dragObj.newEffect.effectType = EFFECT_MOVE;
		}
		dragObj.newEffect.effectRunning = true;		
		dragObj.newEffect.targetObject = dragObj.objectContent;		
		dragObj.newEffect.objectFinishX = xDest;
		dragObj.newEffect.objectFinishY = yDest;	
		dragObj.newEffect.updateSequencer.playing = true;
	}

	function checkObject(){
		this.checked = true;
		var complete = 0;
		for( var i=0; i<this.draglist.length; i++){			
			if(this.draglist[i] == this.draglist[this.draglist[i].index])
				complete++
			else
				break;
		}
		if(complete == this.draglist.length)
			this.applyDefaultActions(0, "onComplete")
		else
			this.applyDefaultActions(0, "onWrongComplete")
	}
	
	function shiftDown(dragObj, dragObjY, i){
		this.moveTo(dragObj, this.draglist[this.showOrder[i]].listX, dragObjY);
		var otherY = dragObj.listY;
		for(var j=dragObj.index+1; j<=i; j++){
			if(j>dragObj.index+1)
				otherY += this.draglist[this.showOrder[j-1]].objectContent.height + this.offsetY;
			this.moveTo(this.draglist[this.showOrder[j]], this.draglist[this.showOrder[j-1]].listX, otherY);
			this.draglist[this.showOrder[j]].index--;										
			this.draglist[this.showOrder[j]].listY = otherY;
		}
		for(var j=i; j>dragObj.index; j--)
			this.draglist[this.showOrder[j]].listX = this.draglist[this.showOrder[j-1]].listX;
		if(dragObj.index == 0)
			this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = null
		else
			this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = this.draglist[this.showOrder[dragObj.index-1]].id;	
		dragObj.autoAttachTarget = this.draglist[this.showOrder[i]].id;
		dragObj.listX = this.draglist[this.showOrder[i]].listX + this.offsetX;;
		dragObj.listY = dragObjY;
		var dragOrder = this.showOrder[dragObj.index];
		for(var j=dragObj.index; j<i; j++)
			this.showOrder[j] = this.showOrder[j+1];									
		this.showOrder[i] = dragOrder;
		dragObj.index = i;
	}
	
	function shiftUp(dragObj, dragObjY, i){
		this.moveTo(dragObj, this.draglist[this.showOrder[i]].listX, dragObjY);
		var otherY = dragObjY + dragObj.objectContent.height + this.offsetY;
		for(var j=i; j<=dragObj.index-1; j++){
			if(j > i)
				otherY += this.draglist[this.showOrder[j-1]].objectContent.height + this.offsetY;
			this.moveTo(this.draglist[this.showOrder[j]], this.draglist[this.showOrder[j+1]].listX, otherY);									
			this.draglist[this.showOrder[j]].index++;
			this.draglist[this.showOrder[j]].listX = this.draglist[this.showOrder[j+1]].listX;
			this.draglist[this.showOrder[j]].listY = otherY;
		}
		this.draglist[this.showOrder[i]].autoAttachTarget = dragObj.id;							
		if(dragObj.index < this.draglist.length-1)
			this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = this.draglist[this.showOrder[dragObj.index-1]].id;								
		dragObj.listX = this.draglist[this.showOrder[i]].listX - this.offsetX;
		dragObj.listY = dragObjY;								
		var dragOrder = this.showOrder[dragObj.index];
		for(var j=dragObj.index; j>i; j--){
			this.showOrder[j] = this.showOrder[j-1];
		}							
		this.showOrder[i] = dragOrder;
		dragObj.index = i;
	}
	
	function shiftRight(dragObj, dragObjX, i){
		this.moveTo(dragObj, dragObjX, this.draglist[this.showOrder[i]].listY);
		var otherX = dragObj.listX;
		for(var j=dragObj.index+1; j<=i; j++){
			if(j>dragObj.index+1)
				otherX += this.draglist[this.showOrder[j-1]].objectContent.width + this.offsetX;
			this.moveTo(this.draglist[this.showOrder[j]], otherX, this.draglist[this.showOrder[j-1]].listY);
			this.draglist[this.showOrder[j]].index--;										
			this.draglist[this.showOrder[j]].listX = otherX;
		}
		for(var j=i; j>dragObj.index; j--)
			this.draglist[this.showOrder[j]].listY = this.draglist[this.showOrder[j-1]].listY;
		if(dragObj.index == 0)
			this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = null
		else
			this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = this.draglist[this.showOrder[dragObj.index-1]].id;	
		dragObj.autoAttachTarget = this.draglist[this.showOrder[i]].id;
		dragObj.listX = dragObjX;
		dragObj.listY = this.draglist[this.showOrder[i]].listY + this.offsetY;;		
		var dragOrder = this.showOrder[dragObj.index];
		for(var j=dragObj.index; j<i; j++)
			this.showOrder[j] = this.showOrder[j+1];									
		this.showOrder[i] = dragOrder;
		dragObj.index = i;
	}
	
	function shiftLeft(dragObj, dragObjX, i){
		this.moveTo(dragObj, dragObjX, this.draglist[this.showOrder[i]].listY);
		var otherX = dragObjX + dragObj.objectContent.width + this.offsetX;
		for(var j=i; j<=dragObj.index-1; j++){
			if(j > i)
				otherX += this.draglist[this.showOrder[j-1]].objectContent.width + this.offsetX;
			this.moveTo(this.draglist[this.showOrder[j]], otherX, this.draglist[this.showOrder[j+1]].listY);									
			this.draglist[this.showOrder[j]].index++;
			this.draglist[this.showOrder[j]].listX = otherX;
			this.draglist[this.showOrder[j]].listY = this.draglist[this.showOrder[j+1]].listY;			
		}
		this.draglist[this.showOrder[i]].autoAttachTarget = dragObj.id;							
		if(dragObj.index < this.draglist.length-1)
			this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = this.draglist[this.showOrder[dragObj.index-1]].id;								
		dragObj.listX = dragObjX;
		dragObj.listY = this.draglist[this.showOrder[i]].listY - this.offsetY;		
		var dragOrder = this.showOrder[dragObj.index];
		for(var j=dragObj.index; j>i; j--){
			this.showOrder[j] = this.showOrder[j-1];
		}							
		this.showOrder[i] = dragOrder;
		dragObj.index = i;
	}
	
	function exchangeDown(dragObj, i, dragObjX, dragObjY){		
		this.moveTo(this.draglist[this.showOrder[i]], dragObj.listX, dragObj.listY);
				
		var index = dragObj.index;
		var autoAttachTarget = dragObj.autoAttachTarget;
		var listX = dragObj.listX;
		var listY = dragObj.listY;		
		var showOrder = this.showOrder[dragObj.index];
		
		dragObj.index = this.draglist[this.showOrder[i]].index;
		dragObj.autoAttachTarget = this.draglist[this.showOrder[i]].autoAttachTarget;
		if(dragObjX)
			dragObj.listX = dragObjX
		else
			dragObj.listX = this.draglist[this.showOrder[i]].listX;		
		if(dragObjY)
			dragObj.listY = dragObjY
		else
			dragObj.listY = this.draglist[this.showOrder[i]].listY;
		this.showOrder[index] = this.showOrder[i];
		
		this.draglist[this.showOrder[i]].index = index;
		this.draglist[this.showOrder[i]].autoAttachTarget = autoAttachTarget;
		this.draglist[this.showOrder[i]].listX = listX;
		this.draglist[this.showOrder[i]].listY = listY;
		this.showOrder[i] = showOrder;
		
		if(index+1 < this.showOrder.length)
			this.draglist[this.showOrder[index+1]].autoAttachTarget = this.draglist[this.showOrder[i]].id;
		if(i+1 < this.showOrder.length)
			this.draglist[this.showOrder[i+1]].autoAttachTarget = dragObj.id;
		
		//если вертикальная расстановка					
		var width = 0;
		// если горизонтальная растановка
		var height = 0;
		for(j=index+1; j<i; j++){			
			//если вертикальная расстановка
			if(this.order == AUTOATTACH_BOTTOM_LEFT)
				height = this.draglist[this.showOrder[j-1]].objectContent.height				
			// если горизонтальная растановка
			else
				width = this.draglist[this.showOrder[j-1]].objectContent.width;
									
			this.draglist[this.showOrder[j]].objectContent.x = this.draglist[this.showOrder[j]].listX = this.draglist[this.showOrder[j-1]].listX + this.offsetX + width;
			this.draglist[this.showOrder[j]].objectContent.y = this.draglist[this.showOrder[j]].listY = this.draglist[this.showOrder[j-1]].listY + this.offsetY + height;
		}		
	}
	
	function exchangeUp(dragObj, i, dragObjX, dragObjY){				
		var index = dragObj.index;
		var autoAttachTarget = this.draglist[this.showOrder[i]].autoAttachTarget;
		var listX = this.draglist[this.showOrder[i]].listX;
		var listY = this.draglist[this.showOrder[i]].listY;		
		var showOrder = this.showOrder[i];
		
		this.draglist[this.showOrder[i]].index = dragObj.index;
		this.draglist[this.showOrder[i]].autoAttachTarget = dragObj.autoAttachTarget;
		this.draglist[this.showOrder[i]].listX = dragObj.listX;
		this.draglist[this.showOrder[i]].listY = dragObj.listY;
		this.showOrder[i] = this.showOrder[dragObj.index];
				
		dragObj.index = i;
		dragObj.autoAttachTarget = autoAttachTarget;
		if(dragObjX)
			dragObj.listX = dragObjX
		else
			dragObj.listX = this.draglist[this.showOrder[i]].listX;		
		if(dragObjY)
			dragObj.listY = dragObjY
		else
			dragObj.listY = this.draglist[this.showOrder[i]].listY;
		this.showOrder[index] = showOrder;
		
		if(index+1 < this.showOrder.length)
			this.draglist[this.showOrder[index+1]].autoAttachTarget = this.draglist[this.showOrder[i]].id;
		if(i+1 < this.showOrder.length)
			this.draglist[this.showOrder[i+1]].autoAttachTarget = dragObj.id;
		
		//если вертикальная расстановка					
		var width = 0;
		// если горизонтальная растановка
		var height = 0;
		for(j=i+1; j<index; j++){			
			//если вертикальная расстановка
			if(this.order == AUTOATTACH_BOTTOM_LEFT)
				height = this.draglist[this.showOrder[j-1]].objectContent.height				
			// если горизонтальная растановка
			else
				width = this.draglist[this.showOrder[j-1]].objectContent.width;
			
			this.draglist[this.showOrder[j]].objectContent.x = this.draglist[this.showOrder[j]].listX = this.draglist[this.showOrder[j-1]].listX + this.offsetX + width;
			this.draglist[this.showOrder[j]].objectContent.y = this.draglist[this.showOrder[j]].listY = this.draglist[this.showOrder[j-1]].listY + this.offsetY + height;						
		}
		
		width = this.draglist[this.showOrder[index-1]].listX.width;
		height = this.draglist[this.showOrder[index-1]].objectContent.height;
		if(dragObjY)
			this.moveTo(this.draglist[this.showOrder[index]], dragObj.listX, this.draglist[this.showOrder[index-1]].listY + this.offsetY + height)
		else
			this.moveTo(this.draglist[this.showOrder[index]], this.draglist[this.showOrder[index-1]].listX + this.offsetX + width, dragObj.listY);
	}
	
	function placeObject(dragObj){
//trace("testIsInPlace");
		if(this.checkMode == DRAGGING_CHECK_AFTER){
			if(this.order == AUTOATTACH_BOTTOM_LEFT){			
			//	вертикальная расстановка
			//	если элемент полдностью за пределами списка - возврат на исходную позицию
				if(dragObj.objectContent.x > this.objectX + this.maxWidth + this.sensitivity + this.offsetX * (this.draglist.length - 1) ||
				dragObj.objectContent.x + dragObj.objectContent.width < this.objectX - this.sensitivity)				
					this.moveTo(dragObj, dragObj.listX, dragObj.listY)
				else{
					var centerY = dragObj.objectContent.y + dragObj.objectContent.height/2;
					var dragObjY = dragObj.listY;
					if(dragObj.objectContent.y > dragObj.listY + (dragObj.objectContent.height + this.offsetY)/2){				
						if(dragObj.index < this.showOrder.length-1){
							for(var i=dragObj.index+1; i<this.showOrder.length; i++){
								if(centerY > this.draglist[this.showOrder[i]].listY - this.offsetY/2)
									dragObjY += this.draglist[this.showOrder[i]].objectContent.height + this.offsetY
								else{
									this.shiftDown(dragObj, dragObjY, i-1);
									this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = dragObj.id;
									break;
								}
								if(i == this.showOrder.length-1){
									this.shiftDown(dragObj, dragObjY, i);
								}
							}
						} else
							this.moveTo(dragObj, dragObj.listX, dragObj.listY);						
					} else if(dragObj.objectContent.y < dragObj.listY - (dragObj.objectContent.height + this.offsetY)/2){					
						if(dragObj.index > 0){						
							for(var i=dragObj.index-1; i>=0; i--){
								if(centerY < this.draglist[this.showOrder[i]].listY + this.draglist[this.showOrder[i]].objectContent.height + this.offsetY/2)
									dragObjY -= this.draglist[this.showOrder[i]].objectContent.height + this.offsetY
								else{
									this.shiftUp(dragObj, dragObjY, i+1);
									break;
								}
								if(i == 0){
									this.shiftUp(dragObj, dragObjY, i);
								}
							}
						} else
							this.moveTo(dragObj, dragObj.listX, dragObj.listY);
					} else
						this.moveTo(dragObj, dragObj.listX, dragObj.listY);
				}				
			} else{
			//	горизонтальная расстановка
				if(dragObj.objectContent.y > this.objectY + this.maxHeight + this.sensitivity + this.offsetY * (this.draglist.length - 1) ||
				dragObj.objectContent.y + dragObj.objectContent.height < this.objectY - this.sensitivity)				
					this.moveTo(dragObj, dragObj.listX, dragObj.listY)
				else{
					var centerX = dragObj.objectContent.x + dragObj.objectContent.width/2;
					var dragObjX = dragObj.listX;
					if(dragObj.objectContent.x > dragObj.listX + (dragObj.objectContent.width + this.offsetX)/2){				
						if(dragObj.index < this.showOrder.length-1){
							for(var i=dragObj.index+1; i<this.showOrder.length; i++){
								if(centerX > this.draglist[this.showOrder[i]].listX - this.offsetX/2)
									dragObjX += this.draglist[this.showOrder[i]].objectContent.width + this.offsetX
								else{
									this.shiftRight(dragObj, dragObjX, i-1);
									this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = dragObj.id;
									break;
								}
								if(i == this.showOrder.length-1){
									this.shiftRight(dragObj, dragObjX, i);
								}
							}
						} else
							this.moveTo(dragObj, dragObj.listX, dragObj.listY);						
					} else if(dragObj.objectContent.x < dragObj.listX - (dragObj.objectContent.width + this.offsetX)/2){					
						if(dragObj.index > 0){						
							for(var i=dragObj.index-1; i>=0; i--){
								if(centerX < this.draglist[this.showOrder[i]].listX + this.draglist[this.showOrder[i]].objectContent.width + this.offsetX/2)
									dragObjX -= this.draglist[this.showOrder[i]].objectContent.width + this.offsetX
								else{
									this.shiftLeft(dragObj, dragObjX, i+1);
									break;
								}
								if(i == 0){
									this.shiftLeft(dragObj, dragObjX, i);
								}
							}
						} else
							this.moveTo(dragObj, dragObj.listX, dragObj.listY);
					} else
						this.moveTo(dragObj, dragObj.listX, dragObj.listY);
				}
			}			
			if(dragObj == this.draglist[dragObj.index])
				this.applyDefaultActions(dragObj, "onPlacedRight")
			else
				this.applyDefaultActions(dragObj, "onPlacedWrong");
		} else{
		//	проверка сразу
			if(this.order == AUTOATTACH_BOTTOM_LEFT){			
			//	вертикальная расстановка
			//	если элемент полдностью за пределами списка - возврат на исходную позицию
				if(dragObj.objectContent.x > this.objectX + this.maxWidth + this.sensitivity + this.offsetX * (this.draglist.length - 1) ||
				dragObj.objectContent.x + dragObj.objectContent.width < this.objectX - this.sensitivity)				
					this.moveTo(dragObj, dragObj.listX, dragObj.listY)
				else{
					var centerY = dragObj.objectContent.y + dragObj.objectContent.height/2;
					var dragObjY = dragObj.listY;
					if(dragObj.objectContent.y > dragObj.listY + (dragObj.objectContent.height + this.offsetY)/2){				
						if(dragObj.index < this.showOrder.length-1){
							for(var i=dragObj.index+1; i<this.showOrder.length; i++){
								if(centerY > this.draglist[this.showOrder[i]].listY - this.offsetY/2)
									dragObjY += this.draglist[this.showOrder[i]].objectContent.height + this.offsetY
								else{
									if(dragObj == this.draglist[i-1]){
										this.nRight++;
										this.applyDefaultActions(dragObj, "onPlacedRight");										
										this.moveTo(dragObj, this.draglist[this.showOrder[i-1]].listX, dragObjY);
										this.exchangeDown(dragObj, i-1, false, dragObjY);									
										this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = dragObj.id;
									} else{
										this.nError++;
										this.applyDefaultActions(dragObj, "onPlacedWrong");
										this.moveTo(dragObj, dragObj.listX, dragObj.listY);
									}
									break;
								}
								if(i == this.showOrder.length-1){
									if(dragObj == this.draglist[i]){
										this.nRight++;
										this.applyDefaultActions(dragObj, "onPlacedRight");
										this.moveTo(dragObj, this.draglist[this.showOrder[i]].listX, dragObjY);
										this.exchangeDown(dragObj, i, false, dragObjY);
									} else{
										this.nError++;
										this.applyDefaultActions(dragObj, "onPlacedWrong");
										this.moveTo(dragObj, dragObj.listX, dragObj.listY);
									}
								}
							}
						} else
							this.moveTo(dragObj, dragObj.listX, dragObj.listY);						
					} else if(dragObj.objectContent.y < dragObj.listY - (dragObj.objectContent.height + this.offsetY)/2){					
						if(dragObj.index > 0){						
							for(var i=dragObj.index-1; i>=0; i--){
								if(centerY < this.draglist[this.showOrder[i]].listY + this.draglist[this.showOrder[i]].objectContent.height + this.offsetY/2)
									dragObjY -= this.draglist[this.showOrder[i]].objectContent.height + this.offsetY
								else{
									if(dragObj == this.draglist[i+1]){
										this.nRight++;
										this.applyDefaultActions(dragObj, "onPlacedRight");
										this.moveTo(dragObj, this.draglist[this.showOrder[i+1]].listX, dragObjY);
										this.exchangeUp(dragObj, i+1, false, dragObjY);
									} else{
										this.nError++;
										this.applyDefaultActions(dragObj, "onPlacedWrong");
										this.moveTo(dragObj, dragObj.listX, dragObj.listY);
									}
									break;
								}
								if(i == 0){
									if(dragObj == this.draglist[i]){
										this.nRight++;
										this.applyDefaultActions(dragObj, "onPlacedRight");
										this.moveTo(dragObj, this.draglist[this.showOrder[i]].listX, dragObjY);
										this.exchangeUp(dragObj, i, false, dragObjY);
									} else{
										this.nError++;
										this.applyDefaultActions(dragObj, "onPlacedWrong");
										this.moveTo(dragObj, dragObj.listX, dragObj.listY);
									}
								}								
							}
						} else
							this.moveTo(dragObj, dragObj.listX, dragObj.listY);
					} else
						this.moveTo(dragObj, dragObj.listX, dragObj.listY);				
				}
			} else{
			//	горизонтальная расстановка
				if(dragObj.objectContent.y > this.objectY + this.maxHeight + this.sensitivity + this.offsetY * (this.draglist.length - 1) ||
				dragObj.objectContent.y + dragObj.objectContent.height < this.objectY - this.sensitivity)				
					this.moveTo(dragObj, dragObj.listX, dragObj.listY)
				else{
					var centerX = dragObj.objectContent.x + dragObj.objectContent.width/2;
					var dragObjX = dragObj.listX;
					if(dragObj.objectContent.x > dragObj.listX + (dragObj.objectContent.width + this.offsetX)/2){				
						if(dragObj.index < this.showOrder.length-1){
							for(var i=dragObj.index+1; i<this.showOrder.length; i++){
								if(centerX > this.draglist[this.showOrder[i]].listX - this.offsetX/2)
									dragObjX += this.draglist[this.showOrder[i]].objectContent.width + this.offsetX
								else{
									if(dragObj == this.draglist[i-1]){
										this.nRight++;
										this.applyDefaultActions(dragObj, "onPlacedRight");
										this.moveTo(dragObj, dragObjX, this.draglist[this.showOrder[i-1]].listY);
										this.exchangeDown(dragObj, i-1, dragObjX);
										this.draglist[this.showOrder[dragObj.index+1]].autoAttachTarget = dragObj.id;
									} else{
										this.nError++;
										this.applyDefaultActions(dragObj, "onPlacedWrong");
										this.moveTo(dragObj, dragObj.listX, dragObj.listY);
									}
									break;
								}
								if(i == this.showOrder.length-1){
									if(dragObj == this.draglist[i]){
										this.nRight++;
										this.applyDefaultActions(dragObj, "onPlacedRight");
										this.moveTo(dragObj, dragObjX, this.draglist[this.showOrder[i]].listY);
										this.exchangeDown(dragObj, i, dragObjX)
									} else{
										this.nError++;
										this.applyDefaultActions(dragObj, "onPlacedWrong");
										this.moveTo(dragObj, dragObj.listX, dragObj.listY);
									}
								}
							}
						} else
							this.moveTo(dragObj, dragObj.listX, dragObj.listY);						
					} else if(dragObj.objectContent.x < dragObj.listX - (dragObj.objectContent.width + this.offsetX)/2){					
						if(dragObj.index > 0){						
							for(var i=dragObj.index-1; i>=0; i--){
								if(centerX < this.draglist[this.showOrder[i]].listX + this.draglist[this.showOrder[i]].objectContent.width + this.offsetX/2)
									dragObjX -= this.draglist[this.showOrder[i]].objectContent.width + this.offsetX
								else{
									if(dragObj == this.draglist[i+1]){
										this.nRight++;
										this.applyDefaultActions(dragObj, "onPlacedRight");
										this.moveTo(dragObj, dragObjX, this.draglist[this.showOrder[i+1]].listY);
										this.exchangeUp(dragObj, i+1, dragObjX);
									} else{
										this.nError++;
										this.applyDefaultActions(dragObj, "onPlacedWrong");
										this.moveTo(dragObj, dragObj.listX, dragObj.listY);
									}
									break;
								}
								if(i == 0){
									if(dragObj == this.draglist[i]){
										this.nRight++;
										this.applyDefaultActions(dragObj, "onPlacedRight");
										this.moveTo(dragObj, dragObjX, this.draglist[this.showOrder[i]].listY);
										this.exchangeUp(dragObj, i, dragObjX);
									} else{
										this.nError++;
										this.applyDefaultActions(dragObj, "onPlacedWrong");
										this.moveTo(dragObj, dragObj.listX, dragObj.listY);
									}
								}
							}
						} else
							this.moveTo(dragObj, dragObj.listX, dragObj.listY);
					} else
						this.moveTo(dragObj, dragObj.listX, dragObj.listY);
				}
			}
			var complete = 0;
			for( var i=0; i<this.draglist.length; i++){			
				if(this.draglist[i] == this.draglist[this.draglist[i].index])
					complete++
				else
					break;
			}
			if(complete == this.draglist.length)
				this.applyDefaultActions(dragObj, "onComplete");
		}		
		dragObj.objectContent.depth += 500;
	}
		

//==================================================================
//	функция пока не используется
	function getResult(resultsArray){		
	    results.init();
		
		for(var i=0; i<this.draglist.length; i++){
			if(this.draglist[i].index == i)
				results.rightElements++
			else
				results.wrongElements++;
		}
		if(this.checkMode == DRAGGING_CHECK_IMMEDIATELY)
			results.wrongElements += this.nError;
			
		results.allRightElements = this.draglist.length;
		results.attemptsCount = this.nRight + this.nError;
		
		results.countResult(this.crAlgorithm);
		this.objectResult = results.objectResult;
		
		if(resultsArray && this.crAlgorithm != "none"){
			var resultString = this.objectResult + ";1.0";
			resultsArray.push(resultString);
		}

		rnmc_stdMediaGroup_getResult(resultsArray);
	}
	
	function getErrors(){
		if(this.checked)
			return results.wrongElements;
	}
	
]]></script>
</composition>
</rmml>