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.object2 then
		if not flags.minicomplete7  then
			if flags.light then
				if flags.elektropen then
					selectrandomobject(1.5,32);
				return;end
					selectrandomobject(1.5,33);
			return;end	
			selectrandomobject(1.5,52);
		return;end
		if not flags.loc1 then
			selectrandomobject(1.5,50);
		return;end;
		selectrandomobject(1.5,52);
	return;end;

    idObject=GetRandomObject();
	if idObject==14 and not flags.minicomplete3 then
		if GetActivCount()>1 then
			flags.HintCount=flags.HintCount+1;
			SelectRandom()		
		return;end;	
		if not flags.dies then
			if not flags.minicomplete7  then
			if flags.light then
				if flags.elektropen then
					selectrandomobject(1.5,32);
				return;end
					selectrandomobject(1.5,33);
			return;end	
			if not flags.minicomplete2 then
			    selectrandomobject(1.5,48);
			return;end;
			selectrandomobject(1.5,52);
			return;end	
			selectrandomobject(1.5,52);
		return;end;
	    selectrandomobject(1.5,46);
	return;end;
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==14 and not flags.minicomplete3 then
		if not flags.dies then
			if not flags.minicomplete7  then
			if flags.light then
				if flags.elektropen then
					selectrandomobject(1.5,32);
				return;end
					selectrandomobject(1.5,33);
			return;end	
			if not flags.minicomplete2 then
			    selectrandomobject(1.5,48);
			return;end;
			selectrandomobject(1.5,52);
			return;end	
			selectrandomobject(1.5,52);
		return;end;
	    selectrandomobject(1.5,46);
	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 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==36 then
		if obj_id==1111 then
			playeffect("Igri");
			StartTimer(1111,43)	
		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==20 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 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);
			AddParticleToObject(46,"TableD",0,0);
			StartEmiter("TableD");
			MoveEmiter("TableD",415,587);	
			AddParticleToObject(48,"Door",0,0);
			StartEmiter("Door");
			MoveEmiter("Door",974,362);	
			playeffect("Igri");
			StartTimer(1111,43)
			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==33 then
		if flags.light then
			if flags.chair then 		
				if attachedID==123 then   
				    playeffect("attach");	
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					SetAlfaSheet(2.0)					
					Set_Cursor(33,3);
					flags.elektropen=true;
					speciale_action(2,33,true);				
					speciale_action(2,32,true);
					Set_Cursor(32,2);
					playeffect("MetalOpen");	
					AddParticleToObject(32,"Schit",883,146);
					StartEmiter("Schit");
					MoveEmiter("Schit",883,156);					
				return; end;
				if attachedID~=123 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"208");  
				return; end;
			return; end;
			if attachedID==201 then   
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");	
				CreateWindow(100,100,"207"); 
				flags.chair=true;
				speciale_action(2,37,true);
			return; end;
			if attachedID~=201 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"206");  
			return; end;			
		return;end;
		return; end;
		


		if obj_id==46 then
		if not flags.minicomplete3 then
			if attachedID==191 or flags.minirun3 then  
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				playeffect("mini");		
				DarkScreen(true);
				add_free_leaf("Root","mini3",3,14);
				dofile("./data/3/14/res.lua");
				set_satelite_leaf("azart_room");
				dofile("data\\3\\14\\level.lua");
				mini_create();	
				speciale_action(2,1030,true);
				speciale_action(2,1031,true);
				speciale_action(2,1032,true);
				speciale_action(2,1020,true);
				for i=1001,1015,1 do
					speciale_action(2,i,true);
				end;		
			return; end;
			if attachedID~=191 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"204");     
			return; end;
		return; end;	
		return; end;

		if obj_id==48 then	
		if attachedID==-1 or attachedID==111 or attachedID==112 or attachedID==113 or attachedID==110 then	
		RemoveFromMouse(attachedID);
			if not flags.minicomplete2 then
				playeffect("mini");	
				DarkScreen(true);		
				add_free_leaf("Root","mini2",3,13);
				dofile("./data/3/13/res.lua");
				set_satelite_leaf("azart_room");
				dofile("data\\3\\13\\level.lua");
				mini_create();
				speciale_action(2,1013,true);
				speciale_action(2,1006,true);
				speciale_action(2,1007,true);
				speciale_action(2,1008,true);
				speciale_action(2,1009,true);
				speciale_action(2,1020,true);	
			return; end;	
		return; end;	
		return; end;	
		
	if attachedID==-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 obj_id==50 then
				setcurentleaf("kab_direktor",3,0);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;	
			

		if obj_id==52 then			
			if flags.minicomplete2 then
				if flags.firstloc3 then
					BlockCursor(true)
					setcurentleaf("private_room",3,2);
					
					SwitchToSheet("re");
					flags.firstloc3=false;
					DarkScreen(true);
					speciale_action(2,503,true,3);	
					speciale_action(4,503)
				return;end;
				setcurentleaf("private_room",3,2);
				savegame(SaveLevel())
				if flags.lamp then
					CreateWindow(100,100,"223")
				end;
				SwitchToSheet("re");
			return; end;
		return; end;			
	
			
			if obj_id==32 then
			if not flags.minicomplete7 then
				DarkScreen(true);
				playeffect("mini");	
				add_free_leaf("Root","mini7",3,18);
				dofile("./data/3/18/res.lua");
				set_satelite_leaf("azart_room");
				dofile("data\\3\\18\\level.lua");
				mini_create();	
				for i=1000,1050,1 do
				speciale_action(2,i,true);
				end;	
			return;end;		
			return;end;			



			if obj_id==103 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,"220"); 
			return; end;
					
			if obj_id==123 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==201 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 or obj_id==1010 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.object2=true;
		if flags.minicomplete7 then
			flags.loc2 = true;
		return;end;	
		
	return; end;		
end
