--// Local auxiliary functions - - - - - - - - - - - - - - - - - - - - - - - -

--// 1.	rename:					" -> '
--// 2. comment composition background element with texture "BG_zum_1.jpg"
--// 3. add auxiliaru routines for managing animations: 
--		auxPlayCandleCaveAltarZoomAnimation(), 
--		auxGetCandleCaveAltarZoomAnimation(), 
--		auxCreateCandleCaveAltarZoomAnimations()
--// 4. replace CreateCompositionElement() with auxCreateCompositionElement() for some corrections ...

------------------------------------------------------------------------------
--
function auxPlayCandleCaveAltarZoomAnimation(compositionName)
    local composition = auxGetCandleCaveAltarZoomAnimation(compositionName);
    composition:SetVisible(true);
    composition:Play();
end

------------------------------------------------------------------------------
--
function auxHideCandleCaveAltarZoomAnimation(compositionName)
    local composition = auxGetCandleCaveAltarZoomAnimation(compositionName);
    composition:Stop();
    composition:SetVisible(false);
end

------------------------------------------------------------------------------
--
function auxGetCandleCaveAltarZoomAnimation(compositionName)
    assert(candleCaveAltarZoomCompositions ~= nil and compositionName ~= nil);
	assert(candleCaveAltarZoomCompositions[compositionName] ~= nil and 'Composition with specified name not exists !');

    return candleCaveAltarZoomCompositions[compositionName];
end

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
--

function CreateComposition(parent, compositionRoutine, name, x,y,z, hotSpotX,hotSpotY, duration, isCyclic)
    assert(parent ~= nil and compositionRoutine ~= nil and name ~= nil and z ~= nil and duration ~= nil);

    local element = compositionRoutine();
    element:SetName(name);
    element:SetHotSpot(hotSpotX,hotSpotY);
    element:SetXY(x, y);
    assert(z - parent:GetZ());
    element:SetZ(z - parent:GetZ());
    element:AttachTo(parent);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    if (isCyclic == true) then
        element:SetDuration(duration);
        element:SetCyclic(true);
    end
	element:Stop();
    element:SetVisible(false);
    element:AssignClippingRect(parent);
	element:SetConsiderParentOpacity(true);

	return element;
end

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function auxCreateCompositionElement(resourceName)
	local element = CreateCompositionElement(resourceName);
    local texName = string.sub(resourceName, string.len('data/Texture/Scenes/17_CandleCaveAltarZoom/Animations/Env') + 1);

    --// set up blend mode for sprites with additive blending
--	if (texName == '.jpg') then
--		element:GetTexture():SetColor('0xBBFFFFFF');
        element:GetTexture():SetBlendMode(0);
--    end
	return element;
end

------------------------------------------------------------------------------
--
function auxCreateCandleCaveAltarZoomAnimations(parent)
    assert(parent ~= nil);
    candleCaveAltarZoomCompositions = {};
    local CreateAndRegisterComposition = function (parent, compositionRoutine, name, x,y,z, hotSpotX,hotSpotY, duration, isCyclic)
        local element = CreateComposition(parent, compositionRoutine, name, x,y,z, hotSpotX,hotSpotY, duration, isCyclic);
        candleCaveAltarZoomCompositions[element:GetName()] = element;
    end
    
    CreateAndRegisterComposition(parent, createCompositionBG_zum_1,  'ForceField', 0,0,206.0, 320,240, 10, true);
end

------------------------------------------------------------------------------
--
createCompositionBG_zum_1 = function()

    local compositionBG_zum_1 = CreateCompositionSequence();
    local compositionDuration = 10;
    compositionBG_zum_1:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/17_CandleCave/Animations/Env/EF_Sparcle01.jpg');
    element:SetName('Layer_1');
    compositionBG_zum_1:AddElement(element);
    element:SetHotSpot(64, 57);
    element:SetParentElement(compositionBG_zum_1);
    element:SetScaleX(1.65625);
    element:SetScaleY(3.68421052631579);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_X, 0, 319);
    effector:SetKey(_TRACK_Y, 0, 256);
    effector:SetKey(_TRACK_X, 0.4, 319);
    effector:SetKey(_TRACK_Y, 0.4, 181);
    effector:SetKey(_TRACK_X, 0.6, 319);
    effector:SetKey(_TRACK_Y, 0.6, 205);
    effector:SetKey(_TRACK_X, 1, 319);
    effector:SetKey(_TRACK_Y, 1, 130);
    effector:SetKey(_TRACK_X, 1.32, 320);
    effector:SetKey(_TRACK_Y, 1.32, 292);
    effector:SetKey(_TRACK_X, 1.72, 320);
    effector:SetKey(_TRACK_Y, 1.72, 217);
    effector:SetKey(_TRACK_X, 1.92, 320);
    effector:SetKey(_TRACK_Y, 1.92, 232);
    effector:SetKey(_TRACK_X, 2.32, 320);
    effector:SetKey(_TRACK_Y, 2.32, 157);
    effector:SetKey(_TRACK_X, 2.56, 318);
    effector:SetKey(_TRACK_Y, 2.56, 185);
    effector:SetKey(_TRACK_X, 2.96, 318);
    effector:SetKey(_TRACK_Y, 2.96, 110);
    effector:SetKey(_TRACK_X, 3.16, 320);
    effector:SetKey(_TRACK_Y, 3.16, 273);
    effector:SetKey(_TRACK_X, 3.56, 320);
    effector:SetKey(_TRACK_Y, 3.56, 198);
    effector:SetKey(_TRACK_X, 3.68, 320);
    effector:SetKey(_TRACK_Y, 3.68, 245);
    effector:SetKey(_TRACK_X, 4.08, 320);
    effector:SetKey(_TRACK_Y, 4.08, 170);
    effector:SetKey(_TRACK_X, 4.28, 318);
    effector:SetKey(_TRACK_Y, 4.28, 261);
    effector:SetKey(_TRACK_X, 4.68, 318);
    effector:SetKey(_TRACK_Y, 4.68, 186);
    effector:SetKey(_TRACK_X, 5.24, 319);
    effector:SetKey(_TRACK_Y, 5.24, 256);
    effector:SetKey(_TRACK_X, 5.64, 319);
    effector:SetKey(_TRACK_Y, 5.64, 181);
    effector:SetKey(_TRACK_X, 5.84, 319);
    effector:SetKey(_TRACK_Y, 5.84, 205);
    effector:SetKey(_TRACK_X, 6.24, 319);
    effector:SetKey(_TRACK_Y, 6.24, 130);
    effector:SetKey(_TRACK_X, 6.56, 320);
    effector:SetKey(_TRACK_Y, 6.56, 292);
    effector:SetKey(_TRACK_X, 6.96, 320);
    effector:SetKey(_TRACK_Y, 6.96, 217);
    effector:SetKey(_TRACK_X, 7.16, 320);
    effector:SetKey(_TRACK_Y, 7.16, 232);
    effector:SetKey(_TRACK_X, 7.56, 320);
    effector:SetKey(_TRACK_Y, 7.56, 157);
    effector:SetKey(_TRACK_X, 7.8, 318);
    effector:SetKey(_TRACK_Y, 7.8, 185);
    effector:SetKey(_TRACK_X, 8.2, 318);
    effector:SetKey(_TRACK_Y, 8.2, 110);
    effector:SetKey(_TRACK_X, 8.4, 320);
    effector:SetKey(_TRACK_Y, 8.4, 273);
    effector:SetKey(_TRACK_X, 8.8, 320);
    effector:SetKey(_TRACK_Y, 8.8, 198);
    effector:SetKey(_TRACK_X, 8.92, 320);
    effector:SetKey(_TRACK_Y, 8.92, 245);
    effector:SetKey(_TRACK_X, 9.32, 320);
    effector:SetKey(_TRACK_Y, 9.32, 170);
    effector:SetKey(_TRACK_X, 9.52, 318);
    effector:SetKey(_TRACK_Y, 9.52, 261);
    effector:SetKey(_TRACK_X, 9.92, 318);
    effector:SetKey(_TRACK_Y, 9.92, 186);
    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 0.2, 1);
    effector:SetKey(_TRACK_O, 0.4, 0);
    effector:SetKey(_TRACK_O, 0.6, 0);
    effector:SetKey(_TRACK_O, 0.8, 1);
    effector:SetKey(_TRACK_O, 1, 0);
    effector:SetKey(_TRACK_O, 1.32, 0);
    effector:SetKey(_TRACK_O, 1.52, 1);
    effector:SetKey(_TRACK_O, 1.72, 0);
    effector:SetKey(_TRACK_O, 1.92, 0);
    effector:SetKey(_TRACK_O, 2.12, 1);
    effector:SetKey(_TRACK_O, 2.32, 0);
    effector:SetKey(_TRACK_O, 2.56, 0);
    effector:SetKey(_TRACK_O, 2.76, 1);
    effector:SetKey(_TRACK_O, 2.96, 0);
    effector:SetKey(_TRACK_O, 3.16, 0);
    effector:SetKey(_TRACK_O, 3.36, 1);
    effector:SetKey(_TRACK_O, 3.56, 0);
    effector:SetKey(_TRACK_O, 3.68, 0);
    effector:SetKey(_TRACK_O, 3.88, 1);
    effector:SetKey(_TRACK_O, 4.08, 0);
    effector:SetKey(_TRACK_O, 4.28, 0);
    effector:SetKey(_TRACK_O, 4.48, 1);
    effector:SetKey(_TRACK_O, 4.68, 0);
    effector:SetKey(_TRACK_O, 5.24, 0);
    effector:SetKey(_TRACK_O, 5.44, 1);
    effector:SetKey(_TRACK_O, 5.64, 0);
    effector:SetKey(_TRACK_O, 5.84, 0);
    effector:SetKey(_TRACK_O, 6.04, 1);
    effector:SetKey(_TRACK_O, 6.24, 0);
    effector:SetKey(_TRACK_O, 6.56, 0);
    effector:SetKey(_TRACK_O, 6.76, 1);
    effector:SetKey(_TRACK_O, 6.96, 0);
    effector:SetKey(_TRACK_O, 7.16, 0);
    effector:SetKey(_TRACK_O, 7.36, 1);
    effector:SetKey(_TRACK_O, 7.56, 0);
    effector:SetKey(_TRACK_O, 7.8, 0);
    effector:SetKey(_TRACK_O, 8, 1);
    effector:SetKey(_TRACK_O, 8.2, 0);
    effector:SetKey(_TRACK_O, 8.4, 0);
    effector:SetKey(_TRACK_O, 8.6, 1);
    effector:SetKey(_TRACK_O, 8.8, 0);
    effector:SetKey(_TRACK_O, 8.92, 0);
    effector:SetKey(_TRACK_O, 9.12, 1);
    effector:SetKey(_TRACK_O, 9.32, 0);
    effector:SetKey(_TRACK_O, 9.52, 0);
    effector:SetKey(_TRACK_O, 9.72, 1);
    effector:SetKey(_TRACK_O, 9.92, 0);

    effector:Play();


    -- Layer Layer_2
    local element = auxCreateCompositionElement('data/Texture/Scenes/17_CandleCave/Animations/Env/EF_Lightning01.jpg');
    element:SetName('Layer_2');
    compositionBG_zum_1:AddElement(element);
    element:SetHotSpot(64.5, 147);
    element:SetParentElement(compositionBG_zum_1);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_X, 0, 332.567565917969);
    effector:SetKey(_TRACK_Y, 0, 224.855850219727);
    effector:SetKey(_TRACK_X, 1.12, 332.567565917969);
    effector:SetKey(_TRACK_Y, 1.12, 224.855850219727);
    effector:SetKey(_TRACK_X, 1.24, 332.567565917969);
    effector:SetKey(_TRACK_Y, 1.24, 224.855850219727);
    effector:SetKey(_TRACK_X, 1.52, 288.747741699219);
    effector:SetKey(_TRACK_Y, 1.52, 212.171173095703);
    effector:SetKey(_TRACK_X, 1.88, 249.540542602539);
    effector:SetKey(_TRACK_Y, 1.88, 201.792785644531);
    effector:SetKey(_TRACK_X, 2.04, 249.540542602539);
    effector:SetKey(_TRACK_Y, 2.04, 201.792785644531);
    effector:SetKey(_TRACK_X, 2.48, 332.567565917969);
    effector:SetKey(_TRACK_Y, 2.48, 205.252243041992);
    effector:SetKey(_TRACK_X, 5.32, 332.567565917969);
    effector:SetKey(_TRACK_Y, 5.32, 224.855850219727);
    effector:SetKey(_TRACK_X, 5.44, 332.567565917969);
    effector:SetKey(_TRACK_Y, 5.44, 224.855850219727);
    effector:SetKey(_TRACK_X, 5.72, 288.747741699219);
    effector:SetKey(_TRACK_Y, 5.72, 212.171173095703);
    effector:SetKey(_TRACK_X, 7.88, 249.540542602539);
    effector:SetKey(_TRACK_Y, 7.88, 201.792785644531);
    effector:SetKey(_TRACK_X, 8.32, 289.900894165039);
    effector:SetKey(_TRACK_Y, 8.32, 187.954940795898);
    effector:SetKey(_TRACK_X, 9.96, 332.567565917969);
    effector:SetKey(_TRACK_Y, 9.96, 224.855850219727);
    effector:SetKey(_TRACK_SX, 0, 2.16279069767442);
    effector:SetKey(_TRACK_SY, 0, 1.78231292517007);
    effector:SetKey(_TRACK_SX, 1.12, 1.7873454850199);
    effector:SetKey(_TRACK_SY, 1.12, 1.72740087025801);
    effector:SetKey(_TRACK_SX, 1.28, 2.26279069767442);
    effector:SetKey(_TRACK_SY, 1.28, 1.88231292517007);
    effector:SetKey(_TRACK_SX, 1.32, 0.1352678259655);
    effector:SetKey(_TRACK_SY, 1.32, 1.88231292517007);
    effector:SetKey(_TRACK_SX, 1.4, 1.28255464767094);
    effector:SetKey(_TRACK_SY, 1.4, 1.88231292517007);
    effector:SetKey(_TRACK_SX, 1.44, 2.40581744535233);
    effector:SetKey(_TRACK_SY, 1.44, 2.01567077281363);
    effector:SetKey(_TRACK_SX, 1.76, 2.40581744535233);
    effector:SetKey(_TRACK_SY, 1.76, 2.01567077281363);
    effector:SetKey(_TRACK_SX, 1.88, -2.06585655422865);
    effector:SetKey(_TRACK_SY, 1.88, 1.57363485934914);
    effector:SetKey(_TRACK_SX, 2.04, 1.76219708080173);
    effector:SetKey(_TRACK_SY, 2.04, 1.95291413862843);
    effector:SetKey(_TRACK_SX, 2.08, 1.23604301976395);
    effector:SetKey(_TRACK_SY, 2.08, 1.84149659863946);
    effector:SetKey(_TRACK_SX, 2.16, -0.8462252950625);
    effector:SetKey(_TRACK_SY, 2.16, 1.51000183857327);
    effector:SetKey(_TRACK_SX, 2.2, 2.40581744535233);
    effector:SetKey(_TRACK_SY, 2.2, 2.01567077281363);
    effector:SetKey(_TRACK_SX, 2.28, 1.92512226000598);
    effector:SetKey(_TRACK_SY, 2.28, 2.18085998085998);
    effector:SetKey(_TRACK_SX, 5.32, -1.62350722815839);
    effector:SetKey(_TRACK_SY, 5.32, 1.70699270699271);
    effector:SetKey(_TRACK_SX, 5.48, 2.26279069767442);
    effector:SetKey(_TRACK_SY, 5.48, 1.88231292517007);
    effector:SetKey(_TRACK_SX, 5.52, 1.25741322718067);
    effector:SetKey(_TRACK_SY, 5.52, 1.49946068517497);
    effector:SetKey(_TRACK_SX, 5.6, -1.88023605000348);
    effector:SetKey(_TRACK_SY, 5.6, 1.84829931972789);
    effector:SetKey(_TRACK_SX, 5.64, 2.40581744535233);
    effector:SetKey(_TRACK_SY, 5.64, 2.01567077281363);
    effector:SetKey(_TRACK_SX, 7.88, -2.14337593407361);
    effector:SetKey(_TRACK_SY, 7.88, 1.49200220628792);
    effector:SetKey(_TRACK_SX, 8.04, 2.26279069767442);
    effector:SetKey(_TRACK_SY, 8.04, 1.88231292517007);
    effector:SetKey(_TRACK_SX, 8.08, 1.53061666317481);
    effector:SetKey(_TRACK_SY, 8.08, 1.8687074829932);
    effector:SetKey(_TRACK_SX, 8.16, -1.16705775542985);
    effector:SetKey(_TRACK_SY, 8.16, 1.8687074829932);
    effector:SetKey(_TRACK_SX, 8.2, 2.40581744535233);
    effector:SetKey(_TRACK_SY, 8.2, 2.01567077281363);
    effector:SetKey(_TRACK_SX, 8.32, 2.13764229345625);
    effector:SetKey(_TRACK_SY, 8.32, 2.42358889501747);
    effector:SetKey(_TRACK_SX, 9.96, 2.16279069767442);
    effector:SetKey(_TRACK_SY, 9.96, 1.78231292517007);
    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 1.08, 0);
    effector:SetKey(_TRACK_O, 1.12, 1);
    effector:SetKey(_TRACK_O, 1.28, 0);
    effector:SetKey(_TRACK_O, 1.36, 1);
    effector:SetKey(_TRACK_O, 1.44, 0.2);
    effector:SetKey(_TRACK_O, 1.52, 1);
    effector:SetKey(_TRACK_O, 1.68, 0);
    effector:SetKey(_TRACK_O, 1.84, 0);
    effector:SetKey(_TRACK_O, 1.88, 1);
    effector:SetKey(_TRACK_O, 2.04, 0);
    effector:SetKey(_TRACK_O, 2.12, 1);
    effector:SetKey(_TRACK_O, 2.2, 0.2);
    effector:SetKey(_TRACK_O, 2.28, 1);
    effector:SetKey(_TRACK_O, 2.44, 0);
    effector:SetKey(_TRACK_O, 5.28, 0);
    effector:SetKey(_TRACK_O, 5.32, 1);
    effector:SetKey(_TRACK_O, 5.48, 0);
    effector:SetKey(_TRACK_O, 5.56, 1);
    effector:SetKey(_TRACK_O, 5.64, 0.2);
    effector:SetKey(_TRACK_O, 5.72, 1);
    effector:SetKey(_TRACK_O, 5.88, 0);
    effector:SetKey(_TRACK_O, 7.84, 0);
    effector:SetKey(_TRACK_O, 7.88, 1);
    effector:SetKey(_TRACK_O, 8.04, 0);
    effector:SetKey(_TRACK_O, 8.12, 1);
    effector:SetKey(_TRACK_O, 8.2, 0.2);
    effector:SetKey(_TRACK_O, 8.28, 1);
    effector:SetKey(_TRACK_O, 8.44, 0);
    effector:SetKey(_TRACK_O, 9.96, 0);

    effector:Play();


    -- Layer Layer_3
    local element = auxCreateCompositionElement('data/Texture/Scenes/17_CandleCave/Animations/Env/EF_light1_01.jpg');
    element:SetName('Layer_3');
    compositionBG_zum_1:AddElement(element);
    element:SetHotSpot(58.5, 138);
    element:SetParentElement(compositionBG_zum_1);
    element:SetXY(326, 215);

    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_SX, 0, 2.31623931623932);
    effector:SetKey(_TRACK_SY, 0, 1.59420289855072);
    effector:SetKey(_TRACK_SX, 0.72, 2.35042735042735);
    effector:SetKey(_TRACK_SY, 0.72, 1.58695652173913);
    effector:SetKey(_TRACK_SX, 1.96, 2.24327524327525);
    effector:SetKey(_TRACK_SY, 1.96, 1.58792897923333);
    effector:SetKey(_TRACK_SX, 2.4, 2.2814763014763);
    effector:SetKey(_TRACK_SY, 2.4, 1.58102766798419);
    effector:SetKey(_TRACK_SX, 3, 2.31842330508997);
    effector:SetKey(_TRACK_SY, 3, 1.58207332120376);
    effector:SetKey(_TRACK_SX, 3.72, 2.2498213068328);
    effector:SetKey(_TRACK_SY, 3.72, 1.58332810506724);
    effector:SetKey(_TRACK_SX, 4.4, 2.29124720102026);
    effector:SetKey(_TRACK_SY, 4.4, 1.58451317871608);
    effector:SetKey(_TRACK_SX, 5.24, 2.22664691983556);
    effector:SetKey(_TRACK_SY, 5.24, 1.58597709322347);
    effector:SetKey(_TRACK_SX, 6, 2.29235486545381);
    effector:SetKey(_TRACK_SY, 6, 1.58005521048999);
    effector:SetKey(_TRACK_SX, 6.64, 2.24493292743002);
    effector:SetKey(_TRACK_SY, 6.64, 1.58234170553011);
    effector:SetKey(_TRACK_SX, 7.64, 2.28350477247865);
    effector:SetKey(_TRACK_SY, 7.64, 1.5859143540303);
    effector:SetKey(_TRACK_SX, 8.32, 2.20762929466255);
    effector:SetKey(_TRACK_SY, 8.32, 1.58834375501042);
    effector:SetKey(_TRACK_SX, 9.96, 2.31623931623932);
    effector:SetKey(_TRACK_SY, 9.96, 1.59420289855072);
    effector:SetKey(_TRACK_O, 0, 0.4);
    effector:SetKey(_TRACK_O, 0.64, 0.5);
    effector:SetKey(_TRACK_O, 1.32, 0.3);
    effector:SetKey(_TRACK_O, 1.96, 0.5);
    effector:SetKey(_TRACK_O, 2.36, 0.3);
    effector:SetKey(_TRACK_O, 3.28, 0.55);
    effector:SetKey(_TRACK_O, 4.04, 0.4);
    effector:SetKey(_TRACK_O, 4.76, 0.45);
    effector:SetKey(_TRACK_O, 5.28, 0.35);
    effector:SetKey(_TRACK_O, 5.96, 0.55);
    effector:SetKey(_TRACK_O, 6.36, 0.3);
    effector:SetKey(_TRACK_O, 6.76, 0.45);
    effector:SetKey(_TRACK_O, 7.44, 0.35);
    effector:SetKey(_TRACK_O, 8.16, 0.45);
    effector:SetKey(_TRACK_O, 8.84, 0.3);
    effector:SetKey(_TRACK_O, 9.36, 0.45);
    effector:SetKey(_TRACK_O, 9.96, 0.4);

    effector:Play();


    -- Layer Layer_4
--    local element = auxCreateCompositionElement('data/Texture/Scenes/17_CandleCave/Animations/Env/BG_zum_1.jpg');
--    element:SetName('Layer_4');
--    compositionBG_zum_1:AddElement(element);
--    element:SetHotSpot(320, 240);
--    element:SetParentElement(compositionBG_zum_1);
--    element:SetXY(320, 240);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 10);
--
--
--    effector:Play();

    compositionBG_zum_1:Play();

    return compositionBG_zum_1;
end
