function Timer(ncount, Param1)
	if not StopSheet then
		AlfingSheet();
		StopSheet=false;
	return;end;
return;end;

function SheetSwitched (ncount)
	StopSheet=true;
return;end;

function SelectRandom()
	if flags.loc2 then
		if not flags.loc1 then
		   selectrandomobject(1.5,64);
		return;end;
		selectrandomobject(1.5,65);
	return;end;	
	if flags.all then
		if not flags.minicomplete1 then
		    if flags.wkatulka then
				selectrandomobject(1.5,67);
			return;end;		
			if flags.boxkey then
				selectrandomobject(1.5,24);
			return;end;			
			if not flags.bedopen then
			   selectrandomobject(1.5,52);
			return;end;
			if flags.lock then
			   selectrandomobject(1.5,55);
			return;end;
			if not flags.open then
			if not flags.hook then 
			   selectrandomobject(1.5,51);
			 return;end; 
			 selectrandomobject(1.5,60);
			return;end;
			selectrandomobject(1.5,65);
		return;end;		
	return;end;
    idObject=GetRandomObject();	
	if idObject==123 and (not flags.minicomplete2) then
		if GetActivCount()>2 then
			flags.HintCount=flags.HintCount+1;
			SelectRandom()		
		return;end;		
		selectrandomobject(1.5,45);
	return;end	
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==123 and (not flags.minicomplete2) then	
		selectrandomobject(1.5,45);
	return;end	
	selectrandomobject(1.5,idObject);
end;


function MessageFromMenu(nCount,Param1)
if Param1==2000029 then
	ScrollLeft();
return;end;
if Param1==2000030 then
	ScrollRight();
return;end;
showoptons(0);
return;end;

function gameinput (sender,obj_id,attachedID)
	if sender == 2 then
		MessageProc(sender,obj_id);
	return;end;
	if sender==12 or sender==26 then
		if flags.loc2 then
		if not flags.whole_darkness then
		if not flags.allobject2 then
		    flags.allobject2=true;
			if flags.loc1 and flags.loc2 and flags.loc3 then
				flags.levelcomplete=true;
				DarkScreen(true);
				ShowMenu(false);
			return; end;	
			CreateWindow(100,100,"199");
		return;end;	
		return;end;	
		return;end;
	return;end;

	if sender==16 then
		if obj_id==503 or obj_id==500 then
		   BlockCursor(false);
		return;end;
		if obj_id==501 then
		   if flags.levelcomplete then	
			--	flags.whole_darkness=true;		   
				speciale_action(2,500,true,2);
				speciale_action(4,500);
				BlockCursor(true);
			return;end;
			BlockCursor(false);
		return;end;
		if obj_id==3 then
			CreateWindow(100,100,"196");
			BlockCursor(false);
		return;end;							
	return;end;
	
	if sender==15 then
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			if flags.minitext1 then
				if flags.loc1 and flags.loc2 and flags.loc3 then
					flags.levelcomplete=true;
					DarkScreen(true);
					ShowMenu(false);
				return; end;				
				CreateWindow(100,100,"199");
				flags.minitext1=false
			return;end;			
			if flags.loc2 then
			if not flags.allobject2 then
				flags.allobject2=true;
				if flags.loc1 and flags.loc2 and flags.loc3 then
					flags.levelcomplete=true;
					DarkScreen(true);
				return; end;	
				CreateWindow(100,100,"199");
			return;end;	
			return;end;			

		return;end;		
		if obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(24,"Box",0,0);
			StartEmiter("Box");
			MoveEmiter("Box",100,496);	
			AddParticleToObject(52,"Bed",0,0);
			StartEmiter("Bed");
			MoveEmiter("Bed",472,562)			
			AddParticleToObject(45,"Tumb",0,0);
			StartEmiter("Tumb");
			MoveEmiter("Tumb",132,574)	
			AddParticleToObject(51,"Hook",0,0);
			StartEmiter("Hook");
			MoveEmiter("Hook",519,64)
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 --кликнули левой кнопкой мыши на активный объект

		if obj_id==24 then  --шкатулка
		if not flags.minicomplete1 then
			if attachedID==111 then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");
				speciale_action(2,67,true);
				speciale_action(2,24,true)
				Set_Cursor(24,3);
				StopEmiter("Box");
				AddParticleToObject(67,"OpenBox",88,510);
				StartEmiter("OpenBox");
				MoveEmiter("OpenBox",82,510);					
				Set_Cursor(67,2);
				flags.wkatulka=true;
				--AddParticleToObject(67,"./particles/particle6.psi",47,479,103,503);
			return; end;
			if attachedID~=111 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"211");   
			return; end;
		return; end;		
		return;end;	

		if obj_id==52 then --разложенная кровать
			if flags.bed then
				if attachedID==215 or attachedID==249  then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
					Set_Cursor(52,3)
					StopEmiter("Bed");
					AddParticleToObject(55,"Zamok1",0,0);
					StartEmiter("Zamok1");
					MoveEmiter("Zamok1",631,576);						
					speciale_action(2,52,true);
					speciale_action(2,53,true);
					speciale_action(2,11,true);
					flags.bedopen=true;
				return; end;
				if attachedID~=215 and attachedID~=249 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"205");  
				return; end;
			return;end;
				if attachedID==215 or attachedID==249  then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
					flags.bed=true;
					--крепии пружину на кровать
				return; end;
				if attachedID~=215 and attachedID~=249 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"205");  
				return; end;
		return; end;	

		if obj_id==55 then  --люк
			if flags.lock then
				if attachedID==221 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
					Set_Cursor(55,3)
					speciale_action(2,55,true);
					flags.lock=false;
					StopEmiter("Zamok1");
				return; end;
				if attachedID~=221 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"206"); 
				return; end;	
			return; end;					
		return;end;
		
		if obj_id==57 then --люк без замка
			CreateWindow(100,100,"207"); 	
		return;end;			
		
		if obj_id==51 then  --крюк
		if flags.bedopen then
			if attachedID==254 then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");
				Set_Cursor(50,3)
				Set_Cursor(51,3)
				flags.hook=true;
				speciale_action(2,50,true);
				speciale_action(2,60,true);
				speciale_action(2,56,true);
				speciale_action(2,68,true);
				StopEmiter("Hook");
				AddParticleToObject(60,"Rope",0,0);
				StartEmiter("Rope");
				MoveEmiter("Rope",523,181);					
				Set_Cursor(60,4)
				--AddParticleToObject(60,"./particles/particle6.psi");
			return; end;
			if attachedID~=254 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"208");
			return; end;		
		return;end;
		CreateWindow(100,100,"209");
		return;end;		

		if obj_id==60 then  --конец верёвки
		if not flags.open then
		if not flags.lock then
			if attachedID==248 then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");
				Set_Cursor(50,3);
				StopEmiter("Rope");
				speciale_action(2,57,true);
				speciale_action(2,62,true);
				speciale_action(2,63,true);
				speciale_action(2,50,true);
				speciale_action(2,60,true);
				speciale_action(2,68,true);
				speciale_action(2,69,true);
				flags.open = true;
				Set_Cursor(65,1)
			return; end;
			if attachedID~=248 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"210");
			return; end;
		return; end;
		CreateWindow(100,100,"214");
		return; end;
		return;end;					
			
	if attachedID==-1 then			
		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","garage");
				delete_tree_leaf("Root","killer");
				delete_tree_leaf("Root","gym");
				delete_tree_leaf("Root","mini1");
				delete_tree_leaf("Root","mini2");
				delete_tree_leaf("Root","mini3");
				delete_tree_leaf("Root","mini");
				setnextlavel(15);
				loadlavel();	
				ShowMenu(false);
			return;end;	
			DarkScreen(false);
			speciale_action(2,503,true);
		return;end;			
		
		if obj_id==102 then
		    playeffect("boks");
			StartAnimation(102,0,8)
		return;end;
		
		if obj_id==103 then
		   StartAnimation(103,0,5)
		return;end;
		
		if obj_id==64 then
				setcurentleaf("garage",14,0);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;	
			
			if obj_id==65 then
				if flags.firstloc3==true then
					BlockCursor(true)
					setcurentleaf("gym",14,2);
					
					SwitchToSheet("re");
					flags.firstloc3 = false;
					DarkScreen(true);
					speciale_action(2,503,true);	
					speciale_action(4,503)					
				return; end;
				setcurentleaf("gym",14,2);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;
			


			if obj_id==67 then
			if not flags.minicomplete1 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini1",14,12);
				dofile("./data/14/12/res.lua");
				set_satelite_leaf("killer");
				dofile("data\\14\\12\\level.lua");
				mini_create();
				for i=1001,1021,1 do
					speciale_action(2,i,true)
				end;
			return;end;				
			return;end;
			
		

			if obj_id==45 then  --стол
			if not flags.minicomplete2 then 
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini2",14,13);
				dofile("./data/14/13/res.lua");
				set_satelite_leaf("killer");
				dofile("data\\14\\13\\level.lua");
				mini_create();	
				for i=1000,1005,1 do
					speciale_action(2,i,true)
				end;
			return; end;		
			return;end;	
			
			if obj_id==82 then  --газета
			if not flags.newspaper then
				flags.newspaper=true;
				Set_Cursor(82,3);
				--CreateWindow(100,100,"212");  
				speciale_action(2,87,true)

			return;end;	
			return;end;	

			if obj_id==87 then
				collaps_obj(82,0,0,10,1);	
				playeffect("collaps");				
				speciale_action(2,87)
				if flags.all and flags.minicomplete1 then
					CreateWindow(100,100,"199");
					flags.loc2 = true;
					if flags.loc1 and flags.loc2 and flags.loc3 then
					flags.levelcomplete=true;
					speciale_action(2,501,true,2);
					return; end;				
				return;end;
			return;end;
			if obj_id==249 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
			return; end;
			
			if obj_id==123 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"213"); 
			return; end;
			
			if obj_id==221 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
			return; end;
			
			if obj_id==254 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
			return; end;	

			if obj_id==248 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
			return; end;
			
			if obj_id==215 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				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 < 71 then --кликаем на активный объект
				playeffect("collaps");
		        collaps_obj(obj_id,0,0,10,1);
	        return 0; end
	return; end;		
	return; end;
	if sender==14 then
	StopSheet=true;
		if obj_id>0 then
			addObjectToMouse(obj_id);
		return; end;
	return; end;
	
	if sender==4 then
	if SLevel==1.0 then return;end;
		flags.all=true;
		
		if flags.newspaper and flags.minicomplete1 then
			flags.loc2 = true;
		return; end;
	return; end;		
end
