
--------------------------------------------------------------------------------
class 'CMoviesPage'

local moviePosition = {1024.0/2.0 + 65.0, 768.0/2.0};
local zOffset = 50;
local PREVIEW_SCALE = 800.0/640.0;
			
function CMoviesPage:__init(screen)
	assert(screen);
		
	self.pageRoot = screen:CreateAnimation('data/Texture/Scenes/Common/area.png');
	self.pageRoot:SetColor('0x10FFFFFF');
	self.pageRoot:SetPosZ(zOffset);

	local back = screen:CreateAnimation('data/Texture/GUI/Extras/PageMovie/backgroundImage.jpg');
    back:AttachTo(self.pageRoot);
	back:SetHotSpot(800.0/2.0, 600.0/2.0);
	back:SetXY(moviePosition[1], moviePosition[2]); 
	back:SetPosZ(zOffset);

	self.movie = nil;

	local eventMap = {};
	eventMap.Play = 'OnPlayMovie';
--	eventMap.Stop = 'OnStopMovie';
	CreateNavigaionPanel(screen, self, self.pageRoot, 235,725, eventMap);

moviesPage = self;
end

function CMoviesPage:Show()
	self.pageRoot:Show();
end
function CMoviesPage:Hide()
	self.pageRoot:Hide();
--	self:StopMovie();
    if (self.movie) then
        self.movie:Destroy();
        self.movie = nil;
    end
end

function CMoviesPage:PlayMovie()

--	if (self.movie:IsPlaying()) then
--		self.movie:Go();
--	else
    if (self.movie == nil) then
    	OnStopMusic();
	
    	self.movie = CreateMovieEntity();
    	self.movie:AttachTo(self.pageRoot);
    	self.movie:SetXY(moviePosition[1], moviePosition[2]); 
    	self.movie:SetZ(zOffset + 10); 
    	self.movie:SetScale(PREVIEW_SCALE);
    	self.movie:SetRepeat(false);
		self.movie:PlayMovie('data/Texture/GUI/Extras/PageMovie/BlackCatMovie.ogg',
							 'data/Texture/GUI/Extras/PageMovie/BlackCatMovie_Sound.ogg');
	end
--	end
end

function CMoviesPage:StopMovie()
	assert(self.movie ~= nil);

	self.movie:Stop();	
end

-- Event handlers ------------------------------------------------------------
function OnPlayMovie()
	assert(moviesPage);

	moviesPage:PlayMovie();
end
function OnStopMovie()
	assert(moviesPage);

	moviesPage:StopMovie();
end
