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 flags.lock1 then
		selectrandomobject(1.5,53);
	return;end;	
	selectrandomobject(1.5,54);
	return;end;
    idObject=GetRandomObject();	
	if idObject==208 and (not flags.minicomplete) then
		if GetActivCount()>1 then
			flags.HintCount=flags.HintCount+1;
			SelectRandom()		
		return;end;			
	if not flags.bolti then
		selectrandomobject(1.5,27);
	return;end	
	selectrandomobject(1.5,31);
	return;end	
	if idObject==223 then
	   if not flags.bolt1 then
			selectrandomobject(1.5,213);
	   return;end;
	   if not flags.bolt2 then
			selectrandomobject(1.5,224);
	   return;end;	
	   if not flags.bolt3 then
			selectrandomobject(1.5,225);
	   return;end;	  
	   if not flags.bolt4 then
	        selectrandomobject(1.5,226);
	   return;end;	 
	   if not flags.bolt5 then
			selectrandomobject(1.5,227);
	   return;end;	   
	return;end;
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==208 and (not flags.minicomplete) then	
	if not flags.bolti then
		selectrandomobject(1.5,27);
	return;end	
	selectrandomobject(1.5,31);
	return;end	
	if idObject==223 then
	   if not flags.bolt1 then
			selectrandomobject(1.5,213);
	   return;end;
	   if not flags.bolt2 then
			selectrandomobject(1.5,224);
	   return;end;	
	   if not flags.bolt3 then
			selectrandomobject(1.5,225);
	   return;end;	  
	   if not flags.bolt4 then
	        selectrandomobject(1.5,226);
	   return;end;	 
	   if not flags.bolt5 then
			selectrandomobject(1.5,227);
	   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.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==35 then
		if obj_id==106 then
			StartAnimation(106,0,6)
		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
			--flags.whole_darkness=true;
		   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==1 then
			CreateWindow(100,100,"198");
			BlockCursor(false);
		return;end;							
	return;end;
	
	if sender==15 then
		if flags.bikeout then
		   savegame(SaveLevel())
		end;
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			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(27,"Vilka",0,0);
			StartEmiter("Vilka");
			MoveEmiter("Vilka",343,535);	
			AddParticleToObject(54,"Zamok",0,0);
			StartEmiter("Zamok");
			MoveEmiter("Zamok",984,358)		
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==54 then				
				if attachedID==208 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("door");
					speciale_action(2,53,true);
					speciale_action(2,54,true);
					Set_Cursor(54,3)
					StopEmiter("Zamok");
					Set_Cursor(53,1)	
					flags.lock1=true;	
				return; end;
				if attachedID~=208 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"201");
				return; end;
			return; end;
			
			if obj_id==27 then --вилка
			if not flags.bolti then
				if flags.bolti1 then
					if attachedID==219 then    
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						SetAlfaSheet(2.0)
						playeffect("attach");
						-- прикручиваем колесо
						flags.bolti1=false;
						flags.bolti=true
						Set_Cursor(27,3);
						StopEmiter("Vilka");
						AddParticleToObject(31,"Bike",519,582);
						StartEmiter("Bike");
						MoveEmiter("Bike",519,582);						
						Set_Cursor(31,2);
						--AddParticleToObject(31,"./particles/particle2.psi");
					return; end;
					if attachedID~=219 and attachedID>-1 then
						CreateWindow(100,100,"200");     
					return; end;
					if attachedID ==-1 then		
						CreateWindow(100,100,"203");
					return; end;				
				return;end;			
				if flags.wheel then
					if attachedID==223 then    
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						SetAlfaSheet(2.0)
						playeffect("attach");
						-- прикручиваем колесо
						flags.bolti1=true;
						flags.wheel=false;	
						CreateWindow(100,100,"203");						
					return; end;
					if attachedID~=223 and attachedID>-1 then
						CreateWindow(100,100,"200");     
					return; end;
					if attachedID ==-1 then		
						CreateWindow(100,100,"204");   
					return; end;				
				return;end;
					if attachedID==232 then    
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						SetAlfaSheet(2.0)
						playeffect("attach");
						-- одеваем колесо на мотоциклж
						flags.wheel=true;
						speciale_action(2,28,true);
						speciale_action(2,29,true);
						speciale_action(2,31,true);
						speciale_action(2,1031);
					--	Set_Cursor(31,2)
						--AddParticleToObject(31,"./particles/particle2.psi",400,364,737,669);
					CreateWindow(100,100,"204");   
					return; end;
					if attachedID~=232 and attachedID>-1 then
						CreateWindow(100,100,"200");     
					return; end;
					if attachedID ==-1 then		
						CreateWindow(100,100,"202"); 
					return; end;
			return; end;		
			return; end;	

	
	if attachedID==-1 then		

		if obj_id==104 then
		    playeffect("tiski");
			StartAnimation(104,0,8);
		return;end;
		if obj_id==105 then
			 playeffect("horn");
			StartAnimation(105,0,5)
		return;end;		
		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","garage");
				delete_tree_leaf("Root","killer");
				delete_tree_leaf("Root","gym");
				delete_tree_leaf("Root","mini1");
				delete_tree_leaf("Root","mini2");
				delete_tree_leaf("Root","mini3");
				delete_tree_leaf("Root","mini");
				setnextlavel(15);
				loadlavel();	
				ShowMenu(false);
			return;end;	
			DarkScreen(false);
			speciale_action(2,503,true);
		return;end;				
		
		if obj_id==53 then
		if flags.firstloc2==true then
				BlockCursor(true)
				setcurentleaf("killer",14,1);
				
				SwitchToSheet("re");
				flags.firstloc2 = false;
				DarkScreen(true);
				speciale_action(2,503,true);
				speciale_action(4,503)
			return; end;
				setcurentleaf("killer",14,1);
				savegame(SaveLevel())
				SwitchToSheet("re");
		return; end;
					
			if obj_id==31 then --мотоцикл
				if flags.bolti then
				if not flags.minicomplete then
					DarkScreen(true);
					playeffect("mini");
					add_free_leaf("Root","mini",14,11);
					dofile("./data/14/11/res.lua");
					set_satelite_leaf("garage");
					dofile("data\\14\\11\\level.lua");
					mini_create();	
					for i=1000,1013,1 do
						speciale_action(2,i,true)
					end;
				return; end;
				return; end;
				CreateWindow(100,100,"204");
			return; end;	
			
		
			
			if obj_id==232 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==219 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==208 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==6 then 
				-- collaps_obj(obj_id,0,0,10,1);
				-- AddElement("gr",obj_id);
				-- setcolor(obj_id,0,0,0,0.5,1);
				-- MoveObjectToTree(obj_id); 
			-- return; end;
			
			-------------болты-------------------
			if obj_id==213 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.bolt1=true;
				if flags.bolt2 and flags.bolt3 and flags.bolt4 and flags.bolt5 then
					DeleteElement("gr",213);
					DeleteElement("gr",224);
					DeleteElement("gr",225);
					DeleteElement("gr",226);					
					DeleteElement("gr",227);
					playeffect("1");
					collaps_obj(223,0,0,10,1);
					AddElement("gr",223);
					setcolor(223,0,0,0,0.5,1);
					MoveObjectToTree(223);
				return; end;
				playeffect("collaps");
			return; end;
			
			if obj_id==224 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.bolt2=true;
				if flags.bolt1 and flags.bolt3 and flags.bolt4 and flags.bolt5 then
					DeleteElement("gr",213);
					DeleteElement("gr",224);
					DeleteElement("gr",225);
					DeleteElement("gr",226);					
					DeleteElement("gr",227);
					playeffect("1");
					collaps_obj(223,0,0,10,1);
					AddElement("gr",223);
					setcolor(223,0,0,0,0.5,1);
					MoveObjectToTree(223);
				return; end;
				playeffect("collaps");
			return; end;
			
			if obj_id==225 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.bolt3=true;
				if flags.bolt2 and flags.bolt1 and flags.bolt4 and flags.bolt5 then
					DeleteElement("gr",213);
					DeleteElement("gr",224);
					DeleteElement("gr",225);
					DeleteElement("gr",226);					
					DeleteElement("gr",227);
					playeffect("1");
					collaps_obj(223,0,0,10,1);
					AddElement("gr",223);
					setcolor(223,0,0,0,0.5,1);
					MoveObjectToTree(223);
				return; end;	
				playeffect("collaps");				
			return; end;
			
			if obj_id==226 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.bolt4=true;
				if flags.bolt2 and flags.bolt3 and flags.bolt1 and flags.bolt5 then
					DeleteElement("gr",213);
					DeleteElement("gr",224);
					DeleteElement("gr",225);
					DeleteElement("gr",226);					
					DeleteElement("gr",227);
					playeffect("1");
					collaps_obj(223,0,0,10,1);
					AddElement("gr",223);
					setcolor(223,0,0,0,0.5,1);
					MoveObjectToTree(223);
				return; end;
				playeffect("collaps");
			return; end;
			
			if obj_id==227 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.bolt5=true;
				if flags.bolt2 and flags.bolt3 and flags.bolt4 and flags.bolt1 then
					DeleteElement("gr",213);
					DeleteElement("gr",224);
					DeleteElement("gr",225);
					DeleteElement("gr",226);					
					DeleteElement("gr",227);
					playeffect("1");
					collaps_obj(223,0,0,10,1);
					AddElement("gr",223);
					setcolor(223,0,0,0,0.5,1);
					MoveObjectToTree(223);
				return; end;
				playeffect("collaps");
			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 sender==14 then
	StopSheet=true;
		if obj_id>0 then
			addObjectToMouse(obj_id);
			StopSheet=true;
		return; end;
	return; end;
	
	if sender==4 then
	    -- CreateWindow(100,100,"199");
		if SLevel==1.0 then return;end;
		flags.loc1 = true;
		-- if flags.loc1 and flags.loc2 and flags.loc3 then
			-- flags.levelcomplete=true;
			-- speciale_action(2,501,true,2);
		-- return; end;			
	return; end;	
end
