-- SetWindowText(tostring(flags.comx1))
function Timer(ncount, Param1)
     if not StopSheet then
          AlfingSheet();
          StopSheet=false;
     return;end;
return;end;
function SheetSwitched (ncount)
     StopSheet=true;
return;end;
function gameinput (sender,obj_id,attachedID)
-----------------------------------------------------------------------------------------------------------------------
	if sender == 2 then
		RemoveFromMouse(object);
		MessageProc(sender,obj_id);
	return;end;
	if sender == 100 then
	if flags.comx then
		speciale_action(2,12121);
		add_free_leaf("gorod",0,50);
		set_satelite_leaf("kabinet");
		DoFile(0,50)
		flags.comx= false;

		flags.comx1= true;
				-- WriteToConsole("comx1lev = ".." "..tostring(flags.comx1).."\n")
	return;end;
	return;end;

	if sender==12 then
	

		if obj_id==36 then
			CreateWindow(150,250,"204",1,nil,250,30); 

			--playeffect("01");
		return;end;
		if obj_id==31 then
		 	CreateWindow(150,250,"229",nil,nil,250,30); 
			--playeffect("01");
			flags.key=true;
		return;end;
		if obj_id==20 then
		 	CreateWindow(150,250,"228",4,nil,250,30); 
			--playeffect("01");
			speciale_action(2,107)
			flags.kyky= true;
			flags.dalee=true;
			flags.seif= false;
		return;end;	
		if last_id==obj_id then
		if obj_id==35 then
			    AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id);
		end;	
		if obj_id==102 then
			    AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id);
				flags.card=true;
		
		end;
			if flags.object then
			CreateWindow(150,250,"223",nil,nil,250,20);
			--playeffect("01");
			flags.object= false;	
		return;end;
		return;end;
	return;end;
if sender==35 then
	if obj_id==631 then
		StartAnimation(631,0,3)
	return; end;
	if obj_id==270 then
		StartAnimation(270,0,3)
	return; end;
return;end;
if sender==15 then
	if obj_id==700 then
		CreateWindow(150,250,"230",nil,nil,250,30); 
		--playeffect("01");
	return; end;
return;end;
	if sender==26 then
		if obj_id==9 then
			speciale_action(2,105)
			StartAnimation(105);
			flags.strelka1 =true;
			StartTimer(852,2)
			BlockCursor(true)
			savegame(SaveLevel());
		return;end;
		if obj_id==10 then
			speciale_action(2,105)
			StartAnimation(105);
			flags.strelka1 =true;
			savegame(SaveLevel());
		return;end;
		if obj_id==1 then
			CreateWindow(150,250,"231",9,nil,250,30); 
           --playeffect("01");		   
		return;end;
		if obj_id==2 then
		speciale_action(2,106)
		StartAnimation(106);
		flags.strelka2 =true;
		 flags.case2 =true;
		savegame(SaveLevel());
		return;end;
		if obj_id==3 then
		setcolor(20,1,0,0,1,1);
		SwitchToSheet("re");
		CreateWindow(150,250,"227",nil,nil,250,30);
		--playeffect("01");
		 speciale_action(2,107)
		  StartAnimation(107);
		  flags.strelka3 =true;
		  savegame(SaveLevel());
		return;end;	
		if obj_id==4 then
			speciale_action(2,108)
			StartAnimation(108);
			flags.strelka4 =true;
			-- setcolor(31,1,0,0,1,1);
			savegame(SaveLevel());
		return;end;		
		return;end;
	if sender==33 then
		BlockCursor(false);
		if obj_id==501 then -- тёмная плашка
			BlockCursor(false);
			if whole_darkness then
			   if flags.levelcomplete then
					SetAlfa(500,0,1,0.1);
					speciale_action(4,500,true);
					BlockCursor(true);
				return;end;			
			   --затемнилось
			return;end;
			whole_darkness=false;
			CreateWindow(150,250,"198",nil,nil,250,20);
			--playeffect("01");
			   -- растемнилось
			AddParticleToObject(65,"Svet",355,379);
			MoveEmiter("Svet",355,379);
			if not flags.minicomplete then
			StartEmiter("Svet"); 
			end;
			AddParticleToObject(59,"zvezd",952,50);
			MoveEmiter("zvezd",952,50);
			StartEmiter("zvezd"); 
		return;end;	   
		if obj_id==503 then --название levовня
		    BlockCursor(false);
			if whole_darkness then
			   --затемнилось
			return;end;			
			-- проявление меню вывод собщений в начале levовня ----
			ShowMenu(true);
			savegame(SaveLevel());
		return;end;
	return;end;
	if pause_state then
		if sender==1 or sender==6 or sender==14 then
			pause_state=false;
			--set_visible_object(11111,false);
		end;	
	return;end;
	if sender == 1 then --кликнули левой кнопкой мыши на активный объект
	last_id=obj_id;
			if obj_id==700 then			
				speciale_action(2,700,true);
			return; end;
	if flags.dalee and flags.podskazka then
	if obj_id==31 then
		playeffect("20");
		collaps_obj(obj_id,0,0,10,1);
		 speciale_action(2,108)
		flags.dalee2=true;
		flags.o4ki=true;
		flags.dalee=false;
		flags.podskazka=false;
	return; end;
	return; end;
			if obj_id==501 then
				if flags.levelcomplete then
					delete_tree_leaf("Root","kabinet");-- Добавляет лист в дерево 
					setnextlavel(22);
					loadlavel();
				return;end;				
				    DarkScreen(false);
				    whole_darkness=false;
					SetAlfa(503,1,0,1);
			return;end;

	    if obj_id==36 then
				SetCurrentRM("menu");
				loadresource("data\\buttons_sheets.png","buttons_sheets",0000000000000);
				addstaticobjecttogame(777777777,"buttons_sheets",75,698,"",0,0,61,61);        
				AddSheet(1001,"gr","green_b",108,705,34,37,"green",185,675,650,60,11,11,15,13,1,48,777777777,10,"buttonsX");
				SetCurrentRM("main");	
				collaps_obj(obj_id,0,0,10,1);
				playeffect("20");
				speciale_action(2,36);
				Set_Cursor(65,2);
				flags.case = true;
		return; end;	
		
       if not flags.case and not flags.photo then
	   CreateWindow(200,300,"200",nil,nil,250,30);
	   --playeffect("01");
       else 
	   if flags.dalee2 then			
			if obj_id==102 then
				speciale_action(2,700,true);
				collaps_obj(obj_id,0,0,10,0);
				playeffect("paper");

			return; end;
		if obj_id==59 then
			if attachedID==35 then
				if (not flags.doorisopen) then
				RemoveFromMouse(object);
					CreateWindow(150,250,"201",nil,nil,250,30);   
					--playeffect("01");
				return;end; 
				if flags.doorisopen and flags.minicomplete then
					RemoveFromMouse(attachedID);
					SetAlfaSheet(2.0)
					DeleteElement("gr",attachedID);
					flags.levelcomplete=true;
					DarkScreen(true);
					ShowMenu(false)
					playeffect("door");
				return;end;		
			return;end;		
			 if (attachedID>-1) and (attachedID~=35) then
			 RemoveFromMouse(object);
			    CreateWindow(150,250,"202",nil,nil,250,30);
				--playeffect("01");
			 return;end;
			 if (attachedID==-1)  then
			    CreateWindow(150,250,"203",nil,nil,250,30);
				--playeffect("01");
			 return;end;
			return;end;						
			if obj_id==35 then
			    collaps_obj(obj_id,0,0,10,0);
				playeffect("20");
			    -- AddElement("gr",obj_id);
				-- SetAlfaSheet(2.5)
				-- setcolor(obj_id,0,0,0,0.5,1);
				-- MoveObjectToTree(obj_id);
			return; end;						
			if obj_id > 0 and obj_id < 104 or obj_id==177 then --кликаем на активный объект
				if obj_id ~= 65 then
					playeffect("20");
					collaps_obj(obj_id,0,0,10,1);
				return 0; end
	        return 0; end
		return; end;	
   	     
			if attachedID==-1 then			
				if obj_id==65 then
				flags.comend=false;
					if not flags.minicomplete and flags.case2 then						
						playeffect("29");	
						add_free_leaf("Root","mini",0,11);-- Добавляет чистый лист
						set_satelite_leaf("kabinet");
						DoFile(0,11)
						if not flags.proideno then
						mini_create();
						return; end;
						flags.nohints=true;
					return; end;
				return; end;
				if flags.seif then
					if obj_id==20 then
						playeffect("20");
						collaps_obj(obj_id,0,0,10,1);
						setcolor(obj_id,0,0,0,1,1);

					return; end;
				return; end;
			return; end;
		return; end;
	
	return; end;
     if sender==36 then          
          if obj_id==9999 then
               if not StopSheet then
                    AlfingSheet();
                    StopSheet=false;
               return;end;
          return;end;
          if obj_id==852 then
			speciale_action(2,105)
		   CreateWindow(150,250,"225",2,nil,250,30);
			--playeffect("01");
			flags.photo=true;
			BlockCursor(false)
          return;end;                    
     return;end;
	if sender==14 then
		if obj_id>0 then
		StopSheet=true;
			object=obj_id
			addObjectToMouse(obj_id);
		return; end;	
	return; end;		
-----------------------------------------------На сцене отработали все объекты-------------------------
	if sender==4 then
	flags.object= true;
        flags.doorisopen=true;
	return; end;	
------------------------------------------------------------------------------------------------------------------	
end
function SelectRandom()
	if  flags.kyky and not flags.o4ki then
		if not flags.doorisopen then
			selectrandomobject(1.5,31);
			flags.podskazka= true;
		return;end;
	return;end;
	if flags.doorisopen then
		selectrandomobject(1.5,59);
	return;end;
		idObject=GetRandomObject();
	selectrandomobject(1.5,idObject);
end;
function SelectRandomRadar(idObject)
	
		if idObject==22 then
	    selectrandomobject(1.5,65);
	return;end;
	selectrandomobject(1.5,idObject);
end;
