panel = nil;

local TITLE_TEXT_SCALE  = 1;
local TEXT_SCALE        = 0.9;
local TEXT_SPACING      = 0.7;
local TEXT_TRACKING     = -6;
local TITLE_COLOR       = "0xFFFF0000";
local TEXT_COLOR        = "0xFF000000";
local RIGHT_PAGE_TEXT_X = 37;

local LEFT_PAGE_BORDER  = 120;
local RIGHT_PAGE_BORDER = 570;
local PAGE_TEXT_WIDTH   = 345;
local PAGE_WIDTH        = RIGHT_PAGE_BORDER - LEFT_PAGE_BORDER;

NOTE_PREV_ID = "_PREV_ID_";
NOTE_SIDE_LEFT  = 0;
NOTE_SIDE_RIGHT = 1;

function PanelOnSceneLoad(screen)
    LoadData(screen)

    panel = screen
    panel:SetLayer(5);
    local back        = screen:GetObject('background')
    local back_comics = screen:GetObject('background_comics')
    
    back_comics:AttachTo(back)
    back_comics:SetXY(back_comics:GetX() - back:GetX(), back_comics:GetY() - back:GetY())
    back_comics:SetZ(back_comics:GetZ() - back:GetZ())
    
    local back_comics_monolog   = screen:GetObject('back_comics_monolog');
    local ctcText               = CreateTextEntity(COMICS_FONT, 'CLICK_TO_CLOSE');
    local monolog_info          = GetCharacterInfo('PlayerMonolog');
    
    ctcText:SetTextAlignment(HGETEXT_TOP + HGETEXT_LEFT)
    ctcText:SetSpacing(monolog_info.spacing);
	ctcText:SetScale(0.5)
    ctcText:SetColor(monolog_info.text_color)
    
    
    ctcText:AttachTo( back_comics_monolog );
    ctcText:SetZ(1);
	ctcText:SetXY(190, 35);

    panel.monolog_ctc_text = ctcText;
    panel.objects_to_scale = {}
    
    local set_mouse_dependent_states = function(object, mouse_not_over, mouse_over, mouse_pressed)
        if not panel.mouse_dependent_states then
            panel.mouse_dependent_states = {}
        end
        
        local info = {};
        panel.mouse_dependent_states[object] = info;
        
        info.mouse_not_over = mouse_not_over
        info.mouse_over     = mouse_over
        info.mouse_pressed  = mouse_pressed
        info.hold           = false;
        
        
        panel:IgnoreOnTestPoint( mouse_not_over )
        panel:IgnoreOnTestPoint( mouse_over )
        panel:IgnoreOnTestPoint( mouse_pressed )

        panel:GetObject( mouse_not_over ):AttachTo(panel:GetObject(object))
        panel:GetObject( mouse_over     ):AttachTo(panel:GetObject(object))
        panel:GetObject( mouse_pressed  ):AttachTo(panel:GetObject(object))

        panel:GetObject( mouse_over     ):SetVisible(false)
        panel:GetObject( mouse_pressed  ):SetVisible(false)
    end
    
    set_mouse_dependent_states('button_r_hint',  'hint',                    'hint_mouse_over',      'hint_mouse_pressed')
    set_mouse_dependent_states('button_r_skip',  'skip',                    'skip_mouse_over',      'skip_mouse_pressed')
    set_mouse_dependent_states('button_menu',    'menu',                    'menu_mouse_over',      'menu_mouse_pressed')
    set_mouse_dependent_states('note',           'note_not_over',           'note_mouse_over',      'note_mouse_pressed')
    set_mouse_dependent_states('notebook_close', 'notebook_close_not_over', 'notebook_close_over',  'notebook_close_pressed');
    set_mouse_dependent_states('LScroll',        'LScroll_not_over',        'LScroll_over',         'LScroll_pressed');
    set_mouse_dependent_states('RScroll',        'RScroll_not_over',        'RScroll_over',         'RScroll_pressed');

    panel:GetObject('background_comics'):SetOpacity(0.)
    panel:GetObject('background_comics'):SetVisible(false)
    
    panel:GetObject('button_r_hint'):GetAnimation():SetMode(HGEANIM_FWD + HGEANIM_NOLOOP);
    panel:GetObject('button_r_hint'):GetAnimation():Stop();
    
    panel:GetObject('button_r_skip'):GetAnimation():SetMode(HGEANIM_FWD + HGEANIM_NOLOOP);
    panel:GetObject('button_r_skip'):GetAnimation():Stop();
    
    panel:GetObject('timer_activation_anim'):GetAnimation():SetMode(HGEANIM_FWD + HGEANIM_NOLOOP);
    panel:GetObject('timer_activation_anim'):GetAnimation():Stop();
    panel:IgnoreOnTestPoint('timer_activation_anim');
    
    local noteOpen = panel:GetObject('note_open');
    noteOpen:GetAnimation():Stop();
    noteOpen:Hide();

    --panel:IgnoreOnTestPoint("background")
    local wheelRightAnim = panel:GetObject("WheelRight"):GetAnimation();
    wheelRightAnim:Stop();
    
    local mechanismAnim = panel:GetObject('mechanism'):GetAnimation();
    mechanismAnim:SetMode(HGEANIM_NOLOOP + HGEANIM_PINGPONG);
    mechanismAnim:Stop();
    
    panel:GetObject('sand_glass_back'):Hide();
    panel:GetObject('sand_glass_fill'):Hide();
    
    local noteObj = panel:GetObject("note");
    local noteHL  = panel:GetObject("BookLighting");
    
    panel:IgnoreOnTestPoint("BookLighting");
    noteHL:SetVisible(false);
    noteHL:AttachTo(  noteObj )
    noteHL:SetXY(noteHL:GetX() - noteObj:GetX(), noteHL:GetY() - noteObj:GetY());
    noteHL:SetZ(1);
    
    -- NOTEBOOK CONTENT
    panel.notebook = CreateNotebook();
    
    panel.notebook.attachObjects(   panel:GetObject('notebook_close'),
                                    panel:GetObject('LScroll'),
                                    panel:GetObject('RScroll'));
                                    
    panel.notebook.LButton = panel:GetObject('LScroll');
    panel.notebook.RButton = panel:GetObject('RScroll');
    
    RegisterAllNotes( panel.notebook );
    
    PanelSetSkipButtonVisible(false)
end

----------------------------------------------------------------------------------------
function CreateNotebook()
    local notebook = {};
    
    notebook.bg   = panel:GetObject('notebook');
    notebook.bg_x = notebook.bg:GetX();
    notebook.bg_y = notebook.bg:GetY();
    
    notebook.notes = {};
    notebook.pages = {};
    notebook.last_hole_filler = nil;
    
    notebook.currPageId = 0;
    
    notebook.appearing_time = 1;
    notebook.is_open        = false;
    
    notebook.LButton = nil;
    notebook.RButton = nil;
    
    ---------------------------
    
    notebook.Open = function()
        notebook.bg:Show();
        notebook.bg:ChangeOpacity(0, 1, notebook.appearing_time);
        
        notebook.SetPageVisible( notebook.currPageId, true);
        notebook.CheckButtons();
        
        notebook.is_open = true
    end
    
    ---------------------------
    
    notebook.Close = function()
        notebook.bg:Show();
        notebook.bg:ChangeOpacity(1, 0, notebook.appearing_time);
        
        notebook.is_open = false
        
        TimerDoString("panel.notebook.OnClosed();", notebook.appearing_time, panel:GetTimer())
    end
    
    ---------------------------
    
    notebook.OnClosed = function()
       notebook.bg:Hide();
       notebook.SetPageVisible( notebook.currPageId, false);
    end
    
    ---------------------------
    
    notebook.isOpen = function()
        return notebook.is_open
    end
    
    ---------------------------
    
    notebook.attachObject = function(obj)
        obj:SetZ(obj:GetZ() - notebook.bg:GetZ());
        obj:SetXY(obj:GetX() - notebook.bg_x, obj:GetY() - notebook.bg_y);
        
        obj:AttachTo( notebook.bg );
    end
    
    ---------------------------
    
    notebook.attachObjects = function(...)
        local arg = {...}
        
        for id, obj in ipairs(arg) do
            notebook.attachObject(obj);
        end
    end
    
    ---------------------------
    
    notebook.RegisterNote = function(noteId, is_double_size, createContent, beforeShow)
        local note = {};
        notebook.notes[noteId] = note;
        
        note.id = noteId;
        note.is_double_size = is_double_size;
        note.objects = {};
        
        note.created = false;
        note.visible = false;
        
        note.createContent = createContent;
        note.beforeShow    = beforeShow;
        
        --
        
        note.create = function(side)
            if note.created then
                return false
            end
            
            local not_attach = {}
            
            note.createContent(note.objects, not_attach)
            
            for id, obj in pairs(note.objects) do
            
                if not not_attach[id] then
                
                    if side == NOTE_SIDE_LEFT then
                        obj:SetX(obj:GetX() + LEFT_PAGE_BORDER);
                    else
                        obj:SetX(obj:GetX() + RIGHT_PAGE_BORDER);
                    end
                    
                    notebook.attachObject(obj);
                end
                
            end
            
            note.hide();
            note.created = true;
            
            return true;
        end
        
        --
        
        note.hide = function()
            for name, obj in pairs(note.objects) do
                obj:SetVisible(false);
            end
            
            note.visible = false;
        end
        
        --
        
        note.show = function()
            if note.beforeShow then
                note.beforeShow(note.objects);
            end
            
            for i, obj in pairs(note.objects) do
                obj:SetVisible(true);
            end
            
            note.visible = true;
        end
    end
    
    ---------------------------
    
    notebook.GetNote = function(noteId)
        return notebook.notes[noteId];
    end
    
    ---------------------------
    
    notebook.AddNote = function(noteId)
        local note   = notebook.notes[noteId];
        local pageId = table.getn(notebook.pages) + 1;
        
        if note.is_double_size then
            if math.fmod(pageId, 2) == 0 then
                pageId = pageId + 1
            end
            
            notebook.pages[pageId]   = noteId;
            notebook.pages[pageId+1] = NOTE_PREV_ID;
            
            local prevPageId = pageId - 1;
            if prevPageId > 1 and notebook.pages[prevPageId] == nil then
                if notebook.last_hole_filler == nil or notebook.last_hole_filler == '_LEAFS_HOLE_FILLER_2' then
                    notebook.last_hole_filler = '_LEAFS_HOLE_FILLER_1'
                else
                    notebook.last_hole_filler = '_LEAFS_HOLE_FILLER_2'
                end
                
                notebook.pages[prevPageId] = notebook.last_hole_filler;
                notebook.notes[notebook.last_hole_filler].create(NOTE_SIDE_RIGHT);
            end
        else
            notebook.pages[pageId] = noteId;
        end
        
        --Save
        local value = pageId.."="..notebook.pages[pageId];
        if not HasGameState('NotebookNotes', value) then
            AddGameState('NotebookNotes', value)
        end
        
        -- Create note content
        local side = (math.fmod(pageId, 2) == 0) and NOTE_SIDE_RIGHT or NOTE_SIDE_LEFT;
        note.create(side);
        
        local prevPageId    = notebook.currPageId;
        notebook.currPageId = (side == NOTE_SIDE_LEFT) and pageId or (pageId - 1);
        
        if notebook.isOpen() then
            if prevPageId ~= notebook.currPageId then
                notebook.SetPageVisible(prevPageId, false);
                notebook.SetPageVisible(notebook.currPageId, true);
            else
                note.show();
            end
            
            notebook.CheckButtons();
        end
    end
    
    ---------------------------
    
    notebook.IsNoteAdded = function(noteId)
        for pageId, noteId_ in pairs(notebook.pages) do
            if noteId == noteId_ then
                return true
            end
        end
        
        return false;
    end
    
    ---------------------------
    
    notebook.LoadNotes = function()
        if HasGameState('NotebookNotes') then
            local save_states  = GetGameState('NotebookNotes')
            local loaded_notes = {};
            
            local max_id       = -1;
            local sepPos       = -1;
            local value        = nil;
            local noteId       = nil;
            local pageId       = nil;
            
            for i=0, save_states:GetSize()-1 do
                value  = save_states:Get(i);
                sepPos = string.find(value, "=");
                pageId = tonumber( string.sub(value, 1, sepPos-1) );
                noteId = string.sub(value, sepPos+1, string.len(value));
                
                loaded_notes[pageId] = noteId;
                
                if pageId > max_id then
                    max_id = pageId;
                end
            end
            
            for i=0, max_id do
                noteId = loaded_notes[i];
                
                if noteId then
                    notebook.AddNote(noteId);
                end
            end
        end
    end
    
    ---------------------------
    
    notebook.SetPageVisible = function(pageId, visible)
        local funct = (visible) and 'show' or 'hide'
        
        local lNodeId = notebook.pages[pageId];
        local rNodeId = notebook.pages[pageId + 1];
        
        if lNodeId then
            notebook.GetNote(lNodeId)[funct]();
        end
        
        if rNodeId and rNodeId ~= NOTE_PREV_ID then
            notebook.GetNote(rNodeId)[funct]();
        end
    end
    
    ---------------------------
    
    --[[
            target:     namber  - открыть страничку с указаным индексом
                        'prev'  - перейти на предыдущую страничку
                        'next'  - перейти на следующую страничку
    --]]
        
    notebook.SetPage = function(target)
        local newPageId;
        
        if type(target) == 'string' then
            if target == 'next' then
                newPageId = notebook.currPageId + 2;
            else
                newPageId = notebook.currPageId - 2;
            end
        elseif target ~= notebook.currPageId then
            newPageId = target;
        end
        
        if (newPageId < 1) or (newPageId > table.getn(notebook.pages)) then
            return;
        end
        
        notebook.SetPageVisible(notebook.currPageId, false);
        notebook.SetPageVisible(newPageId, true);
        
        notebook.currPageId = newPageId;
        
        notebook.CheckButtons();
    end
    
    ---------------------------
    
    notebook.CheckButtons = function()
        if (table.getn(notebook.pages) - notebook.currPageId) > 1 then
            notebook.RButton:Show();
        else
            notebook.RButton:Hide();
        end
        
        if notebook.currPageId > 1 then
            notebook.LButton:Show();
        else
            notebook.LButton:Hide();
        end
    end
    
    ---------------------------
    
    notebook.bg:Hide();
    
    return notebook;
end

----------------------------------------------------------------------------------------
function RegisterAllNotes(notebook)
    notebook.RegisterNote('_LEAFS_HOLE_FILLER_1', false,    function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Leafs_1.png',0,0,436,597,1,0)
                                                                anim:SetHotSpot(218,298)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Leafs_1'] = panel:CreateObject('Leafs_1',anim,172,328,301,0,1,1)
                                                            end);
    
    notebook.RegisterNote('_LEAFS_HOLE_FILLER_2', false,    function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Leafs_2.png',0,0,413,556,1,0)
                                                                anim:SetHotSpot(206,278)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Leafs_2'] = panel:CreateObject('Leafs_2',anim,173,311,301,0,1,1)
                                                            end);
    
    notebook.RegisterNote('A_STORMY_NIGHT', true,           function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry1_1.png',0,0,465,251,1,0)
                                                                anim:SetHotSpot(232,125)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry1_1'] = panel:CreateObject('Entry1_1',anim,193,430,300,14,1,1)
                                                                
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry1_2.png',0,0,180,204,1,0)
                                                                anim:SetHotSpot(90,102)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry1_2'] = panel:CreateObject('Entry1_2',anim,89,180,300,-20,1,1)
                                                                
                                                                --
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_A_STORMY_NIGHT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_A_STORMY_NIGHT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 150);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('DUPINS_FOYER', true,           function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry2_1.png',0,0,213,165,1,0)
                                                                anim:SetHotSpot(106,82)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry2_1'] = panel:CreateObject('Entry2_1',anim,150,440,301,-5,1,1)
                                                                
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry2_2.png',0,0,317,252,1,0)
                                                                anim:SetHotSpot(158,126)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry2_2'] = panel:CreateObject('Entry2_2',anim,620,340,301,20,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_DUPINS_FOYER");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_DUPINS_FOYER");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 150);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('DUPINS_STORAGE_ROOM', false,     function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry3_1_1.png',0,0,257,215,1,0)
                                                                anim:SetHotSpot(128,107)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry3_1_1'] = panel:CreateObject('Entry3_1_1',anim,106,220,301,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_DUPINS_STORAGE_ROOM");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_DUPINS_STORAGE_ROOM");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 340);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('THE_SILHOUETTE', false,         function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry3_2_3.png',0,0,220,220,1,0)
                                                                anim:SetHotSpot(110,110)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry3_2_3'] = panel:CreateObject('Entry3_2_3',anim,100,468,301,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_THE_SILHOUETTE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_THE_SILHOUETTE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 150);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('CHEST_OPEN', false,              function(buf)
                                                                
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry3_1_2.png',0,0,298,241,1,0)
                                                                anim:SetHotSpot(149,120)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry3_1_2'] = panel:CreateObject('Entry3_1_2',anim,130,445,301,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_CHEST_OPEN");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 120);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('GOLD_FOUND', false,             function(buf)
                                                                
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry3_2_1.png',0,0,179,361,1,0)
                                                                anim:SetHotSpot(89,180)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry3_2_1'] = panel:CreateObject('Entry3_2_1',anim,55,257,301,0,1,1)
                                                                
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry3_2_2.png',0,0,191,221,1,0)
                                                                anim:SetHotSpot(95,110)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry3_2_2'] = panel:CreateObject('Entry3_2_2',anim,310,490,303,5,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_GOLD_FOUND");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_TEXT_WIDTH/2 - 35, 120);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize( 215 / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_GOLD_FOUND_2");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                               -- tf:SetXY(-10, 440);
                                                                tf:SetXY(0, 440);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize( 250 / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text_2'] = tf
                                                            end);

    notebook.RegisterNote('VASE_BROKEN', true,             function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry3_3.png',0,0,354,294,1,0)
                                                                anim:SetHotSpot(177,147)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry3_3'] = panel:CreateObject('Entry3_3',anim,169,308,301,0,1.2,1.2)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_THE_BROKEN_VASE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_THE_BROKEN_VASE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 220);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end)
                                                            
    notebook.RegisterNote('STAGECOACH', true,               function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry4.png',0,0,296,375,1,0)
                                                                anim:SetHotSpot(148,187)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry3_3'] = panel:CreateObject('Entry4',anim,170,320,301,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_STAGECOACH");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_STAGECOACH");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 105);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('LOCK_PART', false,               function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry5_1.png',0,0,283,257,1,0)
                                                                anim:SetHotSpot(141,128)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry5_1'] = panel:CreateObject('Entry5_1',anim,117,427,301,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_LOCK_PART");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_LOCK_PART");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 150);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('VISITKA', false,                 function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry5_2.png',0,0,322,212,1,0)
                                                                anim:SetHotSpot(161,106)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry5_2'] = panel:CreateObject('Entry5_2',anim,199,206,301,10,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_VIZITKA");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 340);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('MIGNAUD_ET_FILS_BANK', true,     function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry6.png',0,0,324,317,1,0)
                                                                anim:SetHotSpot(162,158)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry6'] = panel:CreateObject('Entry6',anim,168,324,301,-15,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_MIGNAUD_ET_FILS_BANK");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_MIGNAUD_ET_FILS_BANK");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('BANK_OFFICE', true,             function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry7.png',0,0,327,305,1,0)
                                                                anim:SetHotSpot(163,152)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry7'] = play_field:CreateObject('Entry7',anim,178,330,301,-3,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_BANK_OFFICE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_BANK_OFFICE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                
                                                                buf['text'] = tf
                                                            end);

     notebook.RegisterNote('SAFETY_DEPOSIT_ROOM', true,     function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry8.png',0,0,415,351,1,0)
                                                                anim:SetHotSpot(207,175)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry8'] = play_field:CreateObject('Entry8',anim,642,336,300,9,1,1);
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_SAFETY_DEPOSIT_ROOM");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_SAFETY_DEPOSIT_ROOM");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('Witness_Banker', true,           function(buf, not_attach)
                                                                CreateWitnesTextFields( notebook );
                                                                
                                                                for name, tf in pairs(panel.witnessFields) do
                                                                    buf[name] = tf;
                                                                    
                                                                    if panel.witnessFieldsAdded then
                                                                        not_attach[name] = tf
                                                                    end
                                                                end
                                                                panel.witnessFieldsAdded = true;
                                                                
                                                                local anim = CreateAnimation('data/Texture/Characters/Photos/Banker_photo.png',0,0,205,403,1,0)
                                                                anim:SetHotSpot(102,201)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Banker_photo'] = panel:CreateObject('Banker_photo',anim,80,354,211,0,1,1)
                                                            end,
                                                            function(buf)
                                                                buf.witness_name:SetText(         GetString("WITNESS_NAME_1")         );
                                                                buf.witness_occupation:SetText(   GetString("WITNESS_OCCUPATION_1")   );
                                                                buf.witness_special_note:SetText( GetString("WITNESS_SPECIAL_NOTE_1") );
                                                                buf.witness_testimony:SetText(    GetString("WITNESS_TESTIMONY_1")    );
                                                            end);
                                                        
    notebook.RegisterNote('POLICE_STATION', true,           function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry9_1.png',0,0,372,507,1,0)
                                                                anim:SetHotSpot(186,253)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry9_1'] = panel:CreateObject('Entry9_1',anim,167,344,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_POLICE_STATION");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_POLICE_STATION");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('POLICE_STATION_2', true,         function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry9_2.png',0,0,407,401,1,0)
                                                                anim:SetHotSpot(203,200)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry9_2'] = panel:CreateObject('Entry9_2',anim,593,304,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_POLICE_STATION_2");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('JAIL_CELLS', false,              function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry10_1.png',0,0,317,269,1,0)
                                                                anim:SetHotSpot(158,134)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry10_1'] = panel:CreateObject('Entry10_1',anim,168,225,300,0,0.9,0.9)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_JAIL_CELLS");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_JAIL_CELLS");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 350);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('JAIL_CELLS_2', false,           function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry10_2.png',0,0,317,194,1,0)
                                                                anim:SetHotSpot(158,97)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry10_2'] = panel:CreateObject('Entry10_2',anim,171,466,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_JAIL_CELLS_2");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 120);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('JAIL_CELLS_3', false,            function(buf)   
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_JAIL_CELLS_3");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 240);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('Witness_Gendarme', true,        function(buf, not_attach)
                                                                CreateWitnesTextFields( notebook );
                                                                
                                                                for name, tf in pairs(panel.witnessFields) do
                                                                    buf[name] = tf;
                                                                    
                                                                    if panel.witnessFieldsAdded then
                                                                        not_attach[name] = tf
                                                                    end
                                                                end
                                                                panel.witnessFieldsAdded = true;
                                                                
                                                                local anim = CreateAnimation('data/Texture/Characters/Photos/Gendarme_photo.png',0,0,205,336,1,0)
                                                                anim:SetHotSpot(102,168)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Gendarme_photo'] = panel:CreateObject('Gendarme_photo',anim,85,369,211,0,1,1)
                                                            end,
                                                            function(buf)
                                                                buf.witness_name:SetText(         GetString("WITNESS_NAME_2")         );
                                                                buf.witness_occupation:SetText(   GetString("WITNESS_OCCUPATION_2")   );
                                                                buf.witness_special_note:SetText( GetString("WITNESS_SPECIAL_NOTE_2") );
                                                                buf.witness_testimony:SetText(    GetString("WITNESS_TESTIMONY_2")    );
                                                            end);

    notebook.RegisterNote('RESTAURANT', true,               function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry11.png',0,0,305,344,1,0)
                                                                anim:SetHotSpot(152,172)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry11'] = panel:CreateObject('Entry11',anim,177,324,300,0,1,1)
                                                            
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_RESTAURANT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_RESTAURANT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 220);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('RESTAURANT_2', false,            function(buf)
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_RESTAURANT_2");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 220);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('Witness_Restorator', true,     function(buf, not_attach)
                                                                CreateWitnesTextFields( notebook );
                                                                
                                                                for name, tf in pairs(panel.witnessFields) do
                                                                    buf[name] = tf;
                                                                    
                                                                    if panel.witnessFieldsAdded then
                                                                        not_attach[name] = tf
                                                                    end
                                                                end
                                                                panel.witnessFieldsAdded = true;
                                                                
                                                                local anim = CreateAnimation('data/Texture/Characters/Photos/Restorator_photo.png',0,0,200,339,1,0)
                                                                anim:SetHotSpot(100,169)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Restorator_photo'] = panel:CreateObject('Restorator_photo',anim,83,354,211,0,1,1)
                                                            end,
                                                            function(buf)
                                                                buf.witness_name:SetText(         GetString("WITNESS_NAME_3")         );
                                                                buf.witness_occupation:SetText(   GetString("WITNESS_OCCUPATION_3")   );
                                                                buf.witness_special_note:SetText( GetString("WITNESS_SPECIAL_NOTE_3") );
                                                                buf.witness_testimony:SetText(    GetString("WITNESS_TESTIMONY_3")    );
                                                            end)
    
    notebook.RegisterNote('LAUNDRY_LADY', true,             function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry12.png',0,0,281,383,1,0)
                                                                anim:SetHotSpot(140,191)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry12'] = panel:CreateObject('Entry12',anim,660,268,300,5,1,1)
                                                            
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_LAUNDRY_LADY");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_LAUNDRY_LADY");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('LAUNDROMAT', true,               function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry13_1_1.png',0,0,360,315,1,0)
                                                                anim:SetHotSpot(180,157)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry13_1_1'] = panel:CreateObject('Entry13_1_1',anim,171,321,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_LAUNDROMAT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_LAUNDROMAT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 240);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('LAUNDROMAT_2', true,             function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry13_1_2.png',0,0,250,197,1,0)
                                                                anim:SetHotSpot(125,98)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry13_1_2'] = panel:CreateObject('Entry13_1_2',anim,583,242,300,3,1,1)
                                                                
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry13_1_3.png',0,0,144,170,1,0)
                                                                anim:SetHotSpot(72,85)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry13_1_3'] = panel:CreateObject('Entry13_1_3',anim,707,459,300,-11,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_LAUNDROMAT_2");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 220);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('LAUNDROMAT_3', true,             function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry13_2.png',0,0,209,220,1,0)
                                                                anim:SetHotSpot(104,110)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry13_2'] = panel:CreateObject('Entry13_2',anim,174,310,300,-9,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_LAUNDROMAT_3");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 260);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('SALON', false,                   function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry13_3_1.png',0,0,237,254,1,0)
                                                                anim:SetHotSpot(118,127)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry13_3_1'] = panel:CreateObject('Entry13_3_1',anim,245,490,300,3,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_SALON");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_SALON");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 150);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('SALON_2', false,                 function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry13_3_2.png',0,0,141,141,1,0)
                                                                anim:SetHotSpot(70,70)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry13_3_2'] = panel:CreateObject('Entry13_3_2',anim,279,483,300,-6,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_SALON_2");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 220);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                        
    notebook.RegisterNote('SALON_3', true,                  function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry13_4.png',0,0,298,347,1,0)
                                                                anim:SetHotSpot(149,173)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry13_4'] = panel:CreateObject('Entry13_4',anim,169,323,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_SALON_3");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 220);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('ENTRYWAY', false,                function(buf)
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_ENTRYWAY");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_ENTRYWAY");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('ENTRYWAY_2', false,              function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry14_1.png',0,0,400,307,1,0)
                                                                anim:SetHotSpot(200,153)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry14_1'] = panel:CreateObject('Entry14_1',anim,180,400,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_ENTRYWAY_2");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 130);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('ENTRYWAY_3', true,               function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry14_2_1.png',0,0,198,185,1,0)
                                                                anim:SetHotSpot(99,92)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry14_2_1'] = panel:CreateObject('Entry14_2_1',anim,532,191,300,-9,1,1)
                                                                
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry14_2_2.png',0,0,208,145,1,0)
                                                                anim:SetHotSpot(104,72)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry14_2_2'] = panel:CreateObject('Entry14_2_2',anim,682,416,300,7,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_ENTRYWAY_3");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 220);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('STAINED_GLASS_HALLWAY', true,    function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry15.png',0,0,349,265,1,0)
                                                                anim:SetHotSpot(174,132)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry15'] = panel:CreateObject('Entry15',anim,173,327,300,3,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_STAINED_GLASS_HALLWAY");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_STAINED_GLASS_HALLWAY");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 220);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('UPSTAIRS_FIRST_VISIT', false,    function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry16_1_1.png',0,0,240,243,1,0)
                                                                anim:SetHotSpot(120,121)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry16_1_1'] = panel:CreateObject('Entry16_1_1',anim,170,250,300,0,1,1)
	
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_UPSTAIRS_FIRST_VISIT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_UPSTAIRS_FIRST_VISIT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 400);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('UPSTAIRS_AQUARIUM', false,       function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry16_1_2.png',0,0,297,251,1,0)
                                                                anim:SetHotSpot(148,125)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry16_1_2'] = panel:CreateObject('Entry16_1_2',anim,180,420,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_UPSTAIRS_AQUARIUM");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 120);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('BACK_OF_THE_HOUSE', false,       function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry16_2_1.png',0,0,257,207,1,0)
                                                                anim:SetHotSpot(128,103)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry16_2_1'] = panel:CreateObject('Entry16_2_1',anim,200,215,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_BACK_OF_THE_HOUSE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_BACK_OF_THE_HOUSE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 330);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('ASID_RECEIVED', false,           function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry16_2_2.png',0,0,248,242,1,0)
                                                                anim:SetHotSpot(124,121)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry16_2_2'] = panel:CreateObject('Entry16_2_2',anim,46,500,300,45,1,1)
                                                                
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry16_2_3.png',0,0,234,242,1,0)
                                                                anim:SetHotSpot(117,121)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry16_2_3'] = panel:CreateObject('Entry16_2_3',anim,285,490,300,-45,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_ASID_RECEIVED");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 120);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('BALL_RECEIVED', false,           function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry16_3.png',0,0,353,242,1,0)
                                                                anim:SetHotSpot(176,121)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry16_3'] = panel:CreateObject('Entry16_3',anim,189,450,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_BALL_RECEIVED");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 120);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('BEHIND_THE_STAINED', true,       function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry17.png',0,0,238,305,1,0)
                                                                anim:SetHotSpot(119,152)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry17'] = panel:CreateObject('Entry17',anim,640,300,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_BEHIND_THE_STAINED");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_BEHIND_THE_STAINED");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 230);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('DOCTORS_FLAT', true,             function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry18_1.png',0,0,348,371,1,0)
                                                                anim:SetHotSpot(174,185)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry18_1'] = panel:CreateObject('Entry18_1',anim,630,320,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_DOCTORS_FLAT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_DOCTORS_FLAT");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('WOLFS_EYE_RECEIVE', true,        function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry18_2.png',0,0,261,258,1,0)
                                                                anim:SetHotSpot(130,129)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry18_2'] = panel:CreateObject('Entry18_2',anim,160,340,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_WOLFS_EYE_RECEIVE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 200);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('MADAME_ROOM', true,              function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry19_1.png',0,0,454,426,1,0)
                                                                anim:SetHotSpot(227,213)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry19_1'] = panel:CreateObject('Entry19_1',anim,630,330,300,0,1,1)
	                                                            
	                                                            local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_MADAME_ROOM");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_MADAME_ROOM");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('MADAME_ROOM_ALL_FOUND', true,    function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry19_2.png',0,0,406,534,1,0)
                                                                anim:SetHotSpot(203,267)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry19_2'] = panel:CreateObject('Entry19_2',anim,161,333,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_MADAME_ROOM_ALL_FOUND");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 140);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('BOIS_DE_BOULOGNE', false,        function(buf)
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_BOIS_DE_BOULOGNE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_BOIS_DE_BOULOGNE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('BOIS_DE_BOULOGNE_HAIR', true,    function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry20.png',0,0,392,497,1,0)
                                                                anim:SetHotSpot(196,248)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf[''] = panel:CreateObject('Entry20',anim,170,330,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_BOIS_DE_BOULOGNE_HAIR");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(PAGE_WIDTH, 120);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('THE_DOCKS', true,                function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry21.png',0,0,455,242,1,0)
                                                                anim:SetHotSpot(227,121)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry21'] = panel:CreateObject('Entry21',anim,640,190,300,20,1,1)
	                                                            
	                                                            local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_THE_DOCKS");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_THE_DOCKS");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('THE_DUPLEIX', true,              function(buf)
                                                                
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry22_1.png',0,0,279,255,1,0)
                                                                anim:SetHotSpot(139,127)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry22_1'] = panel:CreateObject('Entry22_1',anim,630,300,300,0,1,1)
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_TITLE_THE_DUPLEIX");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 100);
                                                                tf:SetScale(TITLE_TEXT_SCALE);
                                                                tf:SetColor(TITLE_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['title'] = tf
                                                                
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_THE_DUPLEIX");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 180);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);

    notebook.RegisterNote('THE_DUPLEIX_GORILLA', false,     function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry22_2_1.png',0,0,236,264,1,0)
                                                                anim:SetHotSpot(118,132)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry22_2_1'] = panel:CreateObject('Entry22_2_1',anim,180,210,300,0,1,1)
	
                                                                local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_THE_DUPLEIX_GORILLA");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 350);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
    
    notebook.RegisterNote('THE_DUPLEIX_PUZZLE', false,      function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry22_2_2.png',0,0,350,292,1,0)
                                                                anim:SetHotSpot(175,146)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry22_2_2'] = panel:CreateObject('Entry22_2_2',anim,170,470,300,-10,1,1)
	                                                            
	                                                            local tf = CreateTextEntity(NOTEBOOK_FONT, "BOOK_NOTE_THE_DUPLEIX_PUZZLE");
                                                                tf:SetTextAlignment(HGETEXT_LEFT);
                                                                tf:SetXY(0, 120);
                                                                tf:SetScale(TEXT_SCALE);
                                                                tf:SetColor(TEXT_COLOR);
                                                                tf:SetBorderSize(PAGE_TEXT_WIDTH / tf:GetScale(), 0)
                                                                tf:SetSpacing( TEXT_SPACING );
                                                                tf:SetTracking( TEXT_TRACKING );
                                                                tf:SetZ(220);
                                                                buf['text'] = tf
                                                            end);
                                                            
    notebook.RegisterNote('EXTRAS_BOOKS_CODE', false,    function(buf)
                                                                local anim = CreateAnimation('data/Texture/GUI/NoteBook/Info_notes/Entry_Extras_1.png',0,0,443,333,1,0)
                                                                anim:SetHotSpot(221,166)
                                                                anim:SetBlendMode(2)
                                                                anim:SetColor('0xFFFFFFFF')
                                                                buf['Entry_Extras_1'] = panel:CreateObject('Entry_Extras_1',anim,202,342,300,-21,1,1)
                                                            end);
end

----------------------------------------------------------------------------------------
function AddNoteToNotebook(noteId)

    if not panel.notebook.IsNoteAdded(noteId) then
        panel.notebook.AddNote(noteId)    
        
        local mode = panel:GetMode();
            
        if mode == PM_QUEST
        or mode == PM_COMICSMONOLOG
        then
            SetHighlightingBookButton(false);
            PanelPlayNewNoteAnimation();
        end
        
        if not HasGameState("BookLighting", "true") then
            AddGameState("BookLighting", "true")
        end
        
        return true
    end
    
    return false;
end

function PanelPlayNewNoteAnimation()
    local noteOpen = panel:GetObject('note_open');
    noteOpen:Show();
    
    local noteOpenAnimation = noteOpen:GetAnimation();
    noteOpenAnimation:SetMode(HGEANIM_FWD + HGEANIM_PINGPONG + HGEANIM_NOLOOP);
    noteOpenAnimation:Play();
    
    panel.play_new_note_anim = true;
    
    PlaySound('OpenNotebook');
    
    TimerDoString("PanelOnNewNoteAnimationCompleted()", 1.2, panel:GetTimer());
end

function PanelOnNewNoteAnimationCompleted()
    if panel.play_new_note_anim then
        panel:GetObject('note_open'):Hide();
        panel:GetObject('note_open'):GetAnimation():Stop();
        panel:GetObject('note_open'):GetAnimation():SetFrame(0);
        
        panel.play_new_note_anim = false;
        
        SetHighlightingBookButton(true);
    end
end

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

function PanelSetNotebookDisable(disable)
    if disable then
        if not HasGameState('NOTEBOOD_DISABLED', 'true') then
            AddGameState('NOTEBOOD_DISABLED', 'true')
        end
    else
        if HasGameState('NOTEBOOD_DISABLED', 'true') then
            RemoveGameState('NOTEBOOD_DISABLED', 'true')
        end
    end
    
    panel.nootebook_disable = disable
end

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

function PanelIsNotebookDisable()
    return HasGameState('NOTEBOOD_DISABLED', 'true')
end

----------------------------------------------------------------------------------------
function CreateWitnesTextFields( notebook )
    if panel.witnessFields then
        return;
    end
    
    panel.witnessFields = {};
	
	local TEXT_DELTA_Y      = 25;
	
	local x_pos = PAGE_WIDTH - 20;
    local y_arr = { 100,
                    160,
                    220,
                    300}
    
    local textBox = CreateTextEntity(NOTEBOOK_FONT, 'WITNESS_NAME_TITLE');
	textBox:SetXY(x_pos, y_arr[1]);
	textBox:SetScale(TITLE_TEXT_SCALE);
	textBox:SetColor(TITLE_COLOR);
	
	panel.witnessFields.name_title = textBox;
	
	local textBox = CreateTextEntity(NOTEBOOK_FONT, 'OCCUPATION_TITLE');
	textBox:SetXY(x_pos, y_arr[2]);
	textBox:SetScale(TITLE_TEXT_SCALE);
	textBox:SetColor(TITLE_COLOR);
	
	panel.witnessFields.occupation_title = textBox;
	
	local textBox = CreateTextEntity(NOTEBOOK_FONT, 'SPECIAL_NOTE_TITLE');
	textBox:SetXY(x_pos, y_arr[3]);
	textBox:SetScale(TITLE_TEXT_SCALE);
	textBox:SetColor(TITLE_COLOR);
	
	panel.witnessFields.special_title = textBox;
	
	local textBox = CreateTextEntity(NOTEBOOK_FONT, 'TESTIMONY_TITLE');
	textBox:SetXY(x_pos, y_arr[4]);
	textBox:SetScale(TITLE_TEXT_SCALE);
	textBox:SetColor(TITLE_COLOR);
	
	panel.witnessFields.testimony_title = textBox;
	
	
	local textBox = CreateTextEntity(NOTEBOOK_FONT, "");
	textBox:SetXY(x_pos, y_arr[1] + TEXT_DELTA_Y);
	textBox:SetTextAlignment(HGETEXT_LEFT);
	textBox:SetScale(TEXT_SCALE);
	textBox:SetColor(TEXT_COLOR);
	
	panel.witnessFields.witness_name = textBox;
	
	local textBox = CreateTextEntity(NOTEBOOK_FONT, "");
	textBox:SetXY(x_pos, y_arr[2] + TEXT_DELTA_Y);
	textBox:SetScale(TEXT_SCALE);
	textBox:SetColor(TEXT_COLOR);
	
	panel.witnessFields.witness_occupation = textBox;
	
	local textBox = CreateTextEntity(NOTEBOOK_FONT, "");
	textBox:SetXY(x_pos, y_arr[3] + TEXT_DELTA_Y);
	textBox:SetScale(TEXT_SCALE);
	textBox:SetColor(TEXT_COLOR);
	textBox:SetBorderSize(385 / textBox:GetScale(), 0)
	
	panel.witnessFields.witness_special_note = textBox;
	
	local textBox = CreateTextEntity(NOTEBOOK_FONT, "");
	textBox:SetXY(x_pos, y_arr[4] + TEXT_DELTA_Y);
	textBox:SetScale(TEXT_SCALE);
	textBox:SetColor(TEXT_COLOR);
	textBox:SetBorderSize(385 / textBox:GetScale(), 0)
	
	panel.witnessFields.witness_testimony = textBox;
	
	for name, tf in pairs(panel.witnessFields) do
	    tf:SetTextAlignment( HGETEXT_LEFT );
	    tf:SetSpacing( TEXT_SPACING );
	    tf:SetTracking( TEXT_TRACKING );
	    tf:AttachTo( notebook.bg )
	    tf:SetZ(301);
	end
end

----------------------------------------------------------------------------------------
function SetHighlightingBookButton(higlighting)
    local obj = panel:GetObject("BookLighting");
    
    if higlighting then
        obj:SetOpacity(0.3);
        
        local eff = CreateAnimationEffector();
        eff:AttachTo( obj );
        eff:SetMode(_ANIM_PINGPONG + _ANIM_LOOP)
        
        eff:SetKey(_TRACK_O, 0, 0.3);
        eff:SetKey(_TRACK_O, 0.4, 1);
        eff:Play();
    else
        obj:DestroyChildren();
    end
    
    obj:SetVisible(higlighting);
end

function PanelOnChangeMode(mode)
    if mode == PM_QUEST
    or mode == PM_COMICSMONOLOG
    then
        if HasGameState("BookLighting", "true") then
            SetHighlightingBookButton(true);
        end
    else
        if HasGameState("BookLighting", "true") then
            SetHighlightingBookButton(false);
        end
    end
end

function PanelOnSceneStart()
    
end

function PanelSetSkipButtonVisible(is_visible)
    if is_visible then
        game_state.panel_button_name_to_restore = 'button_r_hint'
        if panel:GetObject('button_menu'):IsVisible() then
            game_state.panel_button_name_to_restore = 'button_menu'
        end
        panel:GetObject(game_state.panel_button_name_to_restore):Hide()
        panel:GetObject('button_r_skip'):Show()
    else
        if game_state.panel_button_name_to_restore then
            panel:GetObject(game_state.panel_button_name_to_restore):Show()
        end
        panel:GetObject('button_r_skip'):Hide()
    end
end

function PanelOnSceneFree(screen)
    FreeData(screen)
end

function PanelOnObjectMouseEnter(object)
    
    if game_state.tool then
        return;
    end
    
    local obj_name      = object:GetName();
    local allTasksFound = HasGameState("AllSceneTaskObjectsFound", game_state.scene_path)
    local isHintEnabled = panel:IsHintEnabled();
    
    if (obj_name == 'button_r_hint' and (not isHintEnabled or allTasksFound))
    or (obj_name == 'button_r_skip' and  not isHintEnabled)
    or (obj_name == 'note' and panel.nootebook_disable)
    then
        return;
    end
    
    if panel.objects_to_scale[obj_name] then    
        object:SetScale(panel.objects_to_scale[obj_name])
    end

    if panel.mouse_dependent_states[obj_name] then
        local info = panel.mouse_dependent_states[obj_name]
        
        panel:GetObject( info.mouse_not_over ):SetVisible(false)
        panel:GetObject( info.mouse_over     ):SetVisible(true)
        panel:GetObject( info.mouse_pressed  ):SetVisible(false)
    end
end

function PanelOnObjectMouseLeave(object)
    local obj_name = object:GetName();
    
    if panel.objects_to_scale[obj_name] then    
        object:SetScale(1.)
    end

    if panel.mouse_dependent_states[obj_name] then
        local info = panel.mouse_dependent_states[obj_name]
        
        panel:GetObject( info.mouse_not_over ):SetVisible(true)
        panel:GetObject( info.mouse_over     ):SetVisible(false)
        panel:GetObject( info.mouse_pressed  ):SetVisible(false)
    end

end
--[[
function OnInventoryButtonPress()
    assert(panel:GetMode() ~= PM_HIDDENOBJECT)

    if game_state.is_inventory_opened ~= nil then
        if game_state.is_inventory_opened then
            if play_field:GetTool() ~= '' then
                DropTool(0.)
            end
            HideInventory();
            TimerDoString('game_state.is_inventory_opened = false', 0.2, panel:GetTimer())
        else
            ShowInventory()
            --TimerDoString('game_state.is_inventory_opened = true', 6.66666666666667, panel:GetTimer())
            TimerDoString('game_state.is_inventory_opened = true', 0.2, panel:GetTimer())
            --GTimerDoString('game_state.is_inventory_opened = true', 0.2)
        end
        game_state.is_inventory_opened = nil
        --game_state.is_inventory_opened = not game_state.is_inventory_opened
    end
end
--]]
function PanelOnObjectMouseDown(object)
    if ingameMenu then
        return;
    end
    
    if endDemoScreen then
        return;
    end
    
    if game_state.tool then
        return;
    end
    
    local obj_name      = object:GetName();
    local allTasksFound = HasGameState("AllSceneTaskObjectsFound", game_state.scene_path)
    local isHintEnabled = panel:IsHintEnabled();
    
    if panel.mouse_dependent_states[obj_name]
        and not (obj_name == 'button_r_hint' and (not isHintEnabled or allTasksFound))
        and not (obj_name == 'button_r_skip' and not isHintEnabled)
        and not (obj_name == 'note' and panel.nootebook_disable)
    then
        local info = panel.mouse_dependent_states[obj_name]
 
        panel:GetObject( info.mouse_not_over ):SetVisible(false)
        panel:GetObject( info.mouse_over     ):SetVisible(false)
        panel:GetObject( info.mouse_pressed  ):SetVisible(true)
    end
    
    if obj_name == 'button_menu' then
        StartIngameMenu();
    end
    if obj_name == 'button_r_hint' and isHintEnabled and not allTasksFound then
        if panel:GetDelayTimer() <= 0. then
            panel:ButtonPress('Hint')
            PanelOnObjectMouseLeave(object);
        end
    end
    if obj_name == 'button_r_skip' then
        if panel:GetDelayTimer() <= 0. then
            panel:ButtonPress('Skip')
            PanelOnObjectMouseLeave(object);
            
            SkipMiniGame()
        end
    end
    if obj_name == 'button_down_r' then
        panel:ButtonPress('Close')
    end
    
    if obj_name == 'note' and not panel.nootebook_disable
    then
        TurnOffHelpTip('TIP_NOTEBOOK');
        
        if panel.play_new_note_anim then
            PanelOnNewNoteAnimationCompleted();
        end
        
        OpenNoteBook();
    end
    
    if (obj_name == 'notebook_close')
    then
        CloseNoteBook()
        
        if not HasGameState(HELP_SHOWN, 'TIP_DOOR') and InteractiveHelpBeingShown()
        then
            TimerDoString("ShowDoorTip();", 2, play_field:GetTimer());
        end
    end
    
    if (obj_name == 'LScroll')
    then
        panel.notebook.SetPage('prev')
    end
    
    if (obj_name == 'RScroll')
    then
        panel.notebook.SetPage('next')
    end

    if game_state.level_mode == 'hidden_object'
        and IsAboveReturnFromZoomZone()
        and play_field:GetLevelScreen():HasTaskObjects()
        and not play_field.mouseDownBlocked
        and (game_state.disable_default_zoom_exit ~= true)
    then
        SetCursor('CursorDefault')
        panel:ButtonPress('Close')
    end
    
    if game_state.level_mode ~= 'map' then
        UpdateComicsRequest()
    end
end

function PanelOnObjectMouseUp(object)
    
    if game_state.tool then
        return;
    end
    
    local obj_name      = object:GetName();
    local allTasksFound = HasGameState("AllSceneTaskObjectsFound", game_state.scene_path)
    local isHintEnabled = panel:IsHintEnabled();
    
    if panel.mouse_dependent_states[obj_name]
        and not (obj_name == 'button_r_hint' and (not isHintEnabled or allTasksFound))
        and not (obj_name == 'button_r_skip' and  not isHintEnabled)
    then
        local info = panel.mouse_dependent_states[obj_name]
        panel:GetObject( info.mouse_not_over ):SetVisible(false)
        panel:GetObject( info.mouse_over     ):SetVisible(true)
        panel:GetObject( info.mouse_pressed  ):SetVisible(false)
    end
    
    if game_state.level_mode == 'map' then
        local background_obj = play_field:GetObject('background');
        
        assert(background_obj);
        OnObjectMouseUp(background_obj);
    end
end

--Пустые фунцкии.. заглушки для уровней где не надо правая кнопка
function OnObjectRightMouseDown(object)
end

function OnObjectRightMouseUp(object)
end
----------------------------------------------------------------
	
function PanelOnButtonPress(title)

    if (title == 'Hint')
    then
        play_field:GetLevelScreen():GetPanel():GetObject('button_r_hint'):GetAnimation():Play();
    end
    
end

function OpenNoteBook()

    if panel.notebook.isOpen() then
        return;
    end
    
    panel.notebook.Open();
    
    local noteOpen = panel:GetObject('note_open');
    noteOpen:Show();
    local noteOpenAnimation = noteOpen:GetAnimation();
    noteOpenAnimation:SetMode(HGEANIM_FWD + HGEANIM_NOLOOP);
    noteOpenAnimation:Play();
    
    PlaySound('OpenNotebook');
    
    if HasGameState("BookLighting", "true") then    
        RemoveGameState("BookLighting", "true");
        SetHighlightingBookButton(false);
    end
end

function CloseNoteBook()

    if not panel.notebook.isOpen() then
        return;
    end
    
    PlaySound('CloseNotebook');
    
    panel.notebook.Close();
    
    local noteOpen = panel:GetObject('note_open');
    noteOpen:Show();
    local noteOpenAnimation = noteOpen:GetAnimation();
    noteOpenAnimation:SetMode(HGEANIM_REV + HGEANIM_NOLOOP);
    noteOpenAnimation:Play();
    
    TimerDoString("panel:GetObject('note_open'):Hide()", 1, panel:GetTimer())
end

-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData(screen)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Back.png',0,0,708,106,1,0)
	anim:SetHotSpot(354,53)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('background',anim,581,797,200,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/left.png',0,0,240,150,1,0)
	anim:SetHotSpot(120,75)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('left',anim,120,693,315,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/right.png',0,0,134,120,1,0)
	anim:SetHotSpot(67,60)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('right',anim,957,708,250,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/mechanism.png',0,0,292,98,6,30)
	anim:SetHotSpot(146,49)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('mechanism',anim,879,720,201,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Sand_glass.png',0,0,113,113,12,15)
	anim:SetHotSpot(56,56)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('button_r_hint',anim,955,700,317,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Sand_glass.png',0,0,113,113,12,15)
	anim:SetHotSpot(56,56)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('button_r_skip',anim,955,700,318,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/menu/menu.png',0,0,87,91,1,0)
	anim:SetHotSpot(43,45)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('button_menu',anim,71,692,317,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Hint/hint.png',0,0,62,62,1,0)
	anim:SetHotSpot(31,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('hint',anim,0,0,320,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Hint/hint.png',0,62,62,62,1,0)
	anim:SetHotSpot(31,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('hint_mouse_over',anim,0,0,320,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Hint/hint.png',0,124,62,62,1,0)
	anim:SetHotSpot(31,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('hint_mouse_pressed',anim,0,0,320,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Skip/skip.png',0,0,62,62,1,0)
	anim:SetHotSpot(31,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('skip',anim,0,0,100,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Skip/skip.png',0,62,62,62,1,0)
	anim:SetHotSpot(31,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('skip_mouse_over',anim,0,0,100,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Skip/skip.png',0,124,62,62,1,0)
	anim:SetHotSpot(31,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('skip_mouse_pressed',anim,0,0,100,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Menu/menu.png',0,0,87,91,1,0)
	anim:SetHotSpot(43,45)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('menu',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Menu/menu.png',0,91,87,91,1,0)
	anim:SetHotSpot(43,45)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('menu_mouse_over',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Menu/menu.png',0,182,87,91,1,0)
	anim:SetHotSpot(43,45)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('menu_mouse_pressed',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/dialog.png',0,0,1022,185,1,0)
	anim:SetHotSpot(511,92)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('background_comics',anim,512,683,200,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/Monolog_bg.png',0,0,708,111,1,0)
	anim:SetHotSpot(354,55)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('back_comics_monolog',anim,581,820,249,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/WheelRight.png',0,0,69,80,9,30)
	anim:SetHotSpot(35,40)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('WheelRight',anim,992,730,200,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/sand_glass_back.png',0,0,61,61,1,0)
	anim:SetHotSpot(30,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sand_glass_back',anim,956,699,315,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/sand_glass_fill.png',0,0,61,61,1,0)
	anim:SetHotSpot(30,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sand_glass_fill',anim,955,700,316,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/note.png',0,0,153,132,1,0)
	anim:SetHotSpot(76,61)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('note',anim,938,701,320,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/note.png',0,0,153,132,1,0)
	anim:SetHotSpot(76,61)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('note_not_over',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/note.png',0,132,153,132,1,0)
	anim:SetHotSpot(76,61)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('note_mouse_over',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/note.png',0,264,153,132,1,0)
	anim:SetHotSpot(76,61)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('note_mouse_pressed',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/note_open.png',0,0,153,132,8,12)
	anim:SetHotSpot(76,61)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('note_open',anim,938,701,325,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/notebook.png',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('notebook',anim,512,340,210,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/close.png',0,0,66,66,1,0)
	anim:SetHotSpot(33,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('notebook_close',anim,938,82,211,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/close.png',0,0,66,66,1,0)
	anim:SetHotSpot(33,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('notebook_close_not_over',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/close.png',0,66,66,66,1,0)
	anim:SetHotSpot(33,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('notebook_close_over',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/close.png',0,132,66,66,1,0)
	anim:SetHotSpot(33,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('notebook_close_pressed',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/BookLighting.png',0,0,110,128,8,0)
	anim:SetHotSpot(55,64)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BookLighting',anim,969,697,326,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/skroll_left.png',0,0,51,51,1,0)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('LScroll',anim,102,598,211,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/skroll_left.png',0,0,51,51,1,0)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('LScroll_not_over',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/skroll_left.png',0,51,51,51,1,0)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('LScroll_over',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/skroll_left.png',0,102,51,51,1,0)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('LScroll_pressed',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/skroll_right.png',0,0,51,51,1,0)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('RScroll',anim,931,592,211,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/skroll_right.png',0,0,51,51,1,0)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('RScroll_not_over',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/skroll_right.png',0,51,51,51,1,0)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('RScroll_over',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/NoteBook/skroll_right.png',0,102,51,51,1,0)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('RScroll_pressed',anim,0,0,1,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Panel/TimerActivationAnim.png',0,0,128,128,42,20)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('timer_activation_anim',anim,956,686,750,0,0.9,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
