// Возвращает массив сдвигов по координатам
CAtom.prototype.getCommonChildDirectionsFor = function(atom)
{
	if( atom.parent != null)
		trace("#0000FF getCommonChildDirectionsFor [" + atom.type + ":"+atom.rootDistance+"] parent is ["+atom.parent.type+"]");
	else
		trace("#0000FF getCommonChildDirectionsFor [" + atom.type + ":"+atom.rootDistance+"]");
	var add=new Array();

	var localDirection = this.firstChildDirection;
	if( localDirection.indexOf("left")!=-1)	localDirection = "left";
	else	if( localDirection.indexOf("right")!=-1)	localDirection = "right";

	trace("-----------------------------------------"+atom.type);
	// см. groups.mjs
	var atomGroupPosition = atom.isInGroup();
	var thisGroupPosition = this.isInGroup();
	var isGroupHead = this.isGroupHead();
	var isAtomGroupHead = atom.isGroupHead();
	trace("getCommonChildDirectionsFor for"+atom.type+", atomGroupPosition="+atomGroupPosition+", isGroupHead="+isGroupHead);
	trace("thisGroupPosition="+thisGroupPosition);
	trace("atom.isGroupHead()="+atom.isGroupHead());
	if( isAtomGroupHead && atomGroupPosition!=2)
	{
		trace("#FF0000 isAtomGroupHead && atomGroupPosition!=2");
		//atomGroupPosition = 0;
	}
	if( isGroupHead && atomGroupPosition==1)
	{
		// 1.
		trace("#FFAA00 1.");
		if( localDirection=="right")
		{
			add.push("right-up");
			add.push("right-down");
		}
		else	if( localDirection=="left")
		{
			add.push("left-up");
			add.push("left-down");
		}
		else	if( localDirection=="up")
		{
			add.push("right-up");
			add.push("left-up");
		}
		else	if( localDirection=="down")
		{
			add.push("right-down");
			add.push("left-down");
		}
	}
	else	if( isGroupHead && atomGroupPosition==4)
	{
		trace("#FFAA00 4.");
		// 4.
		add.push("left-up");
		add.push("left-down");
	}
	else	if( thisGroupPosition==2 && isAtomGroupHead)
	{
		trace("#FFAA00 2.");
		// 2.
		if( localDirection=="right")
		{
			add.push("right-down");
			add.push("right-up");
		}
		else	if( localDirection=="left")
		{
			add.push("left-down");
			add.push("left-up");
		}
		else
			trace("mc2d getCommonChildDirectionsFor error: incorrect group direction[2]:"+localDirection);

		if( atom.isFlipped && add.length==2)
		{
			var temp = add[0];
			add[0] = add[1];
			add[1] = temp;
		}
	}
	else	if( isGroupHead && atomGroupPosition==3)
	{
		trace("#FFAA00 3.");
		// 3.
		if( this.firstChildDirection == "right-down")
		{
			add.push("left-down");
		}
		else	if( this.firstChildDirection == "right-up")
		{
			add.push("left-up");
		}
		else
			trace("mc2d getCommonChildDirectionsFor error: incorrect group direction[3]:"+localDirection);
	}
	else
	{
		trace("#FF0000 mc2d getCommonChildDirectionsFor error: unlnown kombination");
	}
	if( this.isFlipped && add.length==2)
	{
		var temp = add[0];
		add[0] = add[1];
		add[1] = temp;
	}

	if( atom.isOnMainLine == false)
	{
		if( this.isOnMainLine==false)
		{
			if( localDirection=="right")
			{
				add.push("right");	add.push("down");	add.push("up");
			}
			else	if( localDirection=="down")
			{
				add.push("down");	add.push("right");	add.push("left");
			}
			else	if( localDirection=="up")
			{
				add.push("up");	add.push("right");	add.push("left");
			}
			else	if( localDirection=="left")
			{
				add.push("left");	add.push("down");	add.push("up");
			}
			if( this.isFlipped && add.length==3)
			{
				var temp = add[1];
				add[1] = add[2];
				add[2] = temp;
			}
		}
		else
		{
			// 2. ответвления от главной линии
			if( localDirection=="right")
			{
				add.push("right");
				add.push("left");
			}
			else	if( localDirection=="left")
			{
				add.push("left");
				add.push("right");
			}
			if( !this.isFlipped)
			{
				add.push("down");
				add.push("up");
			}
			else
			{
				add.push("up");
				add.push("down");
			}
		}
	}
	else
	{
		// 1. главная линия
		if( localDirection=="right")
		{
			add.push("right");	add.push("left");
		}
		else	if( localDirection=="left")
		{
			add.push("left");	add.push("right");
		}
		if( !this.isFlipped)
		{
			add.push("down");	add.push("up");
		}
		else
		{
			add.push("up");	add.push("down");
		}
	}

	return add;
}

// Возвращает массив сдвигов по координатам
CMolecule.prototype.getChildrenDirections = function(atom)
{
	var add=new Array();

	if( atom.parent == null)
	{
		return add;
	}
	return atom.parent.getCommonChildDirectionsFor(atom);
}
// Возвращает массив объектов с координатами клеток, занимаемых атомом
CAtom.prototype.getOccupiedBoardCells = function()
{
	var cells = new Array();
	// ячейка, занимаемая атомом
	var obj = new Object();
		obj.x = this.getAbsX();
		obj.y = this.getAbsY();
	cells.push( obj);
	// ячейка, занимаемая связью
	obj = new Object();
		obj.x = this.getLinkAbsX();
		obj.y = this.getLinkAbsY();
	cells.push( obj);
	return cells;
}