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.loc1 then
		selectrandomobject(1.5,58);
	return;end;
    idObject=GetRandomObject();
	if idObject==100 then
	    selectrandomobject(1.5,42);
	return;end;	
	if idObject==106 and not flags.minicomplete then
	    selectrandomobject(1.5,19);
	return;end;			
	if idObject==4 then
		if not flags.box then
			selectrandomobject(1.5,31);
		return;end;		
		selectrandomobject(1.5,32);
	return;end;		
	selectrandomobject(1.5,idObject);
end;


function SelectRandomRadar(idObject)
	if idObject==100 then
	    selectrandomobject(1.5,42);
	return;end;	
	if idObject==106 and not flags.minicomplete then
	    selectrandomobject(1.5,19);
	return;end;			
	if idObject==4 then
		if not flags.box then
			selectrandomobject(1.5,31);
		return;end;		
		selectrandomobject(1.5,32);
	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==36 then
		if obj_id==1111 then
			playeffect("Sparks");
			StartTimer(1111,28)		
		return;end;		
	return;end;
	
	if sender==12 or sender==26 then
		if flags.loc1 then
		if not flags.whole_darkness then
		if not flags.allobject1 then
		    flags.allobject1=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==3 then
		    CreateWindow(100,100,"198");
			BlockCursor(false);
		return;end;		
	return;end;
	
	if sender==15 then
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			if flags.loc1 then
			if not flags.allobject1 then
				flags.allobject1=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,"208");
				flags.minitext1=false
				savegame(SaveLevel())
			return;end;
			if flags.minitext2 then
				CreateWindow(100,100,"209");
				flags.minitext2=false
				savegame(SaveLevel())
			return;end;			
		return;end;		
		if obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(61,"fireplace",0,0);
			StartEmiter("fireplace");
			MoveEmiter("fireplace",313,435);	
			AddParticleToObject(11,"candle",0,0);
			StartEmiter("candle");
			AddParticleToObject(19,"PhotoOn",0,0);
			AddParticleToObject(31,"BoxOn",0,0);
			AddParticleToObject(42,"Urna",0,0);				
			MoveEmiter("PhotoOn",663,252);
			MoveEmiter("BoxOn",867,495);
			MoveEmiter("Urna",240,550);				
			StartEmiter("PhotoOn");
			StartEmiter("BoxOn");
			StartEmiter("Urna");				

			playeffect("Sparks");
			StartTimer(1111,28)		
			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==31 then
	if attachedID==146 then 
		playeffect("attach");	
		Set_Cursor(31,3);		
		speciale_action(2,31,true);
		speciale_action(2,32,true);
		Set_Cursor(32,2)
		StopEmiter("BoxOn");
		AddParticleToObject(32,"Box",895,531);
		StartEmiter("Box");
		MoveEmiter("Box",895,531);			
		RemoveFromMouse(attachedID);
		DeleteElement("gr",attachedID);
		SetAlfaSheet(2.0)
		flags.box=true;
	return; end;
	if attachedID~=146 and attachedID>-1 then
		CreateWindow(100,100,"200");     
	return; end;
	if attachedID ==-1 then		
		CreateWindow(100,100,"202"); 
	return; end;	
	return; end;
	
	if obj_id==19 then
	if not flags.minicomplete then

		if attachedID==110 then  
			flags.lens = true;
			playeffect("attach");
			speciale_action(2,18,true);			
			if flags.flash then
			Set_Cursor(19,3)
				Set_Cursor(18,2)
				StopEmiter("PhotoOn");
				AddParticleToObject(17,"Photo",676,262);
				StartEmiter("Photo");
				MoveEmiter("Photo",676,262);	
			end;
			speciale_action(10,18)
			RemoveFromMouse(attachedID);
			DeleteElement("gr",attachedID);			
			SetAlfaSheet(2.0)
		return; end;
		if attachedID==115 then
			flags.flash=true;
			playeffect("attach");
			speciale_action(2,17,true);
			if flags.lens then
			Set_Cursor(19,3)
				Set_Cursor(18,2)
			end;			
			speciale_action(10,17)
			RemoveFromMouse(attachedID);
			DeleteElement("gr",attachedID);					

		return; end;								
		if attachedID~=110 and attachedID~=115 and attachedID>-1 then-- заменить 
			CreateWindow(100,100,"200");     
		return; end;
		if attachedID ==-1 then		
			if flags.flash and flags.lens then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini",5,11);
				dofile("./data/5/11/res.lua");
				set_satelite_leaf("robert_room");
				dofile("data\\5\\11\\level.lua");
				mini_create();
				speciale_action(2,1000,true);
				speciale_action(2,1002,true);
				speciale_action(2,1003,true);
			return;end;		
			CreateWindow(100,100,"201");  
		return; end;
	return; end;	
	return; end;				
	
	
	if attachedID==-1 then		
		if obj_id==3 then
		if not car then
			car=true;
			speciale_action(2,3)
		   StartAnimation(202,0,6);
		return;end;
		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==58 then
			   if flags.firstloc2==true then
					BlockCursor(true)
					setcurentleaf("photo",5,1);
					
					SwitchToSheet("re");
					flags.firstloc2 = false;
					DarkScreen(true);
					speciale_action(2,503,true,3);
					speciale_action(4,503)
				return; end;
				setcurentleaf("photo",5,1);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;
			
						
			if obj_id==42 then
			if not flags.minicomplete1 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini1",5,12);
				dofile("./data/5/12/res.lua");
				set_satelite_leaf("robert_room");
				dofile("data\\5\\12\\level.lua");

				for i=0,16,1 do
					speciale_action(2,i,true);
				end;
				mini_create();	
			return; end;				
			return; end;						

			if obj_id==32 then
			if not flags.minicomplete2 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini2",5,13);
				dofile("./data/5/13/res.lua");
				set_satelite_leaf("robert_room");
				dofile("data\\5\\13\\level.lua");
				mini_create();	
				for i=1001,1021 do
					speciale_action(2,i,true);
				end;
			return;end;
			return; end;
			
	
			
			if obj_id==110 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==115 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==100 then 
				collaps_obj(obj_id,0,0,10,1);
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"208");
			return; end;

			if obj_id==106 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); 
				flags.film_in=true
			return; end;			
			
			if obj_id==146 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==14 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"203");
			return; end;
			
			if obj_id==107 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 < 300 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.loc1 = true;		
	return; end;	
end
