-- 5 массивов
-- placeX,placeY - где находится слово
-- place_okX, place_okY - где должно находиться слово
-- on_place - на своём ли месте слово


skip = false;
local first = true;

function Buttons_T(sender,id)
   ButtonTreatment(id,10001,10002,10003,CloseBtnX,CloseBtnY,CloseWidth,CloseHeight,sender,"laborator",true)
   ButtonTreatment(id,10021,10022,10023,HelpBtnX,HelpBtnY,HelpWidth,HelpHeight,sender,"laborator",true,293,200,200)
   if skip then
    ButtonTreatment(id,10011,10012,10013,SkipBtnX,SkipBtnY,111,31,sender,"laborator",true)
   end;
end;

function SkipActions()
    for i=1050,1059,1 do
        SetObjectPosition(i,place_okX[i],place_okY[i])
        setcolor(i,1,1,1,1);
    end;
    playeffect("miniok")
    skip=false
    HideHelp()
    set_text(2002,"1012")    
    speciale_action(2,10011)
    StartTimer(88810,0.5);
    finish_mini_game(true);
end;

function mini_create ()
    show_help_wnd=true;
    init_mini(true);
    create_mini(8128);
    StartTimer(88821,0.3)
end;
function gameinput (sender,id,attachedID)
 CursorTreatment(id,sender,attachedID);
 Buttons_T(sender,id)
   
  if sender == 100 then
    StartTimer(88811,0.3);
  return; end;

  if sender==35 then
    if activ[id] and clkobj~=lastobject    then
    errorgame=false
        for i=1050,1059,1 do
            if podsv[i] then        
                errorgame =true;    
            end; 
        end;  
        if not errorgame then
            podsv[id]=true
            setcolor(id,1,0.3,0.3,0.7);
            lastobject=id
        return;end;
    return;end;
  return;end;

  if sender==39 then
     if clkobj~=lastobject and activ[lastobject] then
      if podsv[lastobject] then        
        setcolor(lastobject,1,1,1,0.5);
        podsv[lastobject]=false
     end;  
end;     
  return;end;
  
  if sender == 36 then       
    if id == 88811 then
      Block_Show_Cur(false);
      CreatePlashechka(900000,"293")
    return; end;

    if id == 88810 then
        Block_Show_Cur(false)
        flags.john_day_book = true;
    return; end;
  return; end;
  
  if sender == 30 then  
      DeleteResource("john_day_book_0000");
      DeleteResource("john_day_book_0001");
      DeleteResource("john_day_book_0002");      
    setcurentleaf("laborator",2,0);          
    Block_Show_Cur(false);    
    if flags.john_day_book then
      UnStoreObj(obj.jhndk.id);
      CreatePlashechka(900000,"292")
      speciale_action(2,16);
      Set_Anim_Cur(16,2);
    AddParticleToObject(16,"p1",338,244);
    MoveEmiter("p1",338,244);
    StartEmiter("p1");        
      IfTableClose()
    end;
  return; end;
  
  if sender==37 then
    skip = true;
  return;end;

  if sender==14 then
    AddObjToMouse(id)
  return; end;
  
  if sender == 10 then    
    playeffect("miniok")
    skip=false
    HideHelp()
    set_text(2002,"1012")    
    speciale_action(2,10011) 
    StartTimer(88810,0.5);
  return; end;
   if sender==44 then
    AboutItem(obj_id)
  return;end; 
  if sender == 6  then
      if flags.john_day_book then    
        clear_satelite_leaf("laborator");
      return;end;      
  return;end;
  if sender == 1 then   
  
       if attachedID ~= -1 then
        RemObjFromMouse()
      end;   

    if    id >= 1050 and id <= 1059 and not flags.john_day_book then
      if first then
        xx1,yy1=GetObjectPosition(id);
        obj1=id;
        setcolor(id,1,1,1,0.8);
        clkobj=id
        first=false;
      return;end;
      xx2,yy2=GetObjectPosition(id);
      obj2=id;
      clkobj=0
      first=true;                              
      SetObjectPosition(obj2,xx1,yy1);
      SetObjectPosition(obj1,xx2,yy2);
      playeffect("btn1")
      if xx1 == place_okX[obj2] and yy1 == place_okY[obj2] then
        on_place[obj2] = true;
        setcolor(obj2,1,1,1,1);
        ActivateObject(obj2,false);
        activ[obj2]=false
       -- Set_Anim_Cur(obj2,false)
      else
        setcolor(obj2,1,1,1,0.5);
        set_pixel_check(obj2,false);
       -- Set_Anim_Cur(obj2,4)
        OnMouseOver(obj2,true)
        podsv[obj2]=false
        activ[obj2]=true             
      end;     
      if xx2 == place_okX[obj1] and yy2 == place_okY[obj1] then
        on_place[obj1] = true;
        setcolor(obj1,1,1,1,1);
        ActivateObject(obj1,false);
        activ[obj1]=false
     --   Set_Anim_Cur(obj1,false)
      else
        setcolor(obj1,1,1,1,0.5);
        set_pixel_check(obj1,false);
      --  Set_Anim_Cur(obj1,4)
        OnMouseOver(obj1,true)
        podsv[obj1]=false
        activ[obj1]=true             
      end;     
      is_error=false;     
      for i = 1050, 1059, 1 do
         if not on_place[i] then
           is_error = true;
         end;            
      end;          
      if not is_error then 
        BlockCursor(true)
        finish_mini_game(true)
      end;     
    return; end;
  return; end;
end;

function mini_delete ()

end;
function SheetSwitched(nCount)
end;