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

function SelectRandom()
    idObject=GetRandomObject();
	if flags.loc3 then
		if (not flags.loc1) or (not flags.loc2) then
			selectrandomobject(1.5,166);
		return;end;
		selectrandomobject(1.5,167);
	return;end;	
	if flags.darkness then
		if not flags.light then
		if flags.lamp then
			selectrandomobject(1.5,50);
		return;end;		
		selectrandomobject(1.5,167);
		return;end;
		selectrandomobject(1.5,166);
	return; end;
	if idObject==301 then
	    selectrandomobject(1.5,71);
	return;end;
	if idObject==334 and (not flags.minicomplete5) then
		if GetActivCount()>1 then
			flags.HintCount=flags.HintCount+1;
			SelectRandom()		
		return;end;		
	    selectrandomobject(1.5,37);
	return;end;	
	if idObject==25 then
	if not flags.minicomplete5 then
		if not flags.paton then
			selectrandomobject(1.5,33);
		return;end;
		selectrandomobject(1.5,37);
	return;end;
	    selectrandomobject(1.5,47);
	return;end;	
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==301 then
	    selectrandomobject(1.5,71);
	return;end;
	if idObject==334 and (not flags.minicomplete5) then	
	    selectrandomobject(1.5,37);
	return;end;	
	if idObject==25 then
	    selectrandomobject(1.5,47);
	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.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 and flags.loc4 and flags.loc5 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;

	return;end;

	if sender==15 then
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			if flags.loc3 then
			if not flags.allobject3 then
		    flags.allobject3=true;
			if flags.loc1 and flags.loc2 and flags.loc3 and flags.loc4 and flags.loc5 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
		   BlockCursor(false);
		   ShowMenu(true);
		   CreateWindow(100,100,"196");
			AddParticleToObject(50,"LampOn",429,156);
			StartEmiter("LampOn");
			MoveEmiter("LampOn",432,200);
			AddParticleToObject(167,"DoorOn",868,133);
			StartEmiter("DoorOn");
			MoveEmiter("DoorOn",868,133);	
			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==501 then
				if flags.levelcomplete then
					delete_tree_leaf("Root","kab_direktor");
					delete_tree_leaf("Root","azart_room");
					delete_tree_leaf("Root","private_room");
					delete_tree_leaf("Root","grimerka");
					delete_tree_leaf("Root","kulisi");
					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");
					setnextlavel(4);
					loadlavel();
				return;end;	
				DarkScreen(false);
				speciale_action(2,503,true);
			return;end;

		if 	attachedID==-1 then
			if obj_id==66 or obj_id==166 then
				setcurentleaf("azart_room",3,1);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;	
			
			if obj_id==67 or obj_id==167 then
				if flags.firstloc5==true then
					BlockCursor(true)
					setcurentleaf("kulisi",3,4);
					
					StopEmiter("DoorOn");
					
					SwitchToSheet("re");
					flags.firstloc5 = false;	
					DarkScreen(true);
					speciale_action(2,503,true,3);	
					speciale_action(4,503)
					
				return; end;	
				setcurentleaf("kulisi",3,4);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;	
		end;
	if obj_id==50 then
	if not flags.light then
		if attachedID==104 then  
			RemoveFromMouse(attachedID);
			DeleteElement("gr",attachedID);
			SetAlfaSheet(2.0)
			playeffect("attach");	
			flags.lamp=false;
			flags.light=true;
			CreateWindow(100,100,"222");
			Set_Cursor(50,3);
			StopEmiter("LampOn");
			setcurentleaf("azart_room",3,1);
			Set_Cursor(33,4);
			AddParticleToObject(33,"Schit1",0,0);
			StartEmiter("Schit1");
			MoveEmiter("Schit1",898,102);			
			setcurentleaf("private_room",3,2);
			speciale_action(2,54);
			savegame(SaveLevel())
			CreateWindow(100,100,"209"); 
		return; end;
		if attachedID~=104 and attachedID>-1 then
			CreateWindow(100,100,"200");     
		return; end;
		if attachedID ==-1 then		
			CreateWindow(100,100,"211"); 
		return; end;
	return; end;	
	return; end;
			
		if not flags.darkness then
			
		if obj_id==37 then		
		if not flags.minicomplete5 then
		if flags.plate and flags.ruchka and flags.igla then
			flags.minicomplete5=true;
			speciale_action(2,334,true);
			setcolor(334,0,0,0,1,1);
			Set_Cursor(37,3);
			speciale_action(2,37);
			speciale_action(2,1037);
			speciale_action(2,34);
			speciale_action(2,35);
			speciale_action(2,36);
			speciale_action(2,201);
			speciale_action(4,201);
			StopEmiter("Pat");
			playeffect("Melody");
			StartAnimation(201,0,204);
		return; end;
							
		if attachedID==102 then   
			RemoveFromMouse(attachedID);
			DeleteElement("gr",attachedID);
			SetAlfaSheet(2.0)
			playeffect("attach");	
			flags.plate=true;
			speciale_action(2,36,true);
		return; end;				
		if attachedID==331 then   
			RemoveFromMouse(attachedID);
			DeleteElement("gr",attachedID);
			SetAlfaSheet(2.0)
			playeffect("attach");	
			flags.ruchka=true;
			speciale_action(2,34,true);				
		return; end;				
		if attachedID==301 then   
			RemoveFromMouse(attachedID);
			DeleteElement("gr",attachedID);
			SetAlfaSheet(2.0)
			playeffect("attach");	
			flags.igla=true
			speciale_action(2,35,true);					
		return; end;
		if (attachedID>-1) and (attachedID~=102 or attachedID~=301 or attachedID~=331) then
			CreateWindow(100,100,"200");  
		return; end; 
		if attachedID==-1 then
			CreateWindow(100,100,"213");  
		return; end; 
		return; end;
	return; end;
	
	if obj_id==47 then
		if flags.steppler then
		if not flags.minicomplete6  then
			if attachedID==100 or flags.minirun6 then   
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				playeffect("mini");		
				DarkScreen(true);
				add_free_leaf("Root","mini6",3,17);
				dofile("./data/3/17/res.lua");
				set_satelite_leaf("private_room");
				dofile("data\\3\\17\\level.lua");
				mini_create();	
				for i=1000,1029,1 do
					if obj_id~=1004 then
					speciale_action(2,i,true)
					return;end;
				end;		
			return; end;
			if attachedID~=100 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"216");  
			return; end;						
		return;end;					
		return;end;
		if flags.page then
		if not flags.minicomplete6 then
			if attachedID==103 then   
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");
				flags.steppler=true;
				StopEmiter("DictOn");
				AddParticleToObject(47,"Dict",429,156);
				StartEmiter("Dict");
				MoveEmiter("Dict",365,428);
				CreateWindow(100,100,"216");  					
			return; end;
			if attachedID~=103 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"215"); 
			return; end;						
		return;end;					
		return;end;				
		if attachedID==334 then    
			RemoveFromMouse(attachedID);
			DeleteElement("gr",attachedID);
			SetAlfaSheet(2.0)
			playeffect("attach");
			flags.page=true;
			CreateWindow(100,100,"215"); 
		return; end;
		if attachedID~=334 and attachedID>-1 then
			CreateWindow(100,100,"200");     
		return; end;
		if attachedID ==-1 then		
			CreateWindow(100,100,"214"); 
		return; end;
	return; end;
	

	
	if obj_id==71 then
		if not flags.minicomplete4 then
		if attachedID==318 then    
			RemoveFromMouse(attachedID);
			DeleteElement("gr",attachedID);	
			SetAlfaSheet(2.0)
			playeffect("attach");
			Set_Cursor(71,3);
			speciale_action(71,true);
			speciale_action(2,40,true);
			Set_Cursor(40,2);
			flags.tumbon=true;
			StopEmiter("TumbOn");
			AddParticleToObject(40,"Tumb",870,552);
			StartEmiter("Tumb");
			MoveEmiter("Tumb",870,552);			
		return; end;			
		if attachedID~=318 and attachedID>-1 then
			CreateWindow(100,100,"200");     
		return; end;
		if attachedID ==-1 then		
			CreateWindow(100,100,"212");  
		return; end;
		return; end;
	return; end;
			
		if attachedID==-1 then	
		

			if obj_id==40 then
			if not flags.minicomplete4 then
				DarkScreen(true);
				playeffect("mini");	
				add_free_leaf("Root","mini4",3,15);
				dofile("./data/3/15/res.lua");
				set_satelite_leaf("private_room");
				dofile("data\\3\\15\\level.lua");
				mini_create();
				speciale_action(2,100,true);
				speciale_action(2,2,true);
				speciale_action(2,4,true);
				for i=5,11,1 do
					speciale_action(2,i,true);
				end;
			return; end;	
			return;end;
			

			if obj_id==33 then
				speciale_action(2,33);
				speciale_action(2,1033);
				Set_Cursor(33,3);
				speciale_action(2,37);
				speciale_action(2,1037);
				Set_Cursor(37,4);
				flags.paton=true;
				StopEmiter("PatOn")
				AddParticleToObject(37,"Pat",0,0);
				StartEmiter("Pat");
				MoveEmiter("Pat",930,441);					
			return;end;
			
		

			if obj_id==318 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==331 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==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); 
			return; end;	
			
			if obj_id==58 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				setcolor(obj_id,0,0,0,0.5,1);
			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 not flags.light then
		if flags.lamp then
			CreateWindow(100,100,"223")
		return;end;
		CreateWindow(100,100,"210"); 			
		return;end;
		CreateWindow(100,100,"222");


		
	return; end;


	if sender==6 then
	if flags.darkness then
		if not flags.light then
		if flags.lamp then
			CreateWindow(100,100,"223")
		return;end;		
		CreateWindow(100,100,"210"); 	
		return;end;
		CreateWindow(100,100,"222");
	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
