function aniRollInOut(node,delay,dur,leavingDur,startX,endX,startY,endY)
	if delay == nil
	then delay = 1
	end	
	if dur == nil
	then dur = 1
	end	
	if leavingDur == nil
	then leavingDur = .5
	end
	if alpha == nil
	then alpha = 255
	end	

	local a = KrImNodeCurveAnimation();

	local curveY = ParameterCurve();
	curveY:setStartValue( startY );
	curveY:addKey(delay, startY, IParameterCurve.LINEAR);
	curveY:addKey(delay + dur, endY, IParameterCurve.LINEAR);
	a:setYCurve(curveY);

	local curveX = ParameterCurve();
	curveX:setStartValue( startX );
	curveX:addKey(delay, startX, IParameterCurve.LINEAR);
	curveX:addKey(delay + dur, endX, IParameterCurve.LINEAR);
	a:setXCurve(curveX);


	local pairForStart = ComingLeavingPair();
	pairForStart:setComingAnimation(a)

	local a = KrImNodeLinearAnimation(leavingDur, 0, false)
	a:setLaneAbsolute(KrImNodeLinearAnimation.POS_Y, endY, startY, false)

	pairForStart:setLeavingAnimation(a)
	setUserDataPair(node , pairForStart)
end


function aniFadeInFadeOut(node,delay,dur,leavingDur,alpha)
	if delay == nil
	then delay = 1
	end	
	if dur == nil
	then dur = 1
	end	
	if leavingDur == nil
	then leavingDur = .5
	end
	if alpha == nil
	then alpha = 255
	end	
	local a = KrImNodeCurveAnimation();
	local curveA = ParameterCurve();
	curveA:setStartValue( 0 );
	curveA:addKey(delay, 0, IParameterCurve.LINEAR);
	curveA:addKey(delay + dur, alpha, IParameterCurve.LINEAR);
	a:setAlphaCurve(curveA);
	local pairForStart = ComingLeavingPair();
	pairForStart:setComingAnimation(a)
	local a = KrImNodeLinearAnimation(leavingDur, 0, false)
	a:setLaneAbsolute(KrImNodeLinearAnimation.ALPHA, alpha, 0, false)
	pairForStart:setLeavingAnimation(a)
	setUserDataPair(node , pairForStart)
end

function aniFadeOutFadeIn(node,delay,dur,leavingDelay,leavingDur,alpha)
	if delay == nil
	then delay = 1
	end	
	if dur == nil
	then dur = 1
	end	
	if leavingDur == nil
	then leavingDur = .5
	end
	if leavingDelay == nil
	then leavingDelay = .5
	end
	if alpha == nil
	then alpha = 255
	end	

	local a = KrImNodeLinearAnimation(dur, 0, false)
	a:setLaneAbsolute(KrImNodeLinearAnimation.ALPHA, alpha, 0, false)

	local pairForStart = ComingLeavingPair();
	pairForStart:setComingAnimation(a)

	local a = KrImNodeLinearAnimation(leavingDur, 0, false)
	a:setLaneAbsolute(KrImNodeLinearAnimation.ALPHA, 0, alpha, false)

	pairForStart:setLeavingAnimation(a)
	setUserDataPair(node , pairForStart)
end

function aniPoolGroupBg(sprite,x0,x1,y0,tessQuantityX,tessQuantityY)
--	aniPoolHideOriginal(sprite)
	local game = getGameInstance()
	local pairForStart = ComingLeavingPair();
	-- coming Animation ------------------------------------------
	if tessQuantityX == nil
	then tessQuantityX = 10
	end 
	if tessQuantityY == nil
	then tessQuantityY = 3
	end 
	local tessRandX = 1
	local tessRandY = 2
	local delay = 0 
	local duration = .4
	local pieceTimeRange =  1.
	local curvePower = 1
	local ani = KrImNodePoolAnimation(
		game:getEngine(),
		tessQuantityX,
		tessQuantityY,
		tessRandX,
		tessRandY,
		delay, 
		duration,
		pieceTimeRange,
		curvePower,
		false
	)
	ani:setTessRandSeed(123);
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,50,255,255),
		KrRGBA(255,50,255,255)
	)
	--
	--	setTiming(key,channel,delay,duration,pieceTimeRange)
	--
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.POS,x0,y0,0,300)
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.ROTZ, -10,10)
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.SCALE, 1,1.2)
	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR,3 )
	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ,1 )
	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, .3, .1, 1 )

	ani:setTiming(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.COLOR, 0, .1, 1 )

	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,50,255,255),
		KrRGBA(255,50,255,255)
	)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.POS,x1,y0,0,300)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.ROTZ, -10,10)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.SCALE, 1,1.2)

	pairForStart:setComingAnimation(ani)

	-- leaving Animation ------------------------------------------

--	local tessQuantityX = 10
--	local tessQuantityY = 3 
--	local tessRandX = 1 
--	local tessRandY = 2
	local delay = 0 
	local duration = .4
	local pieceTimeRange =  1.
	local curvePower = 1
	local ani = KrImNodePoolAnimation(
		game:getEngine(),
		tessQuantityX,
		tessQuantityY,
		tessRandX,
		tessRandY,
		delay, 
		duration,
		pieceTimeRange,
		curvePower,
		true
	)
	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,50,255,255),
		KrRGBA(255,50,255,255)
	)
	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.POS,x1,y0,0,300)
	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, -10,10)
	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.SCALE, 1,1.2)
--	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR,3 )
	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ,1 )
	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, 0, .1, 1 )
--	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, 0, 0.6 , 1 )

	pairForStart:setLeavingAnimation(ani)

	--------------------------------------------------------------
	setUserDataPair(sprite, pairForStart)
	--------------------------------------------------------------	
end


function aniPoolWindowFrame(sprite,x0,x1,y0,tessQuantityX,tessQuantityY,tessRandX,tessRandY)
--	aniPoolHideOriginal(sprite)
	local game = getGameInstance()
	local pairForStart = ComingLeavingPair();
	-- coming Animation ------------------------------------------
	if x0 == nil
	then x0 = 1500
	end
	if x1 == nil
	then x1 = -1000
	end
	if y0 == nil
	then y0 = 0
	end
	if tessQuantityX == nil
	then tessQuantityX = 12
	end 
	if tessQuantityY == nil
	then tessQuantityY = 9
	end 
	if tessRandX == nil 
	then tessRandX = 2 
	end
	if tessRandY == nil
	then tessRandY = .2
	end 
	local delay = 0 
	local duration = .4
	local pieceTimeRange =  1.
	local curvePower = 1
	local ani = KrImNodePoolAnimation(
		game:getEngine(),
		tessQuantityX,
		tessQuantityY,
		tessRandX,
		tessRandY,
		delay, 
		duration,
		pieceTimeRange,
		curvePower,
		false
	)
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,255,255,255),
		KrRGBA(255,255,255,255)
	)
	
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.POS,x0,y0,0,300)
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.ROTZ, -3,3)
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.SCALE, 1,1.2)
	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR,3 )
	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ,16 )
	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, .7, 1, 1 )
	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, 0, 0.6 , 1 )
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,255,255,255),
		KrRGBA(255,255,255,255)
	)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.POS, x1,y0,0,300)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.ROTZ, -3,3)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.SCALE, 1,1.2)
	pairForStart:setComingAnimation(ani)

	-- leaving Animation ------------------------------------------

	local tessQuantityX = 12
	local tessQuantityY = 9 
	local tessRandX = 2 
	local tessRandY = .2
	local delay = 0 
	local duration = .2
	local pieceTimeRange =  1.
	local curvePower = 2
	local ani = KrImNodePoolAnimation(
		game:getEngine(),
		tessQuantityX,
		tessQuantityY,
		tessRandX,
		tessRandY,
		delay, 
		duration,
		pieceTimeRange,
		curvePower,
		true
	)

	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,255,255,255),
		KrRGBA(255,255,255,255)
	)

	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.POS, x1,y0,0,300)
	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, -3,3)
	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.SCALE, 1,1.2)
	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR,-3 )
	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ,-16 )
	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, 0, .2, .5 )
	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, 0, 0.3 , .5 )
	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.POS, .05, 0.3 , .5 )

	pairForStart:setLeavingAnimation(ani)

	--------------------------------------------------------------
	setUserDataPair(sprite, pairForStart)
	--------------------------------------------------------------
end

function aniPoolMesageWindow(sprite,x0,x1,duration,tessQuantityX,tessQuantityY,comingRad,leavingRad)
	local game = getGameInstance()
	local pairForStart = ComingLeavingPair();
	-- coming Animation ------------------------------------------
	if comingRad == nil
	then comingRad = 500
	end 
	if tessQuantityX == nil
	then tessQuantityX = 2
	end
	if tessQuantityY == nil
	then tessQuantityY = 2 
	end
	local tessRandX = 2 
	local tessRandY = .2
	local delay = 0 
	if duration == nil
	then duration = .4
	end
	local pieceTimeRange =  0
	local curvePower = 3
	local ani = KrImNodePoolAnimation(
		game:getEngine(),
		tessQuantityX,
		tessQuantityY,
		tessRandX,
		tessRandY,
		delay, 
		duration,
		pieceTimeRange,
		curvePower,
		false
	)
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,255,255,255),
		KrRGBA(255,255,255,255)
	)

	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.POS,0,0,comingRad,comingRad)
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.ROTZ, -3,3)
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.SCALE, 1,1.2)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,255,255,255),
		KrRGBA(255,255,255,255)
	)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.POS, 0,0,700,700)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.ROTZ, -3,3)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.SCALE, 1,1.2)
	pairForStart:setComingAnimation(ani)

	-- leaving Animation ------------------------------------------

	if leavingRad == nil
	then leavingRad = 700
	end
	curvePower = -3	
	local ani = KrImNodePoolAnimation(
		game:getEngine(),
		tessQuantityX,
		tessQuantityY,
		tessRandX,
		tessRandY,
		delay, 
		duration,
		pieceTimeRange,
		curvePower,
		true
	)

	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,255,255,255),
		KrRGBA(255,255,255,255)
	)

	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.POS, 0,0,leavingRad,leavingRad)
	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, -3,3)
	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.SCALE, 1,1.2)

	pairForStart:setLeavingAnimation(ani)

	--------------------------------------------------------------
	setUserDataPair(sprite, pairForStart)
	--------------------------------------------------------------
end

function aniPoolStartMenu(spriteBG)
-- spriteBG coming cycled animation ------------------------------------------
	local game = getGameInstance()
	local tessQuantityX = 12
	local tessQuantityY = 9 
	local tessRandX = 2
	local tessRandY = .2
	local delay = 0 
	local duration = 1
	local pieceTimeRange = .5
	local curvePower = 3
	local ani = KrImNodePoolAnimation(game:getEngine(),
		tessQuantityX,
		tessQuantityY,
		tessRandX,
		tessRandY,
		delay,
		duration,
		pieceTimeRange,
		curvePower,
		false
	)
	
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.COLOR, KrRGBA(255,200,255,255),KrRGBA(255,0,255,255))
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.POS, 0,0,800,1000)
	ani:set(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, -10,10)
	ani:set(KrImNodePoolAnimation.SRC, KrImNodePoolAnimation.SCALE, 1.1,1.1)

	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.POS, -4 )
	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, 1 )
	
	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, 1, 5, 4 )
	ani:setLoop(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.COLOR, KrImNodePoolAnimation.CYCLE)

	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, 1, 5, 4 )
	ani:setLoop(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, KrImNodePoolAnimation.CYCLE)
	ani:setPower(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.ROTZ, 25)

	ani:setTiming(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.SCALE, 1, 1, 1 )
	ani:setLoop(KrImNodePoolAnimation.DST, KrImNodePoolAnimation.SCALE, KrImNodePoolAnimation.PING_PONG)
	
	ani:setTiming(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.COLOR, 0, .1, 1 )
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.COLOR, 
		KrRGBA(255,50,255,255),
		KrRGBA(255,50,255,255)
	)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.POS,0,0,0,1500)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.ROTZ, -4,4)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.SCALE, 4,8)
	ani:set(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.COLOR, 		
		KrRGBA(255,0,255,0),
		KrRGBA(255,0,255,0)
	)
	ani:setTiming(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.POS, 0, .5, 0 )
	ani:setTiming(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.ROTZ, 0, .5, 0 )
	ani:setTiming(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.SCALE, 0, .5, 0 )
	ani:setTiming(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.COLOR, 0, .5, 0 )

	ani:setPower(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.POS, 2)
	ani:setPower(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.ROTZ, 2)
	ani:setPower(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.SCALE, 2)
	ani:setPower(KrImNodePoolAnimation.DST2, KrImNodePoolAnimation.COLOR, 1)
	
	
	local pairForStart = ComingLeavingPair();
	pairForStart:setComingAnimation(ani)


	-- leaving Animation ------------------------------------------

	local ani = KrImNodePoolAnimation(game:getEngine(),
		tessQuantityX,
		tessQuantityY,
		tessRandX,
		tessRandY,
		delay,
		duration,
		pieceTimeRange,
		curvePower,
		true
	)

	pairForStart:setLeavingAnimation(ani)


-------------------------------------------------------------
	setUserDataPair(spriteBG, pairForStart)
-------------------------------------------------------------

end
function initXBtn(btn, spriteName, posX, posY, sensorX, sensorY, sensorW, sensorH, vault)
	local icon = KrImNode();
	local sprite = KrSprite(vault:GetSpriteResource(spriteName))

	addNodeAdopt(sprite, icon);

	btn:setIcon(icon);
	btn:setSensorSize(sensorW, sensorH);
	btn:setSensorPos(sensorX, sensorY);
	btn:getRoot():SetPos(posX, posY, -1);

--	btn:getRoot():SetNodeName(name);

end

function initXBtnScaled(btn, spriteName, scaleX, scaleY, posX, posY, sensorX, sensorY, sensorW, sensorH, vault)
	local icon = KrImNode();
	local sprite = KrSprite(vault:GetSpriteResource(spriteName))
	setNodeScale(sprite, scaleX, scaleY);

	addNodeAdopt(sprite, icon);

	btn:setIcon(icon);
	btn:setSensorSize(sensorW, sensorH);
	btn:setSensorPos(sensorX, sensorY);
	btn:getRoot():SetPos(posX, posY, -1);

--	btn:getRoot():SetNodeName(name);

end

function getWndX(location)
	if location == "lu"	then
		return 149;
	elseif location == "ru"	then
		return 878;
	elseif location == "ld"	then
		return 149;
	elseif location == "rd"	then
		return 878;
	end	
end

function getWndY(location)
	if location == "lu"	then
		return 139;
	elseif location == "ru"	then
		return 142;
	elseif location == "ld"	then
		return 626;
	elseif location == "rd"	then
		return 628;
	end	
end

function addMusicianSkripBox1(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box1/skrip.ani", 2, root, speed);
	musician:getRoot():SetPos(getWndX(location) - 32, getWndY(location) + 9, -1);
	musician:getRoot():SetZDepth(-5);
	local skrip_telo = KrSprite( vault:GetSpriteResource("skrip_telo") );
	musician:addStaticNode(skrip_telo);
	local skrip_plecho = KrSprite( vault:GetSpriteResource("skrip_plecho") );
	musician:addDynamicNode(skrip_plecho, "predplech");
	local skrip_smichok = KrSprite( vault:GetSpriteResource("skrip_smichok") );
	musician:addDynamicNode(skrip_smichok, "srick");
	local skrip_predplech = KrSprite( vault:GetSpriteResource("skrip_predpl") );
	musician:addDynamicNode(skrip_predplech, "plecho");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianTrubBox1(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box1/trub.ani", 2, root, speed);
	musician:getRoot():SetPos(getWndX(location) + 27, getWndY(location) + 15, -1);
	musician:getRoot():SetZDepth(-5);

	local trub_telo = KrSprite( vault:GetSpriteResource("trub_telo") );
	musician:addStaticNode(trub_telo);
	local trub_plecho = KrSprite( vault:GetSpriteResource("trub_plecho") );
	musician:addDynamicNode(trub_plecho, "plecho");
	local trub_smichok = KrSprite( vault:GetSpriteResource("trub_stick") );
	musician:addDynamicNode(trub_smichok, "stick");
	local trub_predplech = KrSprite( vault:GetSpriteResource("trub_predplech") );
	musician:addDynamicNode(trub_predplech, "predplech");
	local trub_patch = KrSprite( vault:GetSpriteResource("trub_patch") );
	musician:addStaticNode(trub_patch);


	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianSaxBox1(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box1/sax.ani", 2, root, speed);
	musician:getRoot():SetPos(getWndX(location) - 5, getWndY(location) + 26, -1);
	musician:getRoot():SetZDepth(-5);

	local sax_l_plecho = KrSprite( vault:GetSpriteResource("sax_l_plecho") );
	musician:addDynamicNode(sax_l_plecho, "l_plecho");
	local sax_patch = KrSprite( vault:GetSpriteResource("sax_patch") );
	musician:addStaticNode(sax_patch);
	local sax_head = KrSprite( vault:GetSpriteResource("sax_head") );
	musician:addDynamicNode(sax_head, "head");
	local sax_sax = KrSprite( vault:GetSpriteResource("sax_sax") );
	musician:addDynamicNode(sax_sax, "sax");
	local sax_telo = KrSprite( vault:GetSpriteResource("sax_telo") );
	musician:addStaticNode(sax_telo);
	local sax_r_plecho = KrSprite( vault:GetSpriteResource("sax_r_plecho") );
	musician:addDynamicNode(sax_r_plecho, "r_plecho");
	local sax_r_predpl = KrSprite( vault:GetSpriteResource("sax_r_predpl") );
	musician:addDynamicNode(sax_r_predpl, "r_predpl");


	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianManBox1(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box1/man.ani", 2, root, speed);
	musician:getRoot():SetPos(getWndX(location) - 25, getWndY(location) + 7, -1);
	musician:getRoot():SetZDepth(-5);

	local man_head = KrSprite( vault:GetSpriteResource("man_head") );
	musician:addDynamicNode(man_head, "man_head");
	local man_body = KrSprite( vault:GetSpriteResource("man_body") );
	musician:addStaticNode(man_body);
	local man_pl = KrSprite( vault:GetSpriteResource("man_pl") );
	musician:addDynamicNode(man_pl, "man_pl");
	local man_prpl = KrSprite( vault:GetSpriteResource("man_prpl") );
	musician:addDynamicNode(man_prpl, "man_prpl");


	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianPianBox1(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box1/pian.ani", 2, root, speed);
	musician:getRoot():SetPos(getWndX(location) - 20, getWndY(location) + 41, -1);
	musician:getRoot():SetZDepth(-5);

	local pian_pian = KrSprite( vault:GetSpriteResource("pian_pian") );
	musician:addStaticNode(pian_pian);
	local pian_prpl_l = KrSprite( vault:GetSpriteResource("pian_prpl_l") );
	musician:addDynamicNode(pian_prpl_l, "pian_prpl_l");
	local pian_head = KrSprite( vault:GetSpriteResource("pian_head") );
	musician:addDynamicNode(pian_head, "pian_head");
	local pian_body = KrSprite( vault:GetSpriteResource("pian_body") );
	musician:addDynamicNode(pian_body, "pian_body");
	local pian_pl = KrSprite( vault:GetSpriteResource("pian_pl") );
	musician:addDynamicNode(pian_pl, "pian_pl");
	local pian_prpl_r = KrSprite( vault:GetSpriteResource("pian_prpl_r") );
	musician:addDynamicNode(pian_prpl_r, "pian_prpl_r");

	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianBarBox1(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box1/bar.ani", 2, root, speed);
	musician:getRoot():SetPos(getWndX(location) + 10, getWndY(location) + 17, -1);
	musician:getRoot():SetZDepth(-5);

	local bar_r_predpl = KrSprite( vault:GetSpriteResource("bar_r_predpl") );
	musician:addDynamicNode(bar_r_predpl, "r_predpl");
	local bar_r_plecho = KrSprite( vault:GetSpriteResource("bar_r_plecho") );
	musician:addDynamicNode(bar_r_plecho, "r_plecho");
	local bar_telo = KrSprite( vault:GetSpriteResource("bar_telo") );
	musician:addStaticNode(bar_telo);
	local bar_l_plecho = KrSprite( vault:GetSpriteResource("bar_l_plecho") );
	musician:addDynamicNode(bar_l_plecho, "l_plecho");
	local bar_l_predpl = KrSprite( vault:GetSpriteResource("bar_l_predpl") );
	musician:addDynamicNode(bar_l_predpl, "l_predpl");
	local bar_bar = KrSprite( vault:GetSpriteResource("bar-bar") );
	bar_bar:SetPos(-28, 34, -1);
	bar_bar:SetRotZ(3.14 / 8.0, -1);
	musician:addStaticNode(bar_bar);


	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianSkripBox2(vault, speed, location, root, mission, index)
	local posX = 0;
	local posY = 0;

	if location == "lu"	then
		posX = 137;
		posY = 168;
	elseif location == "ru"	then
		posX = 137;
		posY = 168;
	elseif location == "ld"	then
		posX = 134;
		posY = 634;
	elseif location == "rd"	then
		posX = 839;
		posY = 634;
	end	

	local musician = Musician("../data/mission/box2/scrip.ani", 2, root, speed);
	musician:getRoot():SetPos(posX, posY, -1);
	musician:getRoot():SetZDepth(-12);
	local skrip_telo = KrSprite( vault:GetSpriteResource("scrip_telo") );
	musician:addStaticNode(skrip_telo);
	local skrip_plecho = KrSprite( vault:GetSpriteResource("scrip_pl") );
	musician:addDynamicNode(skrip_plecho, "scrip_pl");
	local skrip_smichok = KrSprite( vault:GetSpriteResource("scrip_sm") );
	musician:addDynamicNode(skrip_smichok, "scrip_sm");
	local skrip_predplech = KrSprite( vault:GetSpriteResource("scrip_pr") );
	musician:addDynamicNode(skrip_predplech, "scrip_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianPianBox2(vault, speed, location, root, mission, index)
	local posX = 0;
	local posY = 0;
	if location == "lu"	then
		posX = 137;
		posY = 168;
	elseif location == "ru"	then
		posX = 833;
		posY = 163;
	elseif location == "ld"	then
		posX = 137;
		posY = 168;
	elseif location == "rd"	then
		posX = 137;
		posY = 168;
	end	

	local musician = Musician("../data/mission/box2/pian.ani", 2, root, speed);
	musician:getRoot():SetPos(posX, posY, -1);
	musician:getRoot():SetZDepth(-12);
	local pian_telo = KrSprite( vault:GetSpriteResource("pian_telo") );
	musician:addStaticNode(pian_telo);
	local pian_pl = KrSprite( vault:GetSpriteResource("pian_pl") );
	musician:addDynamicNode(pian_pl, "pian_pl");
	local pian_pr = KrSprite( vault:GetSpriteResource("pian_pr") );
	musician:addDynamicNode(pian_pr, "pian_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianManBox2(vault, speed, location, root, mission, index)
	local posX = 0;
	local posY = 0;
	if location == "lu"	then
		posX = 137;
		posY = 168;
	elseif location == "ru"	then
		posX = 833;
		posY = 163;
	elseif location == "ld"	then
		posX = 140;
		posY = 624;
	elseif location == "rd"	then
		posX = 845;
		posY = 636;
	end	

	local musician = Musician("../data/mission/box2/man.ani", 2, root, speed);
	musician:getRoot():SetPos(posX, posY, -1);
	musician:getRoot():SetZDepth(-12);
	local man_telo = KrSprite( vault:GetSpriteResource("man_telo") );
	musician:addStaticNode(man_telo);
	local man_pl = KrSprite( vault:GetSpriteResource("man_pl") );
	musician:addDynamicNode(man_pl, "man_pl");
	local man_pr = KrSprite( vault:GetSpriteResource("man_pr") );
	musician:addDynamicNode(man_pr, "man_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianTrubBox2(vault, speed, location, root, mission, index)
	local posX = 0;
	local posY = 0;
	if location == "lu"	then
		posX = 185;
		posY = 168;
	elseif location == "ru"	then
		posX = 833;
		posY = 163;
	elseif location == "ld"	then
		posX = 140;
		posY = 624;
	elseif location == "rd"	then
		posX = 885;
		posY = 636;
	end	

	local musician = Musician("../data/mission/box2/trub.ani", 2, root, speed);
	musician:getRoot():SetPos(posX, posY, -1);
	musician:getRoot():SetZDepth(-12);
	local trub_telo = KrSprite( vault:GetSpriteResource("trub_telo") );
	musician:addStaticNode(trub_telo);
	local trub_pl = KrSprite( vault:GetSpriteResource("trub_pl") );
	musician:addDynamicNode(trub_pl, "trub_pl");
	local trub_pr = KrSprite( vault:GetSpriteResource("trib_pr") );
	musician:addDynamicNode(trub_pr, "trub_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianBarBox2(vault, speed, location, root, mission, index)
	local posX = 0;
	local posY = 0;
	if location == "lu"	then
		posX = 137;
		posY = 168;
	elseif location == "ru"	then
		posX = 877;
		posY = 165;
	elseif location == "ld"	then
		posX = 188;
		posY = 624;
	elseif location == "rd"	then
		posX = 885;
		posY = 636;
	end	

	local musician = Musician("../data/mission/box2/bar.ani", 2, root, speed);
	musician:getRoot():SetPos(posX, posY, -1);
	musician:getRoot():SetZDepth(-12);
	local bar_telo = KrSprite( vault:GetSpriteResource("bar_telo") );
	musician:addStaticNode(bar_telo);
	local bar_pl = KrSprite( vault:GetSpriteResource("bar_pl") );
	musician:addDynamicNode(bar_pl, "bar_pl");
	local bar_pr = KrSprite( vault:GetSpriteResource("bar_pr") );
	musician:addDynamicNode(bar_pr, "bar_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function getWnd3X(location)
	if location == "lu"	then
		return 143;
	elseif location == "ru"	then
		return 886;
	elseif location == "ld"	then
		return 143;
	elseif location == "rd"	then
		return 886;
	end	
end

function getWnd3Y(location)
	if location == "lu"	then
		return 124;
	elseif location == "ru"	then
		return 124;
	elseif location == "ld"	then
		return 634;
	elseif location == "rd"	then
		return 634;
	end	
end

function addMusicianSkripBox3(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box3/skrip.ani", 2, root, speed);
	musician:getRoot():SetPos(getWnd3X(location) - 37, getWnd3Y(location) + 14, -1);
	musician:getRoot():SetZDepth(-5);
	local skrip_telo = KrSprite( vault:GetSpriteResource("skrip_body") );
	musician:addStaticNode(skrip_telo);
	local skrip_plecho = KrSprite( vault:GetSpriteResource("skrip_pl") );
	musician:addDynamicNode(skrip_plecho, "skrip_pl");
	local skrip_smichok = KrSprite( vault:GetSpriteResource("skrip_sm") );
	musician:addDynamicNode(skrip_smichok, "skrip_sm");
	local skrip_predplech = KrSprite( vault:GetSpriteResource("skrip_pr") );
	musician:addDynamicNode(skrip_predplech, "skrip_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianTrubBox3(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box3/trub.ani", 2, root, speed);
	musician:getRoot():SetPos(getWnd3X(location) + 47, getWnd3Y(location) + 13, -1);
	musician:getRoot():SetZDepth(-5);
	local trub_telo = KrSprite( vault:GetSpriteResource("trub_body") );
	musician:addStaticNode(trub_telo);
	local trub_pl = KrSprite( vault:GetSpriteResource("trub_pl") );
	musician:addDynamicNode(trub_pl, "trub_pl");
	local trub_pr = KrSprite( vault:GetSpriteResource("trub_pr") );
	musician:addDynamicNode(trub_pr, "trub_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianBarBox3(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box3/bara.ani", 2, root, speed);
	musician:getRoot():SetPos(getWnd3X(location) - 37, getWnd3Y(location) + 16, -1);
	musician:getRoot():SetZDepth(-5);
	local bar_telo = KrSprite( vault:GetSpriteResource("bara_body") );
	musician:addStaticNode(bar_telo);
	local bar_pl = KrSprite( vault:GetSpriteResource("bara_pl") );
	musician:addDynamicNode(bar_pl, "bara_pl");
	local bar_pr = KrSprite( vault:GetSpriteResource("bara_pr") );
	musician:addDynamicNode(bar_pr, "bara_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianManBox3(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box3/mand.ani", 2, root, speed);
	musician:getRoot():SetPos(getWnd3X(location) + 36, getWnd3Y(location) + 14, -1);
	musician:getRoot():SetZDepth(-5);
	local man_telo = KrSprite( vault:GetSpriteResource("mand_body") );
	musician:addStaticNode(man_telo);
	local man_pl = KrSprite( vault:GetSpriteResource("mand_pl") );
	musician:addDynamicNode(man_pl, "mand_pl");
	local man_pr = KrSprite( vault:GetSpriteResource("mand_pr") );
	musician:addDynamicNode(man_pr, "mand_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end

function addMusicianPianBox3(vault, speed, location, root, mission, index)
	local musician = Musician("../data/mission/box3/pian.ani", 2, root, speed);
	musician:getRoot():SetPos(getWnd3X(location) - 37, getWnd3Y(location) + 16, -1);
	musician:getRoot():SetZDepth(-5);
	local pian_telo = KrSprite( vault:GetSpriteResource("pian_body") );
	musician:addStaticNode(pian_telo);
	local pian_pl = KrSprite( vault:GetSpriteResource("pian_pl") );
	musician:addDynamicNode(pian_pl, "pian_pl");
	local pian_pr = KrSprite( vault:GetSpriteResource("pian_pr") );
	musician:addDynamicNode(pian_pr, "pian_pr");
	musician:setStartPos();
	mission:addAnimationNode(musician, index)
end


function placeStandBorder(vault, parent, name, posX, posY, x, y)
	local standB = KrSprite(vault:GetSpriteResource(name))
	standB:SetPos(posX + 64 * x, posY + 64 * y, -1);
	addNodeAdopt(standB, parent)
end

function placeStandBorderEx(vault, parent, name, posX, posY, x, y, shiftX, shiftY)
	local standB = KrSprite(vault:GetSpriteResource(name))
	standB:SetPos(posX + 64 * x + shiftX, posY + 64 * y + shiftY, -1);
	addNodeAdopt(standB, parent)
end


function aniOutline(node,delay, durIn, leavDelay, durOut, alpha)
	local a = KrImNodeCurveAnimation();
	local curveA = ParameterCurve();
	curveA:setStartValue( 0 );
	curveA:addKey(delay, 0, IParameterCurve.LINEAR);
	curveA:addKey(delay + durIn, alpha, IParameterCurve.LINEAR);
	a:setAlphaCurve(curveA);

	local pairForStart = ComingLeavingPair();
	pairForStart:setComingAnimation(a)

	a = KrImNodeCurveAnimation();
	curveA = ParameterCurve();
	curveA:setStartValue( alpha );
	curveA:addKey(leavDelay, 0, IParameterCurve.LINEAR);
	curveA:addKey(leavDelay + durOut, -alpha, IParameterCurve.LINEAR);
	a:setAlphaCurve(curveA);

	pairForStart:setLeavingAnimation(a)
	setUserDataPair(node , pairForStart)
end

function createBrokenOutline(menu, vault, parent, outline, count, location, posX, posY, delayInTime, inTime, delayOutTime, outTime)
	local brokenOutline = BrokenOutline()

	local bg = KrSprite(vault:GetSpriteResource("bookout_" .. location .."_bg"))
--	local bg = KrSprite(vault:GetSpriteResource("bookout_LU_bg"))
	brokenOutline:setBGSprite(bg);
	if (outline == nil) then
	else
		local outlineSprite = KrSprite(vault:GetSpriteResource(outline))
		if (location == "LD" or location == "RD") then
			brokenOutline:setOutlineSprite(outlineSprite, true);
		else
			brokenOutline:setOutlineSprite(outlineSprite, false);
		end
	end

	if (count > 1) then
		local breakLine = KrSprite(vault:GetSpriteResource("bookout_" .. location .."_break_" .. count))
		brokenOutline:setBreakLineSprite(breakLine);
	end

	if (count == 4) then
		for i = 1, 4 do
			local patch = KrSprite(vault:GetSpriteResource("bookout_" .. location .."_patch_" .. i))
			brokenOutline:addPatch(patch);
		end
	elseif (count == 3) then
		local patch = KrSprite(vault:GetSpriteResource("bookout_" .. location .."_patch_d_1"))
		brokenOutline:addPatch(patch);
		patch = KrSprite(vault:GetSpriteResource("bookout_" .. location .."_patch_1"))
		brokenOutline:addPatch(patch);
		patch = KrSprite(vault:GetSpriteResource("bookout_" .. location .."_patch_2"))
		brokenOutline:addPatch(patch);
	elseif (count == 2) then
		local patch = KrSprite(vault:GetSpriteResource("bookout_" .. location .."_patch_d_1"))
		brokenOutline:addPatch(patch);
		patch = KrSprite(vault:GetSpriteResource("bookout_" .. location .."_patch_d_2"))
		brokenOutline:addPatch(patch);
	end

	
	local solvedRoot = KrImNode();

	local textBox = KrTextBox(game:getFontResource("occ14b"), 100, 100, 2, KrTextBox.CENTER);
	textBox:SetPos(77, -4, -1);
	textBox:SetText("(Solved)", 0);
	if (location == "LU") then
		setTextColor(textBox, 163, 50, 9, 255)
	elseif (location == "RU") then
		setTextColor(textBox, 163, 50, 9, 255)
	elseif (location == "LD") then
		setTextColor(textBox, 163, 54, 15, 255)
	else
		setTextColor(textBox, 145, 45, 9, 255)
	end

	addNodeAdopt(textBox, solvedRoot);

	local ynderline = KrSprite(vault:GetSpriteResource("ynderline_"..location))
	ynderline:SetPos(87, 17, -1);
	addNodeAdopt(ynderline, solvedRoot);

	brokenOutline:setSolvedMarkSprite(solvedRoot);

	local hl = KrSprite(vault:GetSpriteResource("hightlightOut"))
	hl:SetPos(0, 11, -1);
	setNodeScale(hl, 4, 4);

	if (location == "LD" or location == "RD") then
		setAdditive(hl, true, 100);
	else
		setAdditive(hl, true, 70);
	end

	brokenOutline:setHighlightSprite(hl);


	brokenOutline:getRoot():SetPos(posX, posY, -1);

--	aniFadeInFadeOut(brokenOutline:getRoot(), delayTime, inTime, outTime, 255)
	aniOutline(brokenOutline:getRoot(), delayInTime, inTime, delayOutTime, outTime, 255)


	if (location == "LU") then
		brokenOutline:setPs(0);
	elseif (location == "RD") then
		brokenOutline:setPs(1);
	elseif (location == "RU") then
		brokenOutline:setPs(2);
	else
		brokenOutline:setPs(3);
	end

	menu:addBrokenOutline(brokenOutline);
end


function aniHover(node,delay, durIn, durOut,leavingDurIn, leavingDurOut,alpha)

	local a = KrImNodeCurveAnimation();
	local curveA = ParameterCurve();
	curveA:setStartValue( 0 );
	curveA:addKey(durIn, 0, IParameterCurve.LINEAR);
	curveA:addKey(durIn + 0.001, alpha, IParameterCurve.LINEAR);
	curveA:addKey(durIn + durOut, -alpha, IParameterCurve.LINEAR);
	a:setAlphaCurve(curveA);

	local pairForStart = ComingLeavingPair();
	pairForStart:setComingAnimation(a)

	a = KrImNodeCurveAnimation();
	curveA = ParameterCurve();
	curveA:setStartValue( 0 );
	curveA:addKey(leavingDurIn, alpha, IParameterCurve.LINEAR);
	curveA:addKey(leavingDurIn + leavingDurOut, -alpha, IParameterCurve.LINEAR);
	a:setAlphaCurve(curveA);

	pairForStart:setLeavingAnimation(a)
	setUserDataPair(node , pairForStart)
end

function createNameBG(parent, textWidth, vault, shX, shY)
	local div = math.ceil( textWidth / 50 ) - 2;

	local nameBGRoot = KrImNode();

	local sprite = KrSprite(vault:GetSpriteResource("name_bg_left"));
	addNodeAdopt(sprite, nameBGRoot);

	local currX = 0;

	for i = 0, div do
		sprite = KrSprite(vault:GetSpriteResource("name_bg_tile"));
		sprite:SetPos(currX, 0, -1);
		addNodeAdopt(sprite, nameBGRoot);
		currX = currX + 50;
	end

	sprite = KrSprite(vault:GetSpriteResource("name_bg_right"));
	sprite:SetPos(currX - 50, 0, -1);
	addNodeAdopt(sprite, nameBGRoot);

	nameBGRoot:SetPos(512 - 25 - div * 25 + shX, 2 + shY, -1);


	addNodeAdopt(nameBGRoot, parent);
end


function createName(textR, textG, textB, shX, shY, shTextX, shTextY, vault, parent, game, mission)

	local nameTextBox = KrTextBox(game:getFontResource("occ24b"), 1000, 45, 1, KrTextBox.CENTER);
	nameTextBox:SetText(getText("MELODY."..mission:getName().."_short"), 0);
	setTextColor(nameTextBox, textR, textG, textB, 255);

	createNameBG(parent, nameTextBox:getLineWidth(0), vault, shX, shY);

	nameTextBox:SetPos(12 + 3 + shTextX, 6 + shTextY, -1);
	addNodeAdopt(nameTextBox, parent);
end

function createNameBox1(vault, parent, game, mission)
	createName(232, 199, 70, 4, 0, 0, 2, vault, parent, game, mission)
end

function createNameBox2(vault, parent, game, mission)
	createName(238, 223, 138, 0, 0, -4, 2, vault, parent, game, mission)
end

function createNameBox3(vault, parent, game, mission)
	createName(227, 207, 76, 0, 0, -4, 2, vault, parent, game, mission)
end
