
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
		if not flags.loc2 then
			selectrandomobject(1.5,41);
		return;end;
		selectrandomobject(1.5,63);
	return;end;
    idObject=GetRandomObject();
	if idObject==108 and not flags.forpasskey2 then
		if not flags.minicomplete2 then
		    selectrandomobject(1.5,55);
		return;end;
		selectrandomobject(1.5,41);
	return;end;
	if idObject==227 or idObject==108 then
	    selectrandomobject(1.5,6);
	return;end;	
	if idObject==16 or idObject==260  then
		if not flags.boxopen then
			if not flags.forpasskey then
				selectrandomobject(1.5,67);
			return;end;
			selectrandomobject(1.5,6);
		return;end;
		
		selectrandomobject(1.5,33);
	return;end;	
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)
	if idObject==108 and not flags.forpasskey2 then
		if not flags.minicomplete2 then
		    selectrandomobject(1.5,55);
		return;end;
		selectrandomobject(1.5,41);
	return;end;
	if idObject==227 or idObject==108 then
	    selectrandomobject(1.5,6);
	return;end;	
	if idObject==16 or idObject==260  then
		if not flags.boxopen then
			if not flags.forpasskey then
				selectrandomobject(1.5,67);
			return;end;
			selectrandomobject(1.5,6);
		return;end;
		selectrandomobject(1.5,33);
	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.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==7 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);
			if flags.minitext1 then
				CreateWindow(100,100,"207");
				flags.minitext1=false;	
				savegame(SaveLevel())				
			return;end;
			if flags.minitext2 then
				CreateWindow(100,100,"8");
				flags.minitext2=false;				
				savegame(SaveLevel())
			return;end;			
			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;
		return;end;		
		if obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(6,"ApOn",0,0);
			AddParticleToObject(55,"Black",0,0);
			AddParticleToObject(42,"Wkaf",0,0);
			AddParticleToObject(67,"BoxOn",0,0);			
			StartEmiter("ApOn");
			StartEmiter("Black");
			StartEmiter("Wkaf");
			StartEmiter("BoxOn");				
			MoveEmiter("ApOn",55,451);
			MoveEmiter("Black",658,343);
			MoveEmiter("Wkaf",909,156);	
			MoveEmiter("BoxOn",232,604);	
			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==67 then
			if not 	flags.boxopen then		
					if attachedID==226 or attachedID==109 then 
						if not flags.forpasskey1 then
							flags.forpasskey1=true;
							flags.mould_in1=false;							
							RemoveFromMouse(attachedID);
							DeleteElement("gr",attachedID);
							playeffect("attach");
							collaps_obj(260,0,0,10,1);
							AddElement("gr",260);
							SetAlfaSheet(2.5)
							setcolor(260,0,0,0,0.5,1);
							MoveObjectToTree(260); 	
						return; end	
					return; end;
					
					if attachedID==227 then
							RemoveFromMouse(attachedID);
							DeleteElement("gr",attachedID);
							SetAlfaSheet(2.0)
							playeffect("attach");
							Set_Cursor(67,3);
							Set_Cursor(33,2);
							speciale_action(2,33,true);
							flags.boxopen=true;
							StopEmiter("BoxOn");
							AddParticleToObject(33,"Box",246,624);
							StartEmiter("Box");
							MoveEmiter("Box",256,624);						
					return; end;
					if attachedID~=227 and attachedID~=226 and attachedID~=109 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==6 then 
			if (not flags.minicomplete) then  
	
				if attachedID==231 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
					flags.handle=true;
					StopEmiter("ApOn");
					AddParticleToObject(6,"Ap",139,559);
					StartEmiter("Ap");
					MoveEmiter("Ap",139,559);						
					Set_Cursor(6,2);
					speciale_action(2,68,true)
				return; end;
				if attachedID~=231 and attachedID~=260 and attachedID~=261 and attachedID~=236 and attachedID>-1 then
					if not flags.handle then
						CreateWindow(100,100,"200");     
					return;end;
				return; end;
				if attachedID ==-1 or attachedID==260 or attachedID==261 or attachedID==236 then		
					RemoveFromMouse(attachedID);				
					if flags.handle then
						DarkScreen(true);
						playeffect("mini");
						add_free_leaf("Root","mini",7,11);
						dofile("./data/7/11/res.lua");
						set_satelite_leaf("gangster");
						dofile("data\\7\\11\\level.lua");
						mini_create();
						for i=1004,1045,1 do
						  if i<=1011 and i>=1020 and i~=1035 then
							speciale_action(2,i,true,2);
						  end;
						end;
					return; end;	
					CreateWindow(100,100,"203"); 
				return; end;			
			return; end;				
			return; end;

			
		if attachedID==-1 then	

		if obj_id==204 then
			StartAnimation(204,0,3)
		return;end;
		
		if obj_id==202 then
		    StartAnimation(202,0,5)
		return;end;
		
		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","gangster");
				delete_tree_leaf("Root","tir");
				delete_tree_leaf("Root","billiard");
				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");
				setnextlavel(8);
				loadlavel();
			return;end;	
			DarkScreen(false);
			speciale_action(2,503,true);
		return;end;			
		
		if obj_id==41 then
			if flags.minicomplete2 then
				if flags.firstloc2==true then
					BlockCursor(true);
					setcurentleaf("tir",7,1);
					
					SwitchToSheet("re");
					flags.firstloc2 = false;
					DarkScreen(true);
					speciale_action(2,503,true);	
					speciale_action(4,503)
					
				return; end;
				setcurentleaf("tir",7,1);
				savegame(SaveLevel())
			return; end;
				CreateWindow(100,100,"209");  
			return; end;
				
			if obj_id==63 then
				if flags.firstloc3==true then
					BlockCursor(true);
					setcurentleaf("billiard",7,2);
					
					SwitchToSheet("re");
					AddParticleToObject(19,"Steam2",0,0);
					AddParticleToObject(38,"lamp1",0,0);
					AddParticleToObject(41,"lamp2",0,0);
					AddParticleToObject(42,"lamp3",0,0);
					StartEmiter("Steam2");			
					StartEmiter("lamp1");	
					StartEmiter("lamp2");	
					StartEmiter("lamp3");						
					flags.firstloc3 = false;
					DarkScreen(true);
					speciale_action(2,503,true);	
					speciale_action(4,503)
				return; end;
				setcurentleaf("billiard",7,2);
				savegame(SaveLevel())
			return; end;
			

			if obj_id==55 then
			if not flags.minicomplete2 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini2",7,13);
				dofile("./data/7/13/res.lua");
				set_satelite_leaf("gangster");
				dofile("data\\7\\13\\level.lua");
				mini_create();
				
				for i=1001,1021,1 do
				  speciale_action(2,i,true);
				end;
			return; end;	
			return; end;	

			if obj_id==33 then
				if not flags.minicomplete3 then	
					DarkScreen(true);	
					playeffect("mini");
					add_free_leaf("Root","mini3",7,14);
					dofile("./data/7/14/res.lua");
					set_satelite_leaf("gangster");
					dofile("data\\7\\14\\level.lua");
					mini_create();		
					for i=1000,1021,1 do
					  speciale_action(2,i,true);
					end;
				return; end;
			return;end;


			


			if obj_id==226 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==227 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==108 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==236 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				AddElement("gr",obj_id);
				setcolor(obj_id,0,0,0,0.5,1);
				SetAlfaSheet(2.5)
				MoveObjectToTree(obj_id); 
			return; end;
			
			if obj_id==231 then 
			    flags.mould_in2=true;
				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==109 then 
				flags.mould_in1=true;
				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==42 then 
			if not flags.minicomplete2 then
				CreateWindow(100,100,"214"); 
			return; end;	
			return; end;
			
			if obj_id > 0 and obj_id < 59 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
