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.loc2 then
	   selectrandomobject(1.5,66);
	return;end;
    idObject=GetRandomObject();
	if idObject==261  then
		selectrandomobject(1.5,50);
	return;end;			
	if idObject==64 and not flags.minicomplete5 then
		if not flags.rollet then
			if GetActivCount()>3 then
				flags.HintCount=flags.HintCount+1;
				SelectRandom()		
			return;end;				
			if not flags.rolloff then
				if not flags.passkey2 and ((not flags.blank1) or (not flags.blank2))  then
					selectrandomobject(1.5,66);
				return;end;	
					selectrandomobject(1.5,50);
			return;end;
			selectrandomobject(1.5,4);
		return;end;	
	    selectrandomobject(1.5,69);
	return;end;		
	if (idObject==53 or idObject==250) and (not flags.rollet)  then
		if GetActivCount()>3 then
			flags.HintCount=flags.HintCount+1;
			SelectRandom()		
		return;end;			
		if not flags.rolloff then
		if not flags.passkey2 and ((not flags.blank1) or (not flags.blank2))  then
			selectrandomobject(1.5,66);
		return;end;	
			selectrandomobject(1.5,50);
		return;end;
		selectrandomobject(1.5,4);
	return;end;			
	if idObject==247 then
		if not flags.magazin then
		   selectrandomobject(1.5,248);
		return;end;
		if not flags.stvol then
			if not flags.rollet then
				if not flags.rolloff then
					if not flags.passkey2 and ((not flags.blank1) or (not flags.blank2))  then
						selectrandomobject(1.5,66);
					return;end;	
						selectrandomobject(1.5,50);
				return;end;
				selectrandomobject(1.5,4);
			return;end;				
		   selectrandomobject(1.5,250);
		return;end; 
		if not flags.priklad then	
           selectrandomobject(1.5,249);		
		return;end; 
	return;end;
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==261  then
			selectrandomobject(1.5,50);
	return;end;			
	if idObject==64 and not flags.minicomplete5 then
		if not flags.rollet then		
			if not flags.rolloff then
				selectrandomobject(1.5,50);
			return;end;
			selectrandomobject(1.5,4);
		return;end;	
	    selectrandomobject(1.5,69);
	return;end;		
	if (idObject==53 or idObject==250) and (not flags.rollet)  then		
		if not flags.rolloff then
			if not flags.passkey2 then
				selectrandomobject(1.5,66);
			return;end;	
				selectrandomobject(1.5,50);
		return;end;
		selectrandomobject(1.5,4);
	return;end;			
	if idObject==247 then
		if not flags.magazin then
		   selectrandomobject(1.5,248);
		return;end;
		if not flags.stvol then
			if not flags.rollet then
				if not flags.rolloff then
					if not flags.passkey2 then
						selectrandomobject(1.5,66);
					return;end;	
						selectrandomobject(1.5,50);
				return;end;
				selectrandomobject(1.5,4);
			return;end;				
		   selectrandomobject(1.5,250);
		return;end; 
		if not flags.priklad then	
           selectrandomobject(1.5,249);		
		return;end; 
	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 then
				flags.levelcomplete=true;
				DarkScreen(true);
				ShowMenu(false);
			return; end;	
			CreateWindow(100,100,"199");
		return;end;	
		return;end;	
		return;end;
	return;end;

	if sender==35 then
		if obj_id==201 then
			StartAnimation(201,0,4)
		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==2 then
			CreateWindow(100,100,"196");
			BlockCursor(false);
		return;end;					
	return;end;
	
	if sender==15 then	
		if obj_id==51 and flags.rolletout then
		savegame(SaveLevel())
		end;
		if obj_id==69 and flags.tickets then
		savegame(SaveLevel())
		end;
		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);
			BlockCursor(false);
			AddParticleToObject(50,"Zamok",0,0);
			AddParticleToObject(4,"Handle",0,0);		
			StartEmiter("Zamok");
			StartEmiter("Handle");	
			MoveEmiter("Zamok",474,429);
			MoveEmiter("Handle",204,421);
			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==50 then		
			if not flags.rolloff then
			if attachedID==108 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
					flags.rolloff=true;
					speciale_action(2,50,true);
					Set_Cursor(50,3)
				return; end;			
     			if attachedID==109 or attachedID==226 then  
					if not 	flags.forpasskey2 then
						flags.forpasskey2=true; 
						flags.mould_in2=false;
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						playeffect("attach");
						collaps_obj(261,0,0,10,1);
						AddElement("gr",261);
						SetAlfaSheet(2.5)
						setcolor(261,0,0,0,0.5,1);
						MoveObjectToTree(261); 	
					return; end					
				return; end;
				if attachedID~=109 and  attachedID~=109  and  attachedID~=226 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==69 then
				if not flags.minicomplete5 then		
					if attachedID==247 or flags.minirun5 then
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						playeffect("mini");
						Set_Cursor(69,2)
						DarkScreen(true);
						add_free_leaf("Root","mini5",7,16);
						dofile("./data/7/16/res.lua");
						set_satelite_leaf("tir");
						dofile("data\\7\\16\\level.lua");
						mini_create();			
						for i=1004,1015 do
							speciale_action(2,i,true);
						end;						
					return; end;
					if attachedID~=247 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==4 then
			if attachedID==-1 or attachedID==205 then
			RemoveFromMouse(attachedID);
				if flags.rolloff then
				if not flags.minicomplete4 then
						DarkScreen(true);
						playeffect("mini");
						add_free_leaf("Root","mini4",7,15);
						dofile("./data/7/15/res.lua");
						set_satelite_leaf("tir");
						dofile("data\\7\\15\\level.lua");
						mini_create();
						speciale_action(2,1021,true);
						for i=1004,1013,1 do
							speciale_action(2,i,true);
						end;
					return; end;		
				return; end;		
            CreateWindow(100,100,"212");   			
			return; end;
			return; end;	
			
	if attachedID==-1 then	
	
		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==66 then
				setcurentleaf("gangster",7,0);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;	



			if obj_id==64 then
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"208");
			return;end;
			
			if obj_id==205 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==248 then 
				collaps_obj(obj_id,0,0,10,1);
				
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
				flags.magazin=true;
				if flags.magazin and flags.stvol and flags.priklad then
				   playeffect("1");
				   DeleteElement("gr",248);
				   DeleteElement("gr",249);
				   DeleteElement("gr",250);
				   collaps_obj(247,0,0,10,1);
				   AddElement("gr",247);
				   setcolor(247,0,0,0,0.5,1);
				   MoveObjectToTree(247); 
				return;end;
				playeffect("collaps");
			return; end;
			
			if obj_id==250 then 
				collaps_obj(obj_id,0,0,10,1);
				
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
				flags.stvol=true;
				if flags.magazin and flags.stvol and flags.priklad then
				   playeffect("1");
				   DeleteElement("gr",248);
				   DeleteElement("gr",249);
				   DeleteElement("gr",250);
				   collaps_obj(247,0,0,10,1);
				   AddElement("gr",247);
				   setcolor(247,0,0,0,0.5,1);
				   MoveObjectToTree(247); 
				return;end;
				playeffect("collaps");
				
			return; end;
			
			if obj_id==249 then 
				collaps_obj(obj_id,0,0,10,1);
				
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
				flags.priklad=true;
				if flags.magazin and flags.stvol and flags.priklad then
				   playeffect("1");
				   DeleteElement("gr",248);
				   DeleteElement("gr",249);
				   DeleteElement("gr",250);
				   collaps_obj(247,0,0,10,1);
				   AddElement("gr",247);
				   setcolor(247,0,0,0,0.5,1);
				   MoveObjectToTree(247); 
				return;end;	
				playeffect("collaps");
			return; end;	
			
			if obj_id > 0 and obj_id < 57 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.loc2 = true;		
	return; end;	
end
