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.lock then
		    selectrandomobject(1.5,48);
		return;end;
		if not flags.loc1 then
		    selectrandomobject(1.5,51);
		return;end;	
		selectrandomobject(1.5,50);
	return;end;	
    idObject=GetRandomObject();
	if idObject==218 or idObject==219 or idObject==1018 or idObject==1019 then
		if not flags.lamp then
		   selectrandomobject(1.5,45);
		return;end;
	    selectrandomobject(1.5,42);
	return;end;	
	if (idObject==226 or idObject==231) and (not flags.minicomplete4) then
	    selectrandomobject(1.5,53);
	return;end;			
	if idObject==227 or idObject==1027 then
	    selectrandomobject(1.5,37);
	return;end;		
	if (idObject==228 or idObject==1028) and (not flags.minicomplete5) then
	    selectrandomobject(1.5,29);
	return;end;			
	if idObject==1028 then
	    selectrandomobject(1.5,228);
	return;end;
	if idObject==1038 then
	    selectrandomobject(1.5,238);
	return;end;
	if idObject==1043 then
	    selectrandomobject(1.5,243);
	return;end;	
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==218 or idObject==219 or idObject==1018 or idObject==1019 then
		if not flags.lamp then
		   selectrandomobject(1.5,45);
		return;end;
	    selectrandomobject(1.5,42);
	return;end;	
	if (idObject==226 or idObject==231) and (not flags.minicomplete4) then
	    selectrandomobject(1.5,53);
	return;end;			
	if idObject==227 or idObject==1027 then
	    selectrandomobject(1.5,37);
	return;end;		
	if (idObject==228 or idObject==1028) and (not flags.minicomplete5) then
	    selectrandomobject(1.5,29);
	return;end;			
	if idObject==1028 then
	    selectrandomobject(1.5,228);
	return;end;
	if idObject==1038 then
	    selectrandomobject(1.5,238);
	return;end;
	if idObject==1043 then
	    selectrandomobject(1.5,243);
	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		        
				speciale_action(2,500,true,2);
				speciale_action(4,500);
				BlockCursor(true);
			return;end;
			BlockCursor(false);
		return;end;
		if obj_id==4 then
			BlockCursor(false);
		return;end;			
	return;end;
	
	if sender==15 then
	
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			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);
					ShowMenu(false);
				return; end;
				CreateWindow(100,100,"199");
			return;end;	
			return;end;		
			if flags.minitext1 then
				CreateWindow(100,100,"10");
				flags.minitext1=false;
				savegame(SaveLevel())
			end;			
		return;end;		
		if obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(48,"Zamok",81,93);
			AddParticleToObject(29,"Bottle",762,622);
			AddParticleToObject(37,"Urna1",544,513);	
			AddParticleToObject(45,"LampOn",721,94);	
			AddParticleToObject(53,"Prov",609,381);			
			StartEmiter("Zamok");
			StartEmiter("Bottle");
			StartEmiter("Urna1");	
			StartEmiter("LampOn");
			StartEmiter("Prov");			
			MoveEmiter("Zamok",81,93);
			MoveEmiter("Bottle",762,622);
			MoveEmiter("Urna1",544,513);	
			MoveEmiter("LampOn",721,94);
			MoveEmiter("Prov",609,381);		
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==45 then 
			if attachedID==1043 then 
				playeffect("attach");			
				RemoveFromMouse(attachedID);				
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				Set_Cursor(44,3);
				speciale_action(2,42,true);
				speciale_action(2,142,true);
				speciale_action(2,44,true);
				speciale_action(2,45,true);
				speciale_action(2,145,true);
				Set_Cursor(42,2);
				StopEmiter("LampOn");
				AddParticleToObject(42,"Lamp",0,0);
				StartEmiter("Lamp");
				MoveEmiter("Lamp",705,276);					
				flags.lamp=true;
			return; end;
			if attachedID~=1043 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"207");  
			return; end;
		return; end;

		if obj_id==48 then
		if attachedID==107  then
			playeffect("attach");
			RemoveFromMouse(attachedID);
			DeleteElement("gr",attachedID);
			SetAlfaSheet(2.0)
			Set_Cursor(48,3);
			StopEmiter("Zamok");
			flags.lock=true;
			speciale_action(2,48,true);
			speciale_action(2,49,true);
			speciale_action(2,50,true);
			Set_Cursor(50,1);
		return;end;	
		if attachedID~=107 and attachedID>-1 then
			CreateWindow(100,100,"200");     
		return; end;
		if attachedID ==-1 then		
			CreateWindow(100,100,"204");
		return; end;
		return;end;
		
		if obj_id==42 then
		if attachedID==-1 or attachedID==106 or attachedID==1033 or attachedID==1038 then	
			if not flags.minicomplete3 then
				RemoveFromMouse(attachedID);
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini3",5,14);
				dofile("./data/5/14/res.lua");
				set_satelite_leaf("photo");
				dofile("data\\5\\14\\level.lua");
				mini_create();
				speciale_action(2,7,true)
				speciale_action(2,8,true)
				speciale_action(2,9,true)
				speciale_action(2,12,true)
				speciale_action(2,13,true)
				speciale_action(2,15,true)
				speciale_action(2,3,true)
				speciale_action(2,4,true)
				speciale_action(2,5,true)
				speciale_action(2,6,true)
				speciale_action(2,11,true)
			return; end;
		return; end;
		return; end;			

		if obj_id==53 then
		if attachedID==-1 or attachedID==1018 or attachedID==1019 or attachedID==1027 or attachedID==1028 then	
		if not flags.minicomplete4 then
				RemoveFromMouse(attachedID);
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini4",5,15);
				dofile("./data/5/15/res.lua");
				set_satelite_leaf("photo");
				dofile("data\\5\\15\\level.lua");
				mini_create();
				speciale_action(2,1,true);
				speciale_action(2,2,true);
				speciale_action(2,0,true);
				speciale_action(2,7,true);
				speciale_action(2,8,true);
		return; end;
		return; end;
		return; end;
		
		
		if attachedID==-1 then	
		
		if obj_id==201 then
			StartAnimation(201,0,4);
		return;end;
			
			
		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","robert_room");
				delete_tree_leaf("Root","photo");
				delete_tree_leaf("Root","cherdak");
				delete_tree_leaf("Root","comics");
				delete_tree_leaf("Root","mini1");
				delete_tree_leaf("Root","mini2");
				delete_tree_leaf("Root","mini3");
				delete_tree_leaf("Root","mini");
				delete_tree_leaf("Root","mini4");
				delete_tree_leaf("Root","mini5");
				delete_tree_leaf("Root","mini6");		
				delete_tree_leaf("Root","mini7");
				delete_tree_leaf("Root","mini8");
				setnextlavel(6);
				loadlavel();
			return;end;	
			DarkScreen(false);
			speciale_action(2,503,true);
		return;end;	
			
		if obj_id==51 then
				setcurentleaf("robert_room",5,0);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;
				

		if obj_id==50 then
				 if flags.firstloc3==true then				
					BlockCursor(true)
					setcurentleaf("cherdak",5,2);
					
					SwitchToSheet("re");
					flags.firstloc3 = false;
					DarkScreen(true);
					speciale_action(2,503,true,3);
					speciale_action(4,503)
				return; end;
				setcurentleaf("cherdak",5,2);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;	
			


			if obj_id==29 then
			if not flags.minicomplete5 then
				playeffect("mini");
				DarkScreen(true);
				add_free_leaf("Root","mini5",5,16);
				dofile("./data/5/16/res.lua");
				set_satelite_leaf("photo");
				dofile("data\\5\\16\\level.lua");
				mini_create();
				for i=1000,1013,1 do
					speciale_action(2,i,true);
				end;
			return; end;	
			return; end;			


			if obj_id==37 then
			if not flags.minicomplete6 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini6",5,17);
				dofile("./data/5/17/res.lua");
				set_satelite_leaf("photo");
				dofile("data\\5\\17\\level.lua");
				mini_create();
				for i=2,11,1 do
					speciale_action(2,i,true);
				end;
			return; end;
			return; end;		


			
			if obj_id==226 or obj_id==231 then 
				collaps_obj(226,0,0,10,1);
				playeffect("collaps");
				setcolor(226,0,0,0,0.5,1);
				collaps_obj(231,0,0,10,1);
				speciale_action(2,32);
				CreateWindow(100,100,"210");
			return; end;

			if obj_id==218 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==228 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				collaps_obj(1028,0,0,10,1);
				AddElement("gr",1028);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(1028); 
				flags.litr=true;
			return; end;
			
			if obj_id==233 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				collaps_obj(1033,0,0,10,1);
				AddElement("gr",1033);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(1033); 
				flags.lightfilter=true;
			return; end;
			
			if obj_id==243 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				collaps_obj(1043,0,0,10,1);
				AddElement("gr",1043);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(1043); 
			return; end;
			
			if obj_id==238 then
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				collaps_obj(1038,0,0,10,1);
				AddElement("gr",1038);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(1038); 
				flags.photopaper=true;
			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
		if SLevel==1.0 then return;end;
		flags.loc2 = true;	
	return; end;
end
