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

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

function SelectRandom()
	if not flags.inv then
		selectrandomobject(1.5,9);
	return;end;
	if not flags.minicomplete then
		selectrandomobject(1.5,21);
	return;end;
	if not flags.minicomplete1 then
		selectrandomobject(1.5,14);
	return;end;
	if not flags.minicomplete2 then
		selectrandomobject(1.5,19);
	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==26 then
		if obj_id==1 then
			if flags.minicomplete and flags.minicomplete1 and flags.minicomplete2 then
			    flags.levelcomplete=true;
				ShowMenu(false);
				DarkScreen(true);

			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
				speciale_action(2,500,true,2);
				speciale_action(4,500);
				BlockCursor(true);
			return;end;
		return;end;
		if obj_id==21 then
			BlockCursor(false);
			CreateWindow(100,100,"198")
		return;end;		
	return;end;
	
	if sender==15 then
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;

			if flags.minitext2 then			    
				CreateWindow(100,100,"201",1);
				flags.minitext2=false;
				savegame(SaveLevel())
			return;end;			
			if flags.minitext1 then
				CreateWindow(100,100,"203",1);
			   flags.minitext1=false;
			   savegame(SaveLevel())
			return;end;

			if flags.minitext3 then
				CreateWindow(100,100,"202",1);
				flags.minitext3=false;
				savegame(SaveLevel())
			return;end;
		return;end;
		
		if obj_id==503 then
			BlockCursor(false);
			ShowMenu(true);
			AddParticleToObject(9,"Svet5",0,0);
			StartEmiter("Svet5");
			MoveEmiter("Svet5",213,474);		
			StartLevel();
		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==21 then
			if not flags.minicomplete then
				if attachedID==103 or flags.minirun1 then
					playeffect("mini");		
				   	RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					Set_Cursor(21,2)					
					DarkScreen(true);
					add_free_leaf("Root","mini",2,11);
					dofile("./data/2/11/res.lua");
					set_satelite_leaf("photolab");
					dofile("data\\2\\11\\level.lua");
					mini_create();
					speciale_action(2,1000,true)
					speciale_action(2,1003,true)
					speciale_action(2,1004,true)
					speciale_action(2,1006,true)
					speciale_action(2,1009,true)
					speciale_action(2,1010,true)
					speciale_action(2,1014,true)
					speciale_action(2,1015,true)
					speciale_action(2,1016,true)
					speciale_action(2,1017,true)
				return; end;	
				if (attachedID ~= 103) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"206");
				return; end;				
			return; end;	
			return; end;

			if obj_id==19 then
			if not flags.minicomplete2 then
				if attachedID==101 or flags.minirun3 then					
					playeffect("mini");	
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					Set_Cursor(19,2)
					DarkScreen(true);								
					add_free_leaf("Root","mini2",2,13);
					dofile("./data/2/13/res.lua");
					set_satelite_leaf("photolab");
					dofile("data\\2\\13\\level.lua");
					mini_create();
					for i=1000,1003 do
						speciale_action(2,i,true)
					end;
				return; end;				
				if (attachedID ~= 101)  and  (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"208");
				return; end;					
			return;end;
			return;end;
			
			if obj_id==14 then
			if not flags.minicomplete1 then
				if attachedID==102 or flags.minirun2 then
					playeffect("mini");	
					RemoveFromMouse(attachedID);
					DeleteElement("gr",102);
					Set_Cursor(14,2)					
					DarkScreen(true);
					add_free_leaf("Root","mini1",2,12);-- Добавляет чистый лист
					dofile("./data/2/12/res.lua");
					set_satelite_leaf("photolab");
					dofile("data\\2\\12\\level.lua");
					mini_create();					
					for i=1000,1004 do
						speciale_action(2,i,true)
					end;
				return; end;
				if (attachedID ~= 102) and  (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"207");
				return; end;					
			return; end;	
			return; end;	
	
		if attachedID==-1 then		

			
			if obj_id==501 then
				if flags.levelcomplete then
					delete_tree_leaf("Root","kabinet");
					delete_tree_leaf("Root","photolab")
					delete_tree_leaf("Root","mini");
					delete_tree_leaf("Root","mini1");
					delete_tree_leaf("Root","mini2");
					delete_tree_leaf("Root","comics");
					setnextlavel(23);
					loadlavel();
				return;end;		
				DarkScreen(false);
				speciale_action(2,503,true);
				speciale_action(4,503)
			return;end;

			if obj_id==9 then
				if not flags.caseopen then
					playeffect("caseopen");
					Set_Cursor(9,3);
					speciale_action(2,9,true);
					speciale_action(2,10,true);
					Set_Cursor(10,2);
					speciale_action(2,105)
					flags.caseopen=true;
				    Set_Cursor(10,3);
					AddElement("gr",101);
					MoveObjectToTree(101); 
					AddElement("gr",102);
					MoveObjectToTree(102); 
					AddElement("gr",103);
					MoveObjectToTree(103); 
					flags.inv=true;		
					StopEmiter("Svet3");
					AddParticleToObject(21,"Svet1",0,0);
					AddParticleToObject(19,"Svet",0,0);
					AddParticleToObject(14,"Svet2",0,0);
					StartEmiter("Svet");
					StartEmiter("Svet1");
					StartEmiter("Svet2");
					MoveEmiter("Svet1",317,415);
					MoveEmiter("Svet",589,446);
					MoveEmiter("Svet2",430,420);					
				return;end;
			return;end;

			if obj_id==10 then
				if not flags.inv then
				return;end;
			return;end;			
			


			
			if obj_id==100 then
				CreateWindow(100,100,"201");
			return; end;	
			
			if obj_id==1 then
				CreateWindow(100,100,"202");
			return; end;

			if obj_id==30 then
				CreateWindow(100,100,"203");
			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
