function SheetSwitched (ncount)
	StopSheet=true;
return;end;

function AlarmSound()
	playeffect("alarm");
end;

function Timer(ncount, Param1)
	if not StopSheet then
		AlfingSheet();
		StopSheet=false;
	return;end;
return;end;

function SelectRandom()
	if flags.loc1 then
		selectrandomobject(1.5,87);
	return;end;
    idObject=GetRandomObject();
	if idObject==5 then
	    selectrandomobject(1.5,6);
	return;end;
	if idObject==16 then
	    selectrandomobject(1.5,62);
	return;end;
	if idObject==48 then
	    selectrandomobject(1.5,14);
	return;end;	
    selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)
	if idObject==5 then
	    selectrandomobject(1.5,6);
	return;end;
	if idObject==16 then
	    selectrandomobject(1.5,62);
	return;end;
	if idObject==48 then
	    selectrandomobject(1.5,14);
	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.allobject1 then
		if not flags.whole_darkness then
		    flags.allobject1=true;	
			if flags.loc1 and flags.loc2 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==1 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);
			return;end;
			BlockCursor(false);
		return;end;
	return;end;

	
	if sender==15 then
		if obj_id==501 then
		    flags.whole_darkness=false;
			BlockCursor(false);
			if flags.minitext3 then
				CreateWindow(100,100,"211");
				
				flags.minitext3=false;
				savegame(SaveLevel())
			end;			
			if flags.minitext1 then
				CreateWindow(100,100,"212");
				flags.minitext1=false;
				savegame(SaveLevel())
			end;
				if flags.loc1 then
				if not flags.allobject1 then
				if not flags.whole_darkness then
					flags.allobject1=true;	
					if flags.loc1 and flags.loc2 then
						flags.levelcomplete=true;
						DarkScreen(true);
						ShowMenu(false);
						
					return; end;
					CreateWindow(100,100,"199");
				return; end;	
				return;end;
				return;end;

		return;end;
		
		if obj_id==503 then
		   BlockCursor(false);
			ShowMenu(true);

			StartAnimation(101);
			StartAnimation(102);
			AddParticleToObject(6,"Svet1",122,450);
			AddParticleToObject(62,"Svet",215,590);
			AddParticleToObject(14,"Svet2",380,250);
			StartEmiter("Svet");
			StartEmiter("Svet1");
			StartEmiter("Svet2");
			MoveEmiter("Svet1",122,450);
			MoveEmiter("Svet",215,590);
			MoveEmiter("Svet2",380,250);
			AddParticleToObject(8,"stakan",215,590);
			StartEmiter("stakan");
			MoveEmiter("stakan",705,529);
			AddParticleToObject(70,"pil",0,0,0,0);
			StartEmiter("pil");	
			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 attachedID==-1 then	

			
			if obj_id==501 then	
				if flags.levelcomplete then
					delete_tree_leaf("Root","grim");
					delete_tree_leaf("Root","kulisi");
					delete_tree_leaf("Root","mini");
					delete_tree_leaf("Root","mini1");
					delete_tree_leaf("Root","mini2");
					delete_tree_leaf("Root","mini3");
					delete_tree_leaf("Root","mini4");
					setnextlavel(2);
					loadlavel();		
				return;end;				
					DarkScreen(false);
					speciale_action(2,503,true);
			return;end;
			
			if obj_id==87 then
			
			   if flags.firstloc1==true then					
					BlockCursor(true)
					setcurentleaf("kulisi",1,1);		
					
					DarkScreen(true)
					SwitchToSheet("re");

					flags.firstloc1 = false;
					ShowMenu(false);
					speciale_action(2,503,true);						
				return; end;	
				setcurentleaf("kulisi",1,1);
				SwitchToSheet("re");
				savegame(SaveLevel())
			return; end;
			
			
			
			if obj_id==62 then
			if not flags.minicomplete then		
					DarkScreen(true);
					playeffect("mini");
					add_free_leaf("Root","mini",1,11);-- Добавляет чистый лист
					dofile("./data/1/11/res.lua");
					set_satelite_leaf("grim");
					dofile("data\\1\\11\\level.lua");
					mini_create();
					speciale_action(2,100,true);
					speciale_action(2,1000,true);
					for i=1,15,1 do
						speciale_action(2,i,true);
					end;

			return; end;	
			return; end;
			
			if obj_id==14 then
			if not flags.minicomplete1 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini1",1,12);
				dofile("./data/1/12/res.lua");
				set_satelite_leaf("grim");
				dofile("data\\1\\12\\level.lua");
				mini_create();			
				speciale_action(2,1005,true);
			return; end;	
			return; end;
			
			if obj_id==6 then
			if not flags.minicomplete2 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini2",1,13);
				dofile("./data/1/13/res.lua");
				set_satelite_leaf("grim");
				dofile("data\\1\\13\\level.lua");
				mini_create();
				speciale_action(2,1009,true);
				speciale_action(2,1001,true);
				speciale_action(2,1002,true);
				speciale_action(2,1003,true);
				speciale_action(2,1004,true);
				speciale_action(2,1008,true);
			
			return; end;	
			return; end;

			if obj_id==8 then
				StopEmiter("stakan");
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"202");
				
			return; end;

			if obj_id==91 then
				speciale_action(2,91)
				collaps_obj(3,0,0,10,1);
				playeffect("collaps");	
				setcolor(3,0,0,0,0.5,1);
				CreateWindow(100,100,"200");
			return; end;

			if obj_id==92 then
				speciale_action(2,92)
				collaps_obj(7,0,0,10,1);
				playeffect("collaps");	
				setcolor(7,0,0,0,0.5,1);
				CreateWindow(100,100,"203");
			return; end;
			
			if obj_id==3 then
				speciale_action(2,91,true)
			return; end;
			
			if obj_id==7 then
				speciale_action(2,92,true)
			return; end;
			
			if obj_id==59 then
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"204");
			return; end;

			if obj_id==50 then
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"201");
			return; end;	

			if obj_id==55 then
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				setcolor(obj_id,0,0,0,0.5,1);
			return; end;			

			if obj_id==5 then
				StopParticleSystem(5);
				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==16 then
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"212");
			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	
	    if SLevel==1.0 then return;end;
	    flags.loc1 = true;
	return; end;		
end
