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

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

function PhoneSound()
	playeffect("phone");
end;

function SelectRandom()
    idObject=GetRandomObject();	
	if idObject==1 then
		if not flags.lighton then
		    selectrandomobject(1.5,44);
		return;end;
		selectrandomobject(1.5,3);
	return;end	
	if idObject==38 then
		if not flags.lighton then
		    selectrandomobject(1.5,44);
		return;end;	
		if flags.key then	
			if flags.shkaf then
				selectrandomobject(1.5,67);
			return;end;				
			selectrandomobject(1.5,73);
		return;end;	
		selectrandomobject(1.5,3);		
	return;end	
	if idObject==142 then
		if flags.body then
			if not flags.but then
				selectrandomobject(1.5,77);
			return;end	
				selectrandomobject(1.5,142);
		return;end	
		selectrandomobject(1.5,48);
	return;end	
	if idObject==74 then
		if not flags.lighton then
		    selectrandomobject(1.5,44);
		return;end;	
		if not flags.minicomplete then
			if flags.key then
				if flags.shkaf then
					selectrandomobject(1.5,67);
				return;end;	
				selectrandomobject(1.5,73);
			return;end;
			selectrandomobject(1.5,3);
		return;end;
		 selectrandomobject(1.5,45);
	return;end		
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==1 then
		if not flags.lighton then
		    selectrandomobject(1.5,44);
		return;end;
		selectrandomobject(1.5,3);
	return;end	
	if idObject==38 then
		if not flags.lighton then
		    selectrandomobject(1.5,44);
		return;end;	
		if flags.key then	
			if flags.shkaf then
				selectrandomobject(1.5,67);
			return;end;				
			selectrandomobject(1.5,73);
		return;end;	
		selectrandomobject(1.5,3);		
	return;end	
	if idObject==142 then
		if flags.body then
			if not flags.but then
				selectrandomobject(1.5,77);
			return;end	
				selectrandomobject(1.5,142);
		return;end	
		selectrandomobject(1.5,48);
	return;end	
	if idObject==74 then
		if not flags.lighton then
		    selectrandomobject(1.5,44);
		return;end;	
		if not flags.minicomplete then
			if flags.key then
				if flags.shkaf then
					selectrandomobject(1.5,67);
				return;end;	
				selectrandomobject(1.5,73);
			return;end;
			selectrandomobject(1.5,3);
		return;end;
		 selectrandomobject(1.5,45);
	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.levelcomplete then
		DarkScreen(true);
		ShowMenu(false);
	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==8 then
			CreateWindow(100,100,"198");
			BlockCursor(false);
		return;end;								
	return;end;
	
	if sender==15 then
		if obj_id==501 then
		    flags.whole_darkness=false;
			BlockCursor(false);
		return;end;			
		if obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(173,"Door",0,0);
			StartEmiter("Door");
			MoveEmiter("Door",432,330);	
			AddParticleToObject(44,"Switch",0,0);
			StartEmiter("Switch");
			MoveEmiter("Switch",790,211)	
			AddParticleToObject(45,"Glass",0,0);
			StartEmiter("Glass");
			MoveEmiter("Glass",814,595)		
		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 not flags.wine then
			if attachedID==38 then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");
				collaps_obj(74,0,0,10,1);
				-- AddElement("gr",52);
				setcolor(74,0,0,0,0.5,1);
				-- MoveObjectToTree(52)
				CreateWindow(100,100,"207");
				flags.wine=true;
				StopEmiter("Glass");				
			return; end;
			if attachedID~=38 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"205");  
			return; end;
	return; end;		
	return; end;

			if obj_id==3 or obj_id==1 then  --ключ
			if flags.lighton then
			if flags.stepladder then
				if attachedID ==-1 then							
					collaps_obj(1,0,0,10,1);
					AddElement("gr",1);
					SetAlfaSheet(2.5)
					setcolor(1,0,0,0,0.5,1);
					MoveObjectToTree(1); 
					playeffect("collaps");
					flags.key=true;
					StopEmiter("Key");
				return; end;
			return; end;
			if not flags.stepladder then
				if attachedID==76 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
			--		speciale_action(2,7);
					flags.stepladder=true
					speciale_action(2,7,true);
					Set_Cursor(3,3)
					
				return; end;
				if attachedID~=76 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"202");  
				return; end;
			return; end;	
			return; end;		
			return; end;

	
			if obj_id==77 then --комод
				if not flags.but then
				if flags.body then
					if attachedID==32 then    
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						SetAlfaSheet(2.0)
						playeffect("attach");
						speciale_action(2,142,true);
						setcolor(142,0,0,0,1,1);
						Set_Cursor(77,3)
						flags.but=true;
						StopEmiter("But");
					return; end;
					if attachedID~=32 and attachedID>-1 then
						CreateWindow(100,100,"200");     
					return; end;
					if attachedID ==-1 then		
						CreateWindow(100,100,"203");  
					return; end;
				return; end;
				return; end;				
			return; end;
			
			if obj_id==173 then --шкафичк
				if attachedID==1 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("door");	
					Set_Cursor(173,3)
					speciale_action(2,73,true);
					SetAlfa(173,0.001,0,0.1)
					SetAlfa(167,0,0.001,0.1)
					speciale_action(2,71,true);
					speciale_action(2,67);
					flags.shkaf=true;
					StopEmiter("Door");
					AddParticleToObject(167,"Apt",0,0);
					StartEmiter("Apt");
					MoveEmiter("Apt",415,394);				
					
				--	Set_Cursor(67,2)
					--AddParticleToObject(63,"./particles/particle6.psi");
				return; end;
				if attachedID~=1 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"204");  
				return; end;	
			return; end;
			
	if attachedID==-1 then	

		if obj_id==102 then
		    StartAnimation(102,0,3)
		return;end;
		
		if obj_id==104 then
			StartAnimation(104);
			ActivateObject(104,false);
		return;end;
		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","hotel");
				delete_tree_leaf("Root","mini");
				setnextlavel(16);
				loadlavel();	
				ShowMenu(false);
			return;end;	
			DarkScreen(false);
			speciale_action(2,503,true);
		return;end;		
			
			if obj_id==44 then --выключатель
				playeffect("handle");
				speciale_action(2,44);
				speciale_action(2,43);
				Set_Cursor(44,3)
				Set_Cursor(3,4)
				--speciale_action(2,3,true);
				speciale_action(2,2,true);
				speciale_action(2,1,true);
			--	setcolor(1,0,0,0,1,1);
				Set_Cursor(1,2)
				flags.lighton=true;
				StopEmiter("Switch");
				AddParticleToObject(2,"Key",0,0);
				StartEmiter("Key");
				MoveEmiter("Key",530,40);				
				--AddParticleToObject(1,"./particles/particle6.psi");
			return; end;

			if obj_id==1 then  --ключ
			if flags.stepladder and flags.lighton 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.key=true;
			return; end;			
			return; end;
			
			if obj_id==3 then
			    if not flags.key then
				    CreateWindow(100,100,"201");  
				return;end;
			return;end;


			if obj_id==32 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==167 then --шкафичк
				if not flags.minicomplete then
					playeffect("mini");
					DarkScreen(true);
					add_free_leaf("Root","mini",15,11);
					dofile("./data/15/11/res.lua");
					set_satelite_leaf("hotel");
					dofile("data\\15\\11\\level.lua");
					mini_create();
					for i=1000,1005,1 do
						speciale_action(2,i,true)
					end;
				return; end;	
			return; end;		
			

			
			if obj_id==29 then --бокал на столе
			    collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"206");  
				Set_Cursor(19,3)
			return;end;	

			
			if obj_id==8 then  --стремянка
		--		AddElement("gr",obj_id);
				speciale_action(2,obj_id);
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				setcolor(obj_id,0,0,0,0.5,1);
				collaps_obj(76,0,0,10,1);
				AddElement("gr",76);	
				SetAlfaSheet(2.5)				
				MoveObjectToTree(76); 
			return; end;

			if obj_id==142 then  --пуговица
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
			--	AddElement("gr",obj_id);
				setcolor(obj_id,0,0,0,0.5,1);
			--	MoveObjectToTree(obj_id); 
				CreateWindow(100,100,"208");  
			return; end;			
			
			if obj_id==38 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==48 then --тело
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
	--			AddElement("gr",obj_id);
				setcolor(obj_id,0,0,0,0.5,1);
		--		MoveObjectToTree(obj_id); 
				Set_Cursor(77,4);
					AddParticleToObject(77,"But",0,0);
					StartEmiter("But");
					MoveEmiter("But",693,532);						
				--AddParticleToObject(77,"./particles/particle6.psi");
				flags.body=true;
			return;end;	
			
			if obj_id > 0 and obj_id < 101 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
		flags.levelcomplete=true;
	return; end;
	
end
