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,64);
	return;end;
    idObject=GetRandomObject();	
	if idObject==114 and (not flags.minicomplete7) then
		selectrandomobject(1.5,16);
	return;end	
	if idObject==213 then
	    if flags.minicomplete4 then
		    selectrandomobject(1.5,41);
		return;end;	
		selectrandomobject(1.5,68);
	return;end	
	if idObject==30 and (not flags.will) then
		if flags.minicomplete6 then
		if flags.stepladder then
			if not flags.forwill then
				selectrandomobject(1.5,67);
			return;end	
			selectrandomobject(1.5,63);
		return;end	
		selectrandomobject(1.5,60);
		return;end	
		selectrandomobject(1.5,61);
	return;end		
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==114 and (not flags.minicomplete7) then
		selectrandomobject(1.5,16);
	return;end	
	if idObject==213 then
	    if flags.minicomplete4 then
		    selectrandomobject(1.5,41);
		return;end;	
		selectrandomobject(1.5,68);
	return;end	
	if idObject==30 and (not flags.will) then
		if flags.minicomplete6 then
		if flags.stepladder then
			if not flags.forwill then
				selectrandomobject(1.5,67);
			return;end	
			selectrandomobject(1.5,63);
		return;end	
		selectrandomobject(1.5,60);
		return;end	
		selectrandomobject(1.5,61);
	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==16 then
			if flags.boxout or flags.mapout then
		   			savegame(SaveLevel())

		end;
		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);
			--	flags.whole_darkness=true;
			return;end;
			BlockCursor(false);
		return;end;
		if obj_id==3 then
			CreateWindow(100,100,"196");
			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 then
					flags.levelcomplete=true;
					DarkScreen(true);
				return; end;	
				CreateWindow(100,100,"199");
			return;end;	
			return;end;			
		return;end;		
		if obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(68,"Shelf",0,0);
			StartEmiter("Shelf");
			MoveEmiter("Shelf",715,345);	
			AddParticleToObject(60,"SL",0,0);
			StartEmiter("SL");
			MoveEmiter("SL",780,495)	
			AddParticleToObject(61,"Map",0,0);
			StartEmiter("Map");
			MoveEmiter("Map",340,334)	
	
			AddParticleToObject(16,"Kanc",0,0);
			StartEmiter("Kanc");
			MoveEmiter("Kanc",340,496)		
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.will then
		if flags.stepladder then
			if attachedID==213  then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");
				Set_Cursor(67,3);	
				speciale_action(2,67,true);
				speciale_action(2,63,true);
				Set_Cursor(63,4);
				flags.forwill=true;
				
				--AddParticleToObject(63,"./particles/particle6.psi");
			return; end;
			if attachedID~=213 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"206"); 
			return; end;
		return; end;
			CreateWindow(100,100,"204");
		return;end;		
		return;end;

		
		if obj_id==63 then --замочная скважина
		if not flags.will then
		if flags.stepladder then
			if attachedID==113  then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");
				speciale_action(2,30,true);		
				setcolor(30,0,0,0,1,1);				
				Set_Cursor(63,3);
				flags.will =true;
				StopEmiter("Block");
			return; end;
			if attachedID~=113 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"203"); 
			return; end;
		return; end;
			CreateWindow(100,100,"204");
		return;end;	
		return;end;

		if obj_id==41 then -- сейф
		if not flags.minicomplete5 then
			
			if attachedID==112 or flags.minirun5 then	
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				playeffect("mini");				
				DarkScreen(true);		
				add_free_leaf("Root","mini5",17,16);
				dofile("./data/17/16/res.lua");
				set_satelite_leaf("albert_kab");
				dofile("data\\17\\16\\level.lua");
				mini_create();
				for i=1001,1007,1 do
					speciale_action(2,i,true);
				end;
			return; end;
			if attachedID~=112 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"203"); 
			return; end;
		

		return; end;	
		return; end;	

		if obj_id==60 then
			if attachedID==234 or attachedID==242 then  
				if not flags.wheel then
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						SetAlfaSheet(2.0)
						playeffect("attach");
						flags.wheel=true;
						speciale_action(2,52,true);
				return; end;
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
					flags.stepladder=true;
					Set_Cursor(60,3);
					speciale_action(2,52,true);
					speciale_action(2,53,true);
					speciale_action(2,54,true);
					speciale_action(2,59,true);
					speciale_action(2,60,true);
					StopEmiter("SL");
			return; end;
			if attachedID~=234 and attachedID==242 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"205");
			return; end;
			return;end;

			
		if attachedID==-1 then	
		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","albert_house");
				delete_tree_leaf("Root","albert_kab");
				delete_tree_leaf("Root","anna_room");
				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");
				delete_tree_leaf("Root","mini8");
				delete_tree_leaf("Root","mini9");
				delete_tree_leaf("Root","mini10");
				delete_tree_leaf("Root","comics");
				delete_tree_leaf("Root","comics1");				
				setnextlavel(28);
				loadlavel();	
			return;end;	
			DarkScreen(false);
			speciale_action(2,503,true);
		return;end;		

			if obj_id==64 then
				setcurentleaf("albert_house",17,0);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;	
			
			if obj_id==68 then -- книжные полки
			if not flags.minicomplete4 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini4",17,15);
				dofile("./data/17/15/res.lua");
				set_satelite_leaf("albert_kab");
				dofile("data\\17\\15\\level.lua");
				mini_create();
				for i=1001,1019,1 do
					speciale_action(2,i,true)
				end;
				speciale_action(2,1024,true)
			return; end;	
			return; end;
			
			
			
			if obj_id==61 then -- карта мира
			if not flags.minicomplete6 then
			        DarkScreen(true);
					playeffect("mini");
					add_free_leaf("Root","mini6",17,17);
					dofile("./data/17/17/res.lua");
					set_satelite_leaf("albert_kab");
					dofile("data\\17\\17\\level.lua");
					mini_create();
					for i=1000,1014,1 do
						speciale_action(2,i,true)
					end;
			return; end;	
			return; end;
			
			if obj_id==16 then -- подставка
			if not flags.minicomplete7 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini7",17,18);
				dofile("./data/17/18/res.lua");
				set_satelite_leaf("albert_kab");
				dofile("data\\17\\18\\level.lua");
				mini_create();
				speciale_action(2,1000,true)
				for i=1013,1026,1 do
					speciale_action(2,i,true);
				end;
			return; end;	
			return; end;
			

			
			if obj_id==234 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==242 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==114 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==30 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"211"); 
			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);
		return; end;
	return; end;
	
	if sender==4 then
	    -- CreateWindow(100,100,"199");
		if SLevel==1.0 then return;end;
		flags.loc2 = 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
