class 'LevelEventHandler'

local ANIMATIONS_FOLDER_NAME        = '/anim/'

local VIDEO_FOLDER_NAME            = 'data/Video/'
local VIDEO_COLLECTORS_FOLDER_NAME = 'data/ExtraContent/Video/'

local SOUND_FOLDER_NAME             = 'data/Sound/'
local SOUND_COLLECTORS_FOLDER_NAME  = 'data/ExtraContent/Sound/'

function LevelEventHandler:__init(name)
    function GetCurrentLevel()
		return self
	end
		
    self.name = name
    self:LoadDefaultData(play_field)
    
    -- sounds
	self:LoadLevelSounds()
	self:PlayAmbientSound()
	
	self.is_collectors_edition   = levels[name].collectors_edition
	self.mode                    = levels[name].mode
	self.parent_level            = levels[name].parent_level_name
	self.file                    = play_field:GetName()
	
	self.state                   = GetGameManager():GetCurrPlayer().gameState
	self.panel                   = play_field:GetLevelScreen():GetPanel()
	self.inventory               = play_field:GetLevelScreen():GetInventory()
	self.locker                  = ReferenceCounter()
	self.timer                   = Timer()
	
	self.blackBar                = BlackBar()
	self.comics                  = nil
	self.prev_comics             = nil
	
	self.active_zone             = nil
	self.forcedObject            = nil
	self.cursor_to_restore       = nil
	self.drag_info               = nil
	self.restore_punish_timer    = nil
	self.sound_MousePunish       = nil
	
	self.zones                   = {}
	self.tools                   = {}
	self.active_objects          = {}
	self.item_found_actions      = {}
	self.locked_objects          = {}
	self.quest_objects           = {}
	self.drag_objects            = {}
	self.wrong_apply_dialogs     = {}
	self.ignore_on_highlight     = {}
	self.forced_hint_objects     = {}
	self.additional_hint_objects = {}
	self.custom_cursors          = {}
	self.linked_scenes           = {}
	self.task_objects_shadows    = nil
	
	self.mouseBlocker            = MouseBlocker:New()
	self.mouseDownBlocked        = false
	
	self.is_cut_scene = false
	
	if CollectObjectsManager then
	    self.collectManager      = CollectObjectsManager()
	    self.collectManager:SetFindGlobalCallback( OnCollectObjectFound )
	end
	
	local quest_object_highlight_period_change_time = 60.
	
	self.highlighting_disabled                      = false
	self.object_highlight_delay                     = 2
    self.object_highlight_period                    = 3
    
	self.ho_item_highlight_period               	= 7
	self.ho_item_highlight_delay               		= 2.5
    
    self.quest_object_highlight_delay               = 2.5
    self.quest_object_highlight_period              = 3.
    self.quest_object_highlight_period_min          = 1.3
    self.quest_object_highlight_period_change_speed = (self.quest_object_highlight_period_min -
                                                       self.quest_object_highlight_period) /
                                                       quest_object_highlight_period_change_time
    self.clear_task_object_found_states_on_finish   = nil
    self.return_zone_dheight                        = 0
	
	-------------------------
	play_field:GetObject('quest_object_highlight'):SetOpacity(0)
    play_field:GetObject('object_highlight'      ):SetOpacity(0)
    play_field:GetObject('zoom_fade'             ):SetOpacity(0)
    play_field:GetObject('cut_border_top'        ):SetOpacity(0)
	play_field:GetObject('cut_border_bottom'     ):SetOpacity(0)
    
    play_field:IgnoreOnTestPoint('quest_object_highlight')
    play_field:IgnoreOnTestPoint('object_highlight')
	play_field:IgnoreOnTestPoint('fade_in_on_load')
    play_field:IgnoreOnTestPoint('cut_border_top')
	play_field:IgnoreOnTestPoint('cut_border_bottom')
	
	play_field:GetObject('fade_in_on_load'):ChangeOpacity(1., 0., 0.5)
    
    local panel = self:GetPanelLuaObject()
    
    if self.mode == 'quest' then
	    self.video_folder = (self:IsCollectorsEdition() and VIDEO_COLLECTORS_FOLDER_NAME or VIDEO_FOLDER_NAME) .. 'Scenes/' .. name:sub(3) .. '/'
        self.sound_folder = (self:IsCollectorsEdition() and SOUND_COLLECTORS_FOLDER_NAME or SOUND_FOLDER_NAME) .. 'Scenes/' .. name:sub(3) .. '/'
	    
        panel:SetMode(EPanelMode.PM_QUEST)
        panel:SetHintTime(panel:GetSavedHiddenObjectHintTime())
        
    elseif self.mode == 'hidden_object' then
        self.logic = HiddenObjectLogic()
        self.video_folder = (self:IsCollectorsEdition() and VIDEO_COLLECTORS_FOLDER_NAME or VIDEO_FOLDER_NAME) .. 'HiddenObjects/' .. name:sub(3) .. '/'
        self.sound_folder = (self:IsCollectorsEdition() and SOUND_COLLECTORS_FOLDER_NAME or SOUND_FOLDER_NAME) .. 'HiddenObjects/' .. name:sub(3) .. '/'
        
        panel:SetMode(EPanelMode.PM_HIDDENOBJECT)
        panel:SetHintTime(panel:GetSavedHiddenObjectHintTime())
    
    elseif self.mode == 'hidden_picture' then
        self.logic = HiddenPictureLogic()
        self.video_folder = (self:IsCollectorsEdition() and VIDEO_COLLECTORS_FOLDER_NAME or VIDEO_FOLDER_NAME) .. 'HiddenPictures/' .. name:sub(3) .. '/'
        self.sound_folder = (self:IsCollectorsEdition() and SOUND_COLLECTORS_FOLDER_NAME or SOUND_FOLDER_NAME) .. 'HiddenPictures/' .. name:sub(3) .. '/'
        
        panel:SetMode(EPanelMode.PM_HIDDENPICTURE)
        panel:SetHintTime(panel:GetSavedHiddenObjectHintTime())
        
    elseif self.mode == 'mini_game' then
        self.video_folder = (self:IsCollectorsEdition() and VIDEO_COLLECTORS_FOLDER_NAME or VIDEO_FOLDER_NAME) .. 'MiniGames/' .. name:sub(3) .. '/'
        self.sound_folder = (self:IsCollectorsEdition() and SOUND_COLLECTORS_FOLDER_NAME or SOUND_FOLDER_NAME) .. 'MiniGames/' .. name:sub(3) .. '/'
    
        panel:SetMode(EPanelMode.PM_MINIGAME)
        
    elseif self.mode == 'clean' then
        self.video_folder = (self:IsCollectorsEdition() and VIDEO_COLLECTORS_FOLDER_NAME or VIDEO_FOLDER_NAME) .. 'Scenes/' .. name:sub(3) .. '/'
        self.sound_folder = (self:IsCollectorsEdition() and SOUND_COLLECTORS_FOLDER_NAME or SOUND_FOLDER_NAME) .. 'Scenes/' .. name:sub(3) .. '/'
        
        panel:SetMode(EPanelMode.PM_CLEAN)
    end

    RegisterTools()
    self:GetInventoryLuaObject():SetStartPos()
    self:GetInventoryLuaObject():RestoreShift()
    --panel:UpdateCollectObjectsIndicator()

    if not IsSceneVisited(self.name) then
        self.visited_first_time = true
        AddGameState(SCENE_VISITED, self.name)
    end
    
    SetGameState(LAST_VISITED_SCENE, self.name)
    
    -- dog logic
    do
        local panel = self:GetPanelLuaObject()
        
        if not HasGameState('DOG_ACTIVE', 'true') then
            panel:GetObject('area_dog'):SetVisible(false)
        else
            panel:PlayIdleDog()
            panel:GetObject('cover_dog'):SetOpacity(0)
        end
    end
	
	-- has note is active page ------------------------------------------------
    if HasGameState('NotebookActive') then
        self:GetPanelLuaObject():NoteAdded(true)
    end
    
    -- hide intercative help --------------------------------------------------
    if InteractiveHelp.tutorialScreen and PopUpScreensMgr:GetTop() then
        InteractiveHelp.tutorialScreen:Hide()
    end
    
	-- restore state cursor
	SetCursor('CursorDefault')
	
	-- auto close zoom zone ---------------------------------------------------
	self.timer:Add(function()
	                    AutoCloseZoomZones()
	                end, 0)
	
	if IsInGameMenuShown() then
	    CloseInGameMenu()
	end
	
	self:DoAnimationFiles()
	self:PushFlyNote()
	
	-- fish zoom zone --------------------------------------------------
	--[[
	do
	    dofile('data/Scripts/screens/Fish/FishManger.lua')
	    dofile('data/Scripts/screens/Fish/Fish.lua')
	    
	    self.fish_manager = FishManager()
	
	    local init_info = {}
        init_info.name = 'fish'
        init_info.mode =  ZOOM_TYPE_NO_BORDER

	    self.zone_fish = CreateZoomZoneEx(l_fish(init_info), 'bttn_collection', ZOOM_TYPE_NO_BORDER, 0, 0, 1000)
	end
	--]]
end
-------------------------------------------------------------------------------
function LevelEventHandler:LoadLevelSounds()
    
    local prev_level = GetCurrentLevel()
    local prev_level_sound_tracks = {}
    
    self.level_sounds = {
        tracks      = LoadSounds(levels[self.name].sounds_path),
        entities    = {}
    }
    
    if prev_level then
		-- If previous level exists, save it's tracks -----------------------------
		if prev_level then
			if prev_level.name ~= self.name then
				prev_level_sound_tracks = GetCurrentLevel().level_sounds.tracks
			else
				-- if previous leve is the same level -> do not unload any tracks
				GetCurrentLevel().level_sounds.tracks = {}
			end
		end
		
		-- Check for common tracks and remove them from previous level remove list 
        local new_prev_level_sound_tracks = {}
        
        for _,prev_t in ipairs(prev_level_sound_tracks) do
            local exclude = false

            for _,cur_t in ipairs(self.level_sounds.tracks) do
                if prev_t == cur_t then
                    exclude = true
                    break
                end
            end
            
            if not exclude then
                table.insert(new_prev_level_sound_tracks, prev_t)
            end
        end
        
        prev_level.level_sounds.tracks = new_prev_level_sound_tracks
    end
end

function LevelEventHandler:PlayAmbientSound()
    local name       = string.sub(self.name, 3)
    local prev_level = GetCurrentLevel()
    
    local cur_ambient = GetCurrentAmbientSoundTrackName()
	if cur_ambient ~= "" then
		StopAmbientSound(cur_ambient, true)
	end
    
    local bAdditionAmbientSound = not IsAmbientSoundLoaded(name)
    local ambientSoundName      = bAdditionAmbientSound and name..'_addition' or name
		
	if IsAmbientSoundLoaded(ambientSoundName) then
		if not bAdditionAmbientSound then
		    StopAmbientMusic(true)
	    end
	    
		PlayAmbientSound(ambientSoundName, true)
	end
		
	if bAdditionAmbientSound then
		if self.music_list == nil then
            PlayRandomAmbientMusic()
		else
			local list     = self.music_list
			local listType = type(list)
			
			if listType == 'string' then
                    PlayAmbientMusic(list, true)
			elseif listType == 'table' then
				if #list > 0 and not table.has_value(list, currentMusicTrack) then
                    PlayAmbientMusic(table.random_value(list), true)
				end
			elseif list == false then
				StopAmbientMusic()
			end
		end
	end
end

function LevelEventHandler:ReleaseLevelSounds()
    for n,e in pairs(self.level_sounds.entities) do
        e:ReleaseTrack()
    end
    
    for _,t in ipairs(self.level_sounds.tracks) do
        RemoveSound(t)
    end
end

function LevelEventHandler:GetSound(name)
    if not self.level_sounds.entities[name] then
        local entity = CreateSoundEntity(name)
        entity:AttachTo(play_field)
        
        self.level_sounds.entities[name] = entity
    end
    
    return self.level_sounds.entities[name]
end

function LevelEventHandler:ReplaySound(name, cycle)
    local sound = self:GetSound(name)

    sound:StopSound()
    sound:PlaySound(cycle or false)
end

function LevelEventHandler:PlaySound(name, cycle)
    self:GetSound(name):PlaySound(cycle or false)
end

function LevelEventHandler:StopSound(name)
    self:GetSound(name):StopSound()
end

-------------------------------------------------------------------------------
function LevelEventHandler:DoAnimationFiles()
    local DirPach = ExtractFilePath( levels[self.name].path )
    local vecPersonages = ParseDirectory( DirPach .. ANIMATIONS_FOLDER_NAME )
    for i = 0, vecPersonages:size() - 1 do
        local AnimationFilePach = vecPersonages:get(i)
        dofile(AnimationFilePach)
    end
end

-------------------------------------------------------------------------------
function LevelEventHandler:PushFlyNote()
    if HasGameState('FlyNote') then
        local FlyId = GetGameState('FlyNote'):Get(0)
        FlyId = (FlyId ~= '') and FlyId or nil
        
        if FlyId then
            NotebookPushNote(FlyId)
        else
            play_field:GetLevelScreen():GetPanel():GetAssociatedLuaObject():NoteAdded()
        end
        
        RemoveGameState('FlyNote')
    end
end

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

function LevelEventHandler:GetPanel()
    return self.panel
end
-------------------------------------------------------------------------------

function LevelEventHandler:GetPanelLuaObject()
    return self.panel:GetAssociatedLuaObject()
end
-------------------------------------------------------------------------------

function LevelEventHandler:GetInventory()
    return self.inventory
end
-------------------------------------------------------------------------------

function LevelEventHandler:GetInventoryLuaObject()
    return self.inventory:GetAssociatedLuaObject()
end
-------------------------------------------------------------------------------

function LevelEventHandler:GetAdditionalLogic()
    return self.logic
end
-------------------------------------------------------------------------------

function LevelEventHandler:DefaultSkipMiniGame()
    if self.SkipMiniGame then
        self:SkipMiniGame()
    end
    self:CallForZones('DefaultSkipMiniGame')
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultUpdate(dt)
	if self.door_object then
		if self.open_sound and self.door_object:GetOpacity() == 0 then
			self.open_sound:PlaySound(false)
		end
		if self.close_sound then
			self.close_sound:StopSound()
		end
		self.door_object:Update(dt)
	end
	
    local return_zone_check_needed = (self.active_zone and IsZoomZoneNeedsScreenBottomExitZone(self.active_zone))
                                        or  self.mode == 'hidden_object'
                                        or  self.mode == 'hidden_picture'
                                        or (self.mode == 'quest' and self.parent_level ~= nil)
                                        or (self.mode == 'mini_game' and self.parent_level ~= nil)
        
    if return_zone_check_needed and IsAboveReturnFromZoomZone() then
        if currentCursor ~= 'CursorDoorDown' then
            self.cursor_to_restore = currentCursor
        end
        if (not IsDragging()) and (not self:GetInventoryLuaObject():GetTool()) then
		    SetCursor('CursorDoorDown')
		end
    else
        if self.cursor_to_restore then
            SetCursor(self.cursor_to_restore)
            self.cursor_to_restore = nil
        end
    end

	if not self.comics or self.comics.is_monolog then
		if self.quest_object_highlight_period > self.quest_object_highlight_period_min then
			local dperiod = self.quest_object_highlight_period_change_speed * dt
			if self.quest_object_highlight_period + dperiod >= self.quest_object_highlight_period_min then
				self.quest_object_highlight_period = self.quest_object_highlight_period + dperiod
			else
				self.quest_object_highlight_period = self.quest_object_highlight_period_min
			end
		end
		
		if self.forcedObject then
		    self.object_highlight_delay = self.object_highlight_delay - dt
		    if self.object_highlight_delay < 0. then
		        HighlightObject(self.forcedObject)
		        self.object_highlight_delay = self.object_highlight_period
            end
        else
            if not IsMouseBlocked() then
                self.object_highlight_delay = self.object_highlight_delay - dt
                if self.object_highlight_delay < 0. then
                    HighlightRandomObject()
                end

                self.quest_object_highlight_delay = self.quest_object_highlight_delay - dt
                if self.quest_object_highlight_delay < 0. then
                    HighlightRandomQuestObject()
                end
                
                if self.mode == 'hidden_object' then
					self.ho_item_highlight_delay = self.ho_item_highlight_delay - dt
					if self.ho_item_highlight_delay < 0. then
						HighlightRandomHOAction()
					end
				end
            end
		end
	end
	
	if self.OnUpdate then
	    self:OnUpdate(dt)
	end
	self:CallForZones('OnDefaultUpdate', dt)
    
    self.timer:Update(dt)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultAllItemsFound()
    if self.OnAllItemsFound then
        self:OnAllItemsFound()
    end
	self:CallForZones('OnDefaultAllItemsFound')
    
    local strike_time = 1.5
    self.timer:Add( function()
                        RestoreCursor()
                        self:OnClose()
                    end,
                    strike_time)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnClose()
    if self.parent_level then
        StartLevel(self.parent_level)
    end
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDoorMouseEnter(object, door_object, open_sound, close_sound)
    local linked_scene_info = self.linked_scenes[object:GetName()]
    
    if HasGameState(SCENE_CLOSED, linked_scene_info.level_name) then
        return
    end
    if (IsMouseBlocked() and (self.forcedObject == nil or self.forcedObject ~= obj_name)) then
        return
    end
    
    door_object:DestroyEffectors()
    door_object:ChangeOpacity(door_object:GetOpacity(), 1, 0.5)
    
    self.door_object = door_object	
    self.open_sound  = open_sound
    self.close_sound = close_sound
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDoorMouseLeave(object, door_object)
    if not self.door_object then
        return
    end
    
    door_object:DestroyEffectors()
    door_object:ChangeOpacity(door_object:GetOpacity(), 0, 0.5)
    
    self.door_object = nil
    
	if self.open_sound then
		self.open_sound:StopSound()
	end
	if self.close_sound then
		self.close_sound:PlaySound(false)
	end
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultObjectMouseEnter(object)
    if self.OnObjectMouseEnter then
        self:OnObjectMouseEnter(object)
    end
	self:CallForZones('OnObjectMouseEnter', object)

    local objectName = object:GetName();
    
    local linkInfo = self.linked_scenes[objectName]
    
	if linkInfo and linkInfo.door_object then
        self:OnDoorMouseEnter(object,
                              linkInfo.door_object,
                              linkInfo.open_sound,
                              linkInfo.close_sound)
	end
end

function LevelEventHandler:OnUpdateCursorOverObject(object)
    if self:GetInventoryLuaObject():GetTool() then
        SetCursor('CursorTool', true)
    else
        if not object then
--            SetCursor('CursorDefault')
            return
        end
    
        local objectName = object:GetName()
        
        if self.custom_cursors[objectName] ~= nil
            and self.custom_cursors[objectName] ~= ''
            and (not self.active_zone or self.active_zone:HasObject(objectName) or self.forcedObject == objectName)
            and (not IsMouseBlocked() or self.forcedObject == objectName)
            and (not IsDragging() )
            and (not self.comics  )
        then
            name = self.custom_cursors[objectName]
            
            if self.forcedObject then
                SetCursor(name, true)
            else
                SetCursor(name)
            end
        end
    end
end

function LevelEventHandler:OnDefaultObjectMouseLeave(object)
    if self.OnObjectMouseLeave then
        self:OnObjectMouseLeave(object)
    end
	self:CallForZones('OnDefaultObjectMouseLeave', object)

    local obj_name = object:GetName();
    
    if not IsDragging() then
        SetCursor('CursorDefault', true)
    end
    
    local linkInfo = self.linked_scenes[obj_name]
	if linkInfo and linkInfo.door_object then
        self:OnDoorMouseLeave(object, linkInfo.door_object)
	end
end
-------------------------------------------------------------------------------

function LevelEventHandler:AutoApplyTool(object, obj_name)
    local function AddAndApplyTool(inToolName, object)
        if not IsToolFound(inToolName) then
            AddGameState(TOOL_INFO_SHOWN, inToolName)
            FindTool(inToolName)
        end
        
        local inv = self:GetInventoryLuaObject()
        inv:TakeTool(inToolName)
        
        GetCurrentLevel().mouseBlocker:Push()
        self.timer:Add( function()
                            GetCurrentLevel().mouseBlocker:Pop()
                            
                            if not IsToolApplied(inToolName) then
                                self:OnDefaultToolApply(inToolName, object)
                           end
                       end, 
                       0.5)
        return true
    end
	
    for iToolName, v in pairs(self.tools) do
        if not IsToolApplied(iToolName) then
            if type(v.target_name) == 'table' then
                for i2, v2 in pairs(v.target_name) do
                    if v2 == obj_name then 
                        if AddAndApplyTool(iToolName, object) then 
                            return true
                        end
                    end
                end
            elseif v.target_name == obj_name then 
                if AddAndApplyTool(iToolName, object) then 
                    return true
                end
            end
        end
    end
    
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnObjectMouseDown(object, key)
    local obj_name = object:GetName()
    
    if not IsMouseBlocked() then
        HideBlackBar()
    end
    
    if (IsMouseBlocked() and (self.forcedObject == nil or self.forcedObject ~= obj_name)) then
        return true
    end

    if (not IsBuildForCustomerMode()) and key == HGEK_RBUTTON then
        if self:AutoApplyTool(object, obj_name) then
            return true
        end
    end
    
    local panel = self:GetPanelLuaObject()
    if panel:CanMinigameHide() then 
        panel:HideMinigameHelp(nil, true)
    end
    
    local checkExecuted = false
    
    if key == HGEK_LBUTTON then
        local check_functions = {}
        table.insert(check_functions, self.CheckComicsObjectMouseDown)
        table.insert(check_functions, self.CheckDropObjectMouseDown)
        table.insert(check_functions, self.CheckToolFoundObjectMouseDown)
        table.insert(check_functions, self.CheckActiveObjectMouseDown)
        table.insert(check_functions, self.CheckToolApplyObjectMouseDown)
        table.insert(check_functions, self.CheckTaskObjectMouseDown)
        table.insert(check_functions, self.CheckDragObjectMouseDown)
        table.insert(check_functions, self.CheckLinkSceneObjectMouseDown)
        table.insert(check_functions, self.CheckOpenZoomObjectMouseDown)
        table.insert(check_functions, self.CheckCloseSceneMouseDown)
        table.insert(check_functions, self.CheckCloseZoomObjectMouseDown)
        
        for i, funct in ipairs(check_functions) do
            if funct(self, obj_name) then
                checkExecuted = true
                break
            end
        end
        
        if checkExecuted then
            self:CheckCloseInteractiveHelpMouseDown()
        end
    elseif key == HGEK_RBUTTON then
        checkExecuted = true
    end
    
    if self.OnScreenObjectMouseDown then
        self:OnScreenObjectMouseDown(object, key)
    end
	self:CallForZones('OnObjectMouseDown', object, key)
    
    self:OnDefaultObjectMouseDownProcessed( not checkExecuted )
end
-------------------------------------------------------------------------------



-------------------------------------------------------------------------------
-- MOUSE DOWN CHECK FUNCTIONS -------------------------------------------------
-------------------------------------------------------------------------------

function LevelEventHandler:CheckComicsObjectMouseDown(obj_name)
    if self.comics and not IsMouseBlocked() then
        if self.comics:IsClickableScene() then
            UpdateComicsRequest()
        end
        return true
    end
    
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckDropObjectMouseDown(obj_name)
    local obj = play_field:GetObject(obj_name)
    local res = DropObjectRequest(obj, false)
    
    return res
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckToolFoundObjectMouseDown(obj_name)
    local success = false
    
    if not self:IsLockedObject(obj_name) and
        self.mode ~= 'hidden_object'     and
        self.mode ~= 'hidden_picture'
    then
        local trigger_name = nil
        
        for tool_name, info in pairs(self.tools) do
            if info.find_scene == self.name then
                trigger_name = info.trigger_name
                local action_triggered = obj_name == info.trigger_name
                
                if not action_triggered and type(info.trigger_name) == 'table' then
                    for i, v in ipairs(info.trigger_name) do
                        if obj_name == v then
                            table.remove(info.trigger_name, i)
                            if table.getn(info.trigger_name) == 0 then
                                trigger_name = v
                                action_triggered = true
                            end
                        end
                    end
                end
                
                if action_triggered and not success then
                    local objects_zone = GetObjectsZone(trigger_name);

                    if (objects_zone == nil and self.locker:GetNReferences() == 0) or
                       (objects_zone ~= nil and objects_zone:IsVisible())
                    then
                        success = true
                        play_field:GetObject(trigger_name):SetVisible(false)
                        
                        if objects_zone ~= nil then
							if info.disable_zoom_request() then
								objects_zone:Close()
								objects_zone:Disable()
							end
                        end
                        
                        FindTool(tool_name, info.do_not_show_window)
                        return true
                    end
                end
            end
        end
    end
    
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckActiveObjectMouseDown(obj_name)
    local info = self.active_objects[obj_name]
    
    if info
        and not self:IsLockedObject(obj_name)
        and (not IsObjectClicked(obj_name) or info.multi_use == true)
        and (self.locker:GetNReferences() == 0 or IsActiveZoneObject(obj_name) or (self.forcedObject == obj_name))
    then
        local state_value = self.name..'('..obj_name..')'
        AddUniqueGameState(OBJECT_CLICKED, state_value)
        
        if not info.multi_use == true then
            self:LockObject(obj_name)
            UnregisterActiveObject(obj_name)
        end
        
        if info.on_click then
            local event  = {}
            event.save   = false
            event.target = obj_name
            
            info.on_click(event)
        end
        
        return true
    end
    
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckToolApplyObjectMouseDown(obj_name)
    if not self:IsLockedObject(obj_name) then
        for name, info in pairs(self.tools) do
            if  info.apply_text_alias  ~= nil and
                info.target_name       ~= nil 
            then
                local is_target = false
                
                if type(info.target_name) == 'string' then
                    is_target = (obj_name == info.target_name)
                else
                    for i, target_name in pairs(info.target_name) do
                        if target_name == obj_name then
                            is_target = true
                            break
                        end
                    end
                end
                
                if is_target and not IsToolTargetUsed(name, obj_name) and not IsHardPlayMode() then
                    local text_alias_type = type(info.apply_text_alias)
                    local alias = nil
                    local delay = nil
                    
                    if text_alias_type == 'string' then
                        alias = info.apply_text_alias
                        
                    elseif text_alias_type == 'table' then
                        local index = math.random(#info.apply_text_alias)
                        alias = info.apply_text_alias[index]
                        
                    elseif text_alias_type == 'function' then
                        local event    = {}
                        event.target   = obj_name
                        event.toolName = name
                        
                        alias, delay = info.apply_text_alias(event)
                    end
                    
                    if alias ~= nil then
                        if delay then
                            self.timer:Add( function()
                                                ShowBlackBar(alias)
                                            end,
                                            delay)
                        else
                            ShowBlackBar(alias)
                        end
                    end
                    
                    return true
                end
            end
        end
    end
    
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckTaskObjectMouseDown(obj_name)
    local logic = self:GetAdditionalLogic()
    
    if logic and (not self:IsLockedObject(obj_name)) and
        (self.locker:GetNReferences() == 0 or IsActiveZoneObject(obj_name))
    then
        return logic:CheckTaskObjectMouseDown(obj_name)
    end
    
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckDragObjectMouseDown(obj_name)
    return StartDragObjectRequest(obj_name)
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckLinkSceneObjectMouseDown(obj_name)
    local linkInfo = self.linked_scenes[obj_name]
    
    if linkInfo
        and not self:IsLockedObject(obj_name)
        and (self.locker:GetNReferences() == 0 or IsActiveZoneObject(obj_name))
    then
        local is_closed  = IsSceneClosed(linkInfo.level_name)
		local target_pos = linkInfo.camera_target_pos		
		
		if target_pos == 'auto' then
			target_pos = play_field:GetObject(obj_name):GetPosition()
		end
		
        if linkInfo.condition then
            if not is_closed and linkInfo.condition() then
                StartLevel(linkInfo.level_name, target_pos)
            else
                if linkInfo.on_condition_fail then 
                    linkInfo.on_condition_fail()
                end
            end
        else
            if not is_closed then
                StartLevel(linkInfo.level_name, target_pos)
                return true
            end
        end
    end
    
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckOpenZoomObjectMouseDown(obj_name)
    if not self:IsLockedObject(obj_name)
        and (self.locker:GetNReferences() == 0 or IsActiveZoneObject(obj_name))
    then
        for _, zone in pairs(self.zones) do
            if zone.trigger_name == obj_name then
                zone:Open()
				return true
            end
        end
    end
    
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckCloseSceneMouseDown(obj_name)
    if not self.active_zone
        and (self.mode == 'mini_game' or self.mode == 'quest' or self.mode == 'hidden_picture')
        and IsAboveReturnFromZoomZone()
    then
        SetCursor('CursorDefault')
        self:OnClose()
		return true
    end
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckCloseZoomObjectMouseDown(obj_name)
    if self.active_zone
        and ( 
            ((IsZoomZoneNeedsScreenBottomExitZone(self.active_zone) and IsAboveReturnFromZoomZone())
            or (obj_name == 'zoom_fade' and self.active_zone.mode ~= ZOOM_TYPE_FULLSCREEN)) 
            or (not IsClickInZoom(self.active_zone))
        )
    then
        if not self.active_zone.is_fading then
            self.active_zone:Close()
            --SetCursor('CursorDefault')
        end
		return true
    end
    
    return false
end
-------------------------------------------------------------------------------

function LevelEventHandler:CheckCloseInteractiveHelpMouseDown(obj_name)
    if --[[self.forcedObject and --]] InteractiveHelp.tutorialScreen then
        InteractiveHelp.tutorialScreen:Hide()
        return true
    end
    return false
end
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultObjectMouseDownProcessed(is_wrong_click)
    if is_wrong_click and self.mode == 'hidden_object' then
        play_field:ShowWrongObjectEffect();
        
        if play_field.wrongObjectClickSound then
            play_field.wrongObjectClickSound:StopSound()
            play_field.wrongObjectClickSound:PlaySound(false)
        else
            play_field.wrongObjectClickSound = MakeSoundEntity("Wrong_click")
            play_field.wrongObjectClickSound:PlaySound(false)
        end
        --PlaySound("Wrong_click");
        
        if play_field.wrongClicksCount and not self:GetAdditionalLogic():IsAllTaskObjectsFound() then
            local curTime = APP:GetCurrentTime()
            
            if (curTime - play_field.lastClickTime <=
                    CLICK_TIME_TO_PUNISH / CLICKS_COUNT_TO_PUNISH)
            then
                play_field.wrongClicksCount = play_field.wrongClicksCount + 1;
                if (play_field.wrongClicksCount >= CLICKS_COUNT_TO_PUNISH) and IsHardPlayMode()
                then
                    PunishClicking();
                    play_field.wrongClicksCount = 0;
                end
            else
                play_field.wrongClicksCount = 1;
            end
        else
            play_field.wrongClicksCount = 1;
        end
        
    end
    
    play_field.lastClickTime = APP:GetCurrentTime();
    
    if self.OnObjectMouseDownProcessed then
        self:OnObjectMouseDownProcessed(is_wrong_click)
    end
	self:CallForZones('OnDefaultObjectMouseDownProcessed', is_wrong_click)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultObjectMouseUp(object)    
    DropObjectRequest(object, true)
    
    if self.OnObjectMouseUp then
        self:OnObjectMouseUp(object)
    end
	self:CallForZones('OnDefaultObjectMouseUp', object)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultObjectFound(object)
    local objName = object:GetName()
    
    if self.task_objects_shadows then
        for i, v in pairs( self.task_objects_shadows ) do
            if i == objName then
                ObjectOpacity(v, 0, 0.2)
                break
            end
        end
    end
    
    local action = self.item_found_actions[objName]
    if action then
        local event   = {}
        event.objName = objName
        event.save    = false
        
        action(event)
    end
    
    AutoCloseZoomZones()
    
    if self.OnObjectFound then
        self:OnObjectFound(object)
    end
	self:CallForZones('OnDefaultObjectFound', object)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultToolFound(tool_name)
    if self.OnToolFound then
        self:OnToolFound(tool_name)
    end
	self:CallForZones('OnDefaultToolFound', tool_name)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultToolApply(tool_name, object)
    local inv   = self:GetInventoryLuaObject()
    local panel = self:GetPanelLuaObject()
    
    if tool_name ~= "" and not IsMouseBlocked() then
        HideBlackBar()
    end
    
    if not object then
        if inv:GetTool() then
            local info = self.tools[tool_name]
            
            if info.target_name == '<DOG_ON_PANEL>' and panel:IsDogOver() and not self.toolWindow then
                local state, value = GenerateToolTargedUsed(tool_name, '<DOG_ON_PANEL>')
                assert(not HasGameState(state, value))
                AddGameState(state, value)
                
                inv:RemoveTool(tool_name)
                SetCursor('CursorDefault')
                
                AddGameState(TOOL_APPLIED, tool_name)
                panel:SetActiveDogState(false)
                
                local callback = function()
                    if info.on_apply then
                        local event    = {}
                        event.save     = false
                        event.toolName = tool_name
                        
                        info.on_apply(event)
                    end
                end
                
                local dogEffectPos
                
                if type(info.dogEffectTarget) == 'string' then
                    local targetObject = play_field:GetObject(info.dogEffectTarget)
                    dogEffectPos = Vector(targetObject:GetScrX(), targetObject:GetScrY())
                else
                    dogEffectPos = info.dogEffectTarget
                end
                
                while self.active_zone do
                    self.active_zone:Close()
                end
                
                CreateDogEffect(dogEffectPos, nil, callback)
            else
                inv:DropTool()
            end
        end
        
        return
    end
    
    local bToolApplied = false
	local obj_name     = object:GetName()
	
	if (IsMouseBlocked() and (self.forcedObject == nil or self.forcedObject ~= obj_name)) then
        return true;
    end
    
    if object then
        for name, info in pairs(self.tools) do
            local target_table_index
            local is_target

            is_target, target_table_index = IsToolTarget(name, obj_name)

            if not bToolApplied
                and tool_name == name
                and is_target
            then
                local apply_allowed = info.apply_request(tool_name, obj_name)
                
                if apply_allowed then
                    self.custom_cursors[obj_name] = 'CursorDefault'
                    
                    local state, value = GenerateToolTargedUsed(tool_name, obj_name)
                    assert(not HasGameState(state, value))
                    AddGameState(state, value)
                    
                    if target_table_index ~= nil then
                        table.remove(info.target_name, target_table_index)
                    end
                    
                    info.local_targets_applied = info.local_targets_applied + 1
                    
                    local all_local_targets_used  = (info.local_targets_applied == info.local_targets_count)
                    local all_global_targets_used = IsToolAllGlobalTargetsUsed(tool_name)

                    if all_global_targets_used or info.once_apply then
                        assert(not IsToolApplied(tool_name))
                        
                        inv:RemoveTool(tool_name)
                        AddGameState(TOOL_APPLIED, tool_name)
                        
                        if info.once_apply then
                            info.target_name = {}
                        end
                    else
                        if all_local_targets_used then
                            inv:DropTool(0)
                        end
                    end
                    
                    if info.on_apply then
                        local event                  = {}
                        event.save                   = false
                        event.target                 = obj_name
                        event.toolName               = tool_name
                        event.applied                = IsToolApplied(tool_name)
                        event.allLocalTargetsApplied = all_local_targets_used
                        event.lockAndRestoreTime     = nil
                        
                        info.on_apply(event)
                        
                        if not IsToolApplied(tool_name) then
                            if event.lockAndRestoreTime then
								local lockTime    = nil
                                local restoreTime = nil
                                
                                assert(type(event.lockAndRestoreTime) == 'table' or type(event.lockAndRestoreTime) == 'number')
                                
                                if type(event.lockAndRestoreTime) == 'table' then
									lockTime    = event.lockAndRestoreTime[1]
									restoreTime = event.lockAndRestoreTime[2]
								else
									lockTime    = event.lockAndRestoreTime
									restoreTime = event.lockAndRestoreTime
								end

                                -- callbacks -------
                                local function callback_unlock()
                                    inv:UnlockTool(tool_name)
                                end
                                
                                local function callback_tacktool()
                                    if not inv:GetTool() and not all_local_targets_used then
                                        inv:TakeTool(tool_name)             
                                    end
                                end
                                --------------------
                                
                                if play_field:GetTool() == tool_name then
                                    inv:DropTool(0)                          
                                end
                                
                                if lockTime == restoreTime then
                                    inv:LockTool(tool_name)
                                    
                                    self.timer:Add( function()
                                                        callback_unlock()
                                                        callback_tacktool()
                                                    end,
                                                    restoreTime)
                                else
                                    if lockTime ~= nil then
                                        inv:LockTool(tool_name)
                                        self.timer:Add(callback_unlock, lockTime)
                                    end
                                    
                                    if restoreTime ~= nil then
                                        self.timer:Add(callback_tacktool, restoreTime)
                                    end
                                end
                                
                            elseif all_local_targets_used then
                                if play_field:GetTool() == tool_name then
                                    inv:DropTool(0)
                                end
                            end
                        end
                    end
                    
                    bToolApplied = true
                    break
               else
                    ShowBlackBar('C_TOOL_NOT_ALLOWED_'..tool_name)
               end
            end
        end
    end

    if not bToolApplied then
		local bOpenZoomAriaClicked = false
		
		if not self:IsLockedObject(obj_name)
            and (self.locker:GetNReferences() == 0 or IsActiveZoneObject(obj_name))
		then
            for _, zone in pairs(self.zones) do
                if zone.trigger_name == obj_name and not zone:IsDisabled() then
                    zone:Open()
                    bOpenZoomAriaClicked = true
                    break
                end
            end
		end
		
		if not bOpenZoomAriaClicked then
            local targetTool       = GetToolNameByTargetName(obj_name, true)
            local wrongApplyDialog = GetWrongApplyDialog(tool_name, obj_name);
            
            if wrongApplyDialog then
                ShowBlackBar(wrongApplyDialog)
            elseif targetTool ~= nil then
                ShowBlackBar('C_TOOL_DENY_'..tostring(math.random(1, 4)))
            end

			inv:DropTool()
		end
    end
    
    if self.OnToolApply then
        self:OnToolApply(tool_name, object)
    end
	self:CallForZones('OnDefaultToolApply', tool_name, object)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultToolWindowClose(tool_name)
    if self.OnToolWindowClose then
        self:OnToolWindowClose(tool_name)
    end
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultToolAddToInventory(tool_name)
    if self.OnToolAddToInventory then
        self:OnToolAddToInventory(tool_name)
    end
	self:CallForZones('OnDefaultToolAddToInventory', tool_name)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultObjectReachPanel(object)
    if self.OnObjectReachPanel then
        self:OnObjectReachPanel(object)
    end
	self:CallForZones('OnDefaultObjectReachPanel', object)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultButtonPress(title)
    if IsMouseBlocked()
        and (self.forcedObject == nil or self.forcedObject ~= title)
        and (not GetActiveZone() or GetActiveZone().mode ~= ZOOM_TYPE_INFO_WINDOW)
    then
        return;
    end
    
    for _, zone in pairs(self.zones) do
        if zone.close_button_message == title then
            zone:Close()
            PlaySound('Menu_button_click')
        end
    end
    
    if self.OnButtonPress then
        self:OnButtonPress(title)
    end
	self:CallForZones('OnDefaultButtonPress', title)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultMouseMove(previous_pos, current_pos)
    local info = self.drag_info
    
    if info then
        local drag_obj = play_field:GetObject(info.obj_name)
        local bDrop    = false
        local rect     = self.drag_objects[info.obj_name].rect
        
        if rect ~= nil then
            local lx = current_pos.x - rect.x;
            local ly = current_pos.y - rect.y;
            
            bDrop = (lx < 0) or (lx > rect.w) or (ly < 0) or (ly > rect.h);
        end
        
        if bDrop then
            DropDragingObject(nil)
        else
            drag_obj:SetScrX(current_pos.x + info.dx)
            drag_obj:SetScrY(current_pos.y + info.dy)
        end
    end
    
    if self.OnMouseMove then
        self:OnMouseMove(previous_pos, current_pos)
    end
	self:CallForZones('OnDefaultMouseMove', previous_pos, current_pos)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultSetTool(tool)
    if self.OnSetTool then
        self:OnSetTool(tool)
    end
	self:CallForZones('OnDefaultSetTool', tool)
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultLoaded()
    bLoadLevelBlocked = nil
    
    if self.OnLoaded then
        self:OnLoaded()
    end
    
	self:CallForZones('OnDefaultLoaded')
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultDestroy()
	self:CallForZones('OnDefaultDestroy')
    if self.OnDestroy then
        self:OnDestroy()
    end
    self:ReleaseLevelSounds()
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnDefaultHintObject(object, is_proper, priority, additional_obj)
    if self.OnHintObject then
        return self:OnHintObject(object, is_proper, priority, additional_obj)
    else
        return is_proper, priority, additional_obj
    end
end
-------------------------------------------------------------------------------


function LevelEventHandler:LockObject(obj_name)
    self.locked_objects[obj_name] = true
end
-------------------------------------------------------------------------------

function LevelEventHandler:UnlockObject(obj_name)
    self.locked_objects[obj_name] = nil
end
-------------------------------------------------------------------------------

function LevelEventHandler:IsLockedObject(obj_name)
    return (self.locked_objects[obj_name] == true)
end
-------------------------------------------------------------------------------

function LevelEventHandler:GetHintTimerState()
    return "HintTimer"
end
-------------------------------------------------------------------------------

function LevelEventHandler:OnMusicTrackEnd()
    PlayNextRandomAmbientMusic()
end
-------------------------------------------------------------------------------

function LevelEventHandler:IsFirstVisited()
    return self.visited_first_time
end
-------------------------------------------------------------------------------

function LevelEventHandler:IsCollectorsEdition()    
    return self.is_collectors_edition
end
-------------------------------------------------------------------------------

function LevelEventHandler:GetVideoFolder()
    return self.video_folder
end

function LevelEventHandler:GetVideoPath( nameVideo )
    return self:GetVideoFolder() .. nameVideo .. '.ogg'
end
-------------------------------------------------------------------------------

function LevelEventHandler:CutScene(is_cut_scene, ScrZ, time)    
    if is_cut_scene ~= self.is_cut_scene then
        self.is_cut_scene = is_cut_scene
        
        time = time and time or 1
        
        if self.cut_scene_Eff then
            self.cut_scene_Eff.Top:Destroy()
            self.cut_scene_Eff.Bottom:Destroy()
        else
            self.cut_scene_Eff = {}
        end
        
        if self.cut_scene_timer then
            self.cut_scene_timer:Kill()
        end
        
        if is_cut_scene then
            self.PanelMode = self:GetPanelLuaObject():GetMode()
            
            self:GetPanelLuaObject():SetMode(EPanelMode.PM_CLEAN)
            
            local MaxZ
            if ScrZ then
                MaxZ = ScrZ
            else
                MaxZ = play_field:GetMaxObjectZ() + 1
            end
            
            Object('cut_border_top'   ):SetScrZ(MaxZ)
            Object('cut_border_bottom'):SetScrZ(MaxZ)
            
            self.cut_scene_Eff.Top    = Object('cut_border_top'   ):ChangeOpacity( Object('cut_border_top'   ):GetOpacity() ,1, time)
	        self.cut_scene_Eff.Bottom = Object('cut_border_bottom'):ChangeOpacity( Object('cut_border_bottom'):GetOpacity() ,1, time)
	        
	        self.cut_scene_Eff.Top:SetDestroysOnEnd(false)
	        self.cut_scene_Eff.Bottom:SetDestroysOnEnd(false)
	        
	        self.mouseBlocker:Push()
        else
            self:GetPanelLuaObject():SetMode(self.PanelMode)
            
            self.cut_scene_Eff.Top    = Object('cut_border_top'   ):ChangeOpacity( Object('cut_border_top'   ):GetOpacity() ,0, time)
	        self.cut_scene_Eff.Bottom = Object('cut_border_bottom'):ChangeOpacity( Object('cut_border_bottom'):GetOpacity() ,0, time)
	        
	        self.cut_scene_Eff.Top:SetDestroysOnEnd(false)
	        self.cut_scene_Eff.Bottom:SetDestroysOnEnd(false)
	        
	        self.cut_scene_timer = self.timer:Add(
                function()
                    Object('cut_border_top'   ):SetScrZ(-1)
                    Object('cut_border_bottom'):SetScrZ(-1)
                end, time)
	        
	        self.mouseBlocker:Pop()
        end
    end
end
-------------------------------------------------------------------------------
function LevelEventHandler:RegisterToolFindMG(toolName)
    self.find_toolMG = toolName
end
-------------------------------------------------------------------------------

function LevelEventHandler:SetAdditionalHintObject(ObjectName, ...)
    local addobj = {...}
    if not addobj then
        addobj = true
    end
    
    self.additional_hint_objects[ObjectName] = addobj
end
-------------------------------------------------------------------------------

function LevelEventHandler:CallForZones(funcName, ...)
    --[[
    if level.zones then
        for i, zone in pairs(level.zones) do
            local ZoneObject = zone.ZoneObject
            if ZoneObject then
                ZoneObject[funcName](ZoneObject, ...)
            end
        end
    end
    ]]
    if self.active_zone then
        local ZoneObject = self.active_zone.ZoneObject
        if ZoneObject and ZoneObject[funcName] then
            ZoneObject[funcName](ZoneObject, ...)
        end
    end
end
-------------------------------------------------------------------------------

function LevelEventHandler:GetFishManager()
    return self.fish_manager
end
-------------------------------------------------------------------------------

function LevelEventHandler:LoadDefaultData(screen)
    local anim = CreateAnimation('data/Texture/Common/fade.png',0,0,512,384,1,0)
    anim:SetHotSpot(256,192)
    anim:SetBlendMode(2)
    anim:SetColor('0xFFFFFFFF')
    screen:CreateObject('zoom_fade',anim,512,384,500,0,2,2)

	local anim = CreateAnimation('data/Texture/Common/fade.png',0,0,512,384,1,0)
	anim:SetHotSpot(256,192)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fade_in_on_load',anim,512,384,1000,0,2,2)

    local anim = CreateAnimation('data/Texture/Effect/EffectHighlight.png',0,0,82,82,27,24)
    anim:SetHotSpot(41,41)
    anim:SetBlendMode(2)
    anim:SetColor('0xFFFFFFFF')
    screen:CreateObject('object_highlight',anim,512,384,100,0,1,1)

	local anim = CreateAnimation('data/Texture/Effect/Single_Particle.PNG',0,0,36,36,1,0)
	anim:SetHotSpot(18,18)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('quest_object_highlight',anim,512,384,140,0,1,1)
	
	local anim = CreateAnimation('data/Texture/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0xCC000000')
	screen:CreateObject('cut_border_top',anim,512,24,-1,0,128,6)
	
	local anim = CreateAnimation('data/Texture/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0xCC000000')
	screen:CreateObject('cut_border_bottom',anim,512,744,-1,0,128,6)
	
	if self.LoadData then
	    self:LoadData(screen)
	end
end
-------------------------------------------------------------------------------