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 not flags.inv then
		selectrandomobject(1.5,9);
	return;end;
	if not flags.minicomplete then
		if flags.handle and not flags.glass_in then
			selectrandomobject(1.5,30);
		return;end;
		selectrandomobject(1.5,27);		
	return;end;
	if not flags.minicomplete1 then
		if flags.ashes and not flags.ash_in then
		   selectrandomobject(1.5,40);
		return;end;
		if not flags.sig_in then
			selectrandomobject(1.5,34);
		return;end;
		selectrandomobject(1.5,14);
	return;end;
	if not flags.minicomplete2 then
		selectrandomobject(1.5,23);
	return;end;	
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==16 then
		if obj_id==503 or obj_id==500 then
		   BlockCursor(false);
		return;end;
		if obj_id==501 then
		   if flags.levelcomplete then		        
				speciale_action(2,500,true,2);
				speciale_action(4,500);
				BlockCursor(true);	
			return;end;
			BlockCursor(false);
		return;end;
		if obj_id==19 then
			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
				CreateWindow(100,100,"201",1);
				flags.minitext1=false;
				savegame(SaveLevel())
			end;
			if flags.minitext2 then
			    CreateWindow(100,100,"202",1);
				flags.minitext2=false;
				savegame(SaveLevel())
			end;
			if flags.minitext3 then
				CreateWindow(100,100,"203",1);
				flags.minitext3=false;
				savegame(SaveLevel())
			end;			
		return;end;	
		
		if obj_id==503 then
		   BlockCursor(false);
		   ShowMenu(true);
			AddParticleToObject(37,"water",0,0,0,0);
			AddParticleToObject(35,"probirka_b",0,0,0,0);
			AddParticleToObject(36,"probirka_y",0,0,0,0);
			AddParticleToObject(41,"banka",0,0,0,0);			
			StartEmiter("water");
			MoveEmiter("water",126,391);			
			StartEmiter("probirka_b");
			MoveEmiter("probirka_b",202,283);
			StartEmiter("probirka_y");
			MoveEmiter("probirka_y",365,183);
			StartEmiter("banka");
			MoveEmiter("banka",400,189);	
			AddParticleToObject(9,"Bag",0,0);
			StartEmiter("Bag");
			MoveEmiter("Bag",213,474);	
		savegame(SaveLevel())			
		return;end;
	return;end;		
	
	if sender==26 then
		if obj_id==1 then
			if flags.minicomplete and flags.minicomplete1 and flags.minicomplete2 then
				flags.levelcomplete=true;
				DarkScreen(true);
				ShowMenu(false);
			return; end;	
		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==27 then
			if not flags.minicomplete then
			if not flags.handle then 
				if attachedID==101 or attachedID==106 then
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					playeffect("attach");
					flags.handle=true;
					CreateWindow(100,100,"214");
				return; end;	
				if (attachedID ~= 101) and (attachedID ~= 106) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"211");
				return; end;
			return;end;	
				if attachedID==106 or attachedID==101 or flags.minirun1  then
				   	RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					playeffect("mini");	
					Set_Cursor(27,2)									
					DarkScreen(true);		
					add_free_leaf("Root","mini",4,11);-- Добавляет чистый лист
					dofile("./data/4/11/res.lua");
					set_satelite_leaf("photolab");
					dofile("data\\4\\11\\level.lua");
					mini_create();
					speciale_action(2,1000,true)
					speciale_action(2,1003,true)
					speciale_action(2,1004,true)
					speciale_action(2,1007,true)
					speciale_action(2,1008,true)
					speciale_action(2,1009,true)
				return; end;	
				if (attachedID ~= 106) and (attachedID ~= 101) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"214");
				return; end;
			return;end;
			return;end;

			if obj_id==34 then
			if not flags.minicomplete1 then
				if attachedID==102 then
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					playeffect("attach");
					AddElement("gr",104);
					MoveObjectToTree(104);
					flags.sig_in=true;
					StopEmiter("Sigin");
				return; end;
				if (attachedID ~= 103) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"212");
				return; end;				
			return; end;	
			return; end;
			
			if obj_id==14 then
			if not flags.minicomplete1  then
			if not flags.ashes then
				if attachedID==104 or attachedID==105  then
				   	RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					playeffect("attach");
					flags.ashes=true;
					CreateWindow(100,100,"214");
				return; end;	
				if (attachedID ~= 104) and (attachedID ~= 105) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"207");
				return; end;				
			return; end;
				if attachedID==104 or attachedID==105 or flags.minirun2 then
				   	RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					playeffect("mini");						
					Set_Cursor(14,2)				
					DarkScreen(true);
					add_free_leaf("Root","mini1",4,12);-- Добавляет чистый лист
					dofile("./data/4/12/res.lua");
					set_satelite_leaf("photolab");
					dofile("data\\4\\12\\level.lua");
					mini_create();
					for i=1000,1004,1 do
						speciale_action(2,i,true)
					end;
				return; end;	
				if (attachedID ~= 104) and (attachedID ~= 105) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"214");
				return; end;			
			return; end;
			return; end;
			
			if obj_id==23 then
			if not flags.minicomplete2 then
				if attachedID==103 or flags.minirun3 then
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					playeffect("mini");	
					Set_Cursor(23,2)
					DarkScreen(true);
					add_free_leaf("Root","mini2",4,13);-- Добавляет чистый лист
					dofile("./data/4/13/res.lua");
					set_satelite_leaf("photolab");
					dofile("data\\4\\13\\level.lua");
					mini_create();
					for i=1001,1023,1 do
						speciale_action(2,i,true)
					end;
				return; end;			
				if (attachedID ~= 103) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"213");
				return; end;					
			return; end;	
			return; end;


		if attachedID==-1 then	
	
			if obj_id==501 then
				if flags.levelcomplete then
					delete_tree_leaf("Root","photolab")
					delete_tree_leaf("Root","mini");
					delete_tree_leaf("Root","mini1");
					delete_tree_leaf("Root","mini2");
					setnextlavel(24);
					loadlavel();
				return;end;		
				DarkScreen(false);
				speciale_action(2,503,true);
			return;end;

			if obj_id==9 then
				if not flags.caseopen then
					flags.inv=true;
					playeffect("caseopen");
					Set_Cursor(9,3);
					speciale_action(2,9,true);
					AddElement("gr",101);
					AddElement("gr",102);
					AddElement("gr",103);
					MoveObjectToTree(101);
					MoveObjectToTree(102);
					MoveObjectToTree(103);
					speciale_action(2,10,true);
					flags.caseopen=true;
					AddParticleToObject(27,"Powder",0,0);
					AddParticleToObject(19,"Book",0,0);
					AddParticleToObject(23,"Micro",0,0);
					AddParticleToObject(30,"Glass",0,0);
					AddParticleToObject(40,"Ash",0,0);		
					AddParticleToObject(34,"Sigin",0,0);						
					StartEmiter("Powder");
					StartEmiter("Book");
					StartEmiter("Micro");
					StartEmiter("Glass");
					StartEmiter("Ash");		
					StartEmiter("Sigin");					
					MoveEmiter("Powder",588,358);
					MoveEmiter("Book",600,426);
					MoveEmiter("Micro",430,420);	
					MoveEmiter("Glass",61,417);
					MoveEmiter("Ash",685,211);		
					MoveEmiter("Sigin",568,415);					
				return;end;
			return;end;

			if obj_id==10 then
			return;end;		
			

			

			
			if obj_id==100 then
				CreateWindow(100,100,"208");
			return; end;	
			
			if obj_id==1 then
				CreateWindow(100,100,"209");
			return; end;

			if obj_id==30 then
			if not flags.minicomplete then
				StopEmiter("Glass")
				AddElement("gr",106);
				speciale_action(2,30);	
				StopParticleSystem(30);
				flags.glass_in=true;
			return; end;	
			CreateWindow(100,100,"210");			
			return; end;			

			if obj_id==2 then
				CreateWindow(100,100,"202");
			return; end;	
			
			if obj_id==8 then
				CreateWindow(100,100,"203");
			return; end;
			
			if obj_id==42 then
				CreateWindow(100,100,"201");
			return; end;

			if obj_id==40 then
			 if not flags.minicomplete1 then
			    StopEmiter("Ash")
				AddElement("gr",105);
				Set_Cursor(40,3)
				speciale_action(2,40);
				flags.ash_in=true;
			 return;end;
				CreateWindow(100,100,"217");
			return; end;
			
			if obj_id > 0 and obj_id < 57 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		

	return; end;	
end
