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.loc3 then
		selectrandomobject(1.5,56);
	return;end;
    idObject=GetRandomObject();
	if (idObject==346 or idObject==305) and (not flags.minicomplete8)  then
	    selectrandomobject(1.5,45);
	return;end;			
	if idObject==8 and (not flags.minicomplete7) then
		if GetActivCount()>1 then
			flags.HintCount=flags.HintCount+1;
			SelectRandom()		
		return;end;			
	    selectrandomobject(1.5,38);
	return;end;		
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)
	if (idObject==346 or idObject==305) and (not flags.minicomplete8)  then
	    selectrandomobject(1.5,45);
	return;end;			
	if idObject==8 and (not flags.minicomplete7) then		
	    selectrandomobject(1.5,38);
	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==35 then
		if obj_id==201 then
			StartAnimation(201,0,8)
		return;end;
		if obj_id==202 then
			StartAnimation(202,0,6)
		return;end;		
	return;end;
	
	if sender==12 or sender==26 then
		if flags.loc3 then
		if not flags.whole_darkness then
		if not flags.allobject3 then
		    flags.allobject3=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==1 then
			CreateWindow(100,100,"197");
			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;			
		return;end;			
		if obj_id==503 then
			ShowMenu(true);
				AddParticleToObject(2,"Emitter",0,0);
				MoveEmiter("Emitter",383,392);
				StartEmiter("Emitter");	
				AddParticleToObject(38,"RWOn",0,0);
				AddParticleToObject(45,"Furniture",0,0);			
				StartEmiter("RWOn");
				StartEmiter("Furniture");
				MoveEmiter("RWOn",616,577);
				MoveEmiter("Furniture",577,444);					
			BlockCursor(false);
			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==38 then 
			if not flags.minicomplete7 then
				if attachedID==305 then
					playeffect("attach");
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					speciale_action(2,37,true);
					Set_Cursor(38,2)
					StopEmiter("RWOn");
					AddParticleToObject(38,"RW",570,547);
					StartEmiter("RW");
					MoveEmiter("RW",570,547);						
					flags.parts=true;				
				return;end;
				if attachedID~=305 and attachedID~=333 and attachedID~=334 and attachedID~=348 and attachedID~=346 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if flags.parts  then
				    RemoveFromMouse(attachedID);	
					DarkScreen(true);		
					playeffect("mini");
					add_free_leaf("Root","mini7",5,18);
					dofile("./data/5/18/res.lua");
					set_satelite_leaf("cherdak");
					dofile("data\\5\\18\\level.lua");
					mini_create();
					for i=1000,1012 do
						if i~=1002 and i~=1004 and i~=1008 and i~=1011 then
							speciale_action(2,i,true);
						end;
					end;
				return; end;
				CreateWindow(100,100,"201");  		 
			return; end;			
			return; end;	

		if attachedID==-1 then	

		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==56 then
				setcurentleaf("photo",5,1);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;	
			

			
			if obj_id==45 then 
			if not flags.minicomplete8 then
			    DarkScreen(false);
				playeffect("mini");
				add_free_leaf("Root","mini8",5,19);
				dofile("./data/5/19/res.lua");
				set_satelite_leaf("cherdak");
				dofile("data\\5\\19\\level.lua");
				mini_create();
				for i=1001,1021 do
					speciale_action(2,i,true)
				end;
			return; end;	
			return; end;	

			if obj_id==346 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.trans=true;			
			return; end;

			if obj_id==305 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==8 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"211");			
			return; end;			
			
			if obj_id==348 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.redwire=true;
			return; end;

			if obj_id==333 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.bluewire=true;
			return; end;
			
			if obj_id==334 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.fuel=true;
			return; end;				
			
			if obj_id > 0 and obj_id < 400 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.loc3 = true;	
	return; end;	
end
