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

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

function SelectRandom()

	if flags.loc2 then
		selectrandomobject(1.5,67);
	return;end;
    idObject=GetRandomObject();
	if not flags.curtain and (idObject==36 or idObject==45 or idObject==46 or idObject==56 or idObject==60 or idObject==44) then
		c=GetActivCount();
		if c>6 then
			flags.HintCount=flags.HintCount+1;
			SelectRandom()
		return;end;
		selectrandomobject(1.5,70);
	return;end;
	if (not flags.hat) and (idObject==22 or idObject==216) then
			if not flags.oillamp then
				selectrandomobject(1.5,100);
			return;end
			selectrandomobject(1.5,33);
	return;end
	if idObject==9 and not flags.minicomplete3 then
		selectrandomobject(1.5,30);
	return;end;
	if idObject==245 and not flags.minicomplete4 then	
		if not flags.fourkilo  then
			selectrandomobject(1.5,221);
		return;end;
		if not flags.sevenkilo then
		if (not flags.hat) then
			if not flags.oillamp then
				selectrandomobject(1.5,100);
			return;end
			selectrandomobject(1.5,33);
		return;end
			selectrandomobject(1.5,216);
		return;end;
		 selectrandomobject(1.5,7);
	return;end;
	if idObject==115 then
		flags.HintCount=flags.HintCount+1;
		SelectRandom()	
	return;end;	
    selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)
	if not flags.curtain and (idObject==36 or idObject==45 or idObject==46 or idObject==56 or idObject==60 or idObject==44) then
		selectrandomobject(1.5,70);
	return;end;
	if (not flags.hat) and (idObject==22 or idObject==216) then
			if not flags.oillamp then
				selectrandomobject(1.5,100);
			return;end
			selectrandomobject(1.5,33);
	return;end
	if idObject==9 and not flags.minicomplete3 then
		selectrandomobject(1.5,30);
	return;end;
	if idObject==245 and not flags.minicomplete4 then	
		if not flags.fourkilo  then
			selectrandomobject(1.5,221);
		return;end;
		if not flags.sevenkilo then
		if (not flags.hat) then
			if not flags.oillamp then
				selectrandomobject(1.5,100);
			return;end
			selectrandomobject(1.5,33);
		return;end
			selectrandomobject(1.5,216);
		return;end;
		 selectrandomobject(1.5,7);
	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==28 then
	if obj_id==34 then

		for i=104,107,1 do
			speciale_action(2,i)
			StartAnimation(i);
		end;
	return;end;
	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 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==103 then
			StartAnimation(103,0,6);
		return;end;	
	return;end;


	
	if sender==16 then
		if obj_id==503 or obj_id==7 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);
				Set_Cursor(67,3);				
			return;end;
			BlockCursor(false);
		return;end;
		
		if obj_id==69 then
			speciale_action(2,71,true,3)
			speciale_action(2,69,true,2)		
		return;end;
	return;end;
	
	if sender==15 then
		if obj_id==501 then
			flags.whole_darkness=false;
			BlockCursor(false);
			if flags.loc2 then
			if not flags.allobject2 then
		    flags.allobject2=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;	
	
		if obj_id==503 then
		   BlockCursor(false);
			AddParticleToObject(30,"Svet3",815,583);
			AddParticleToObject(7,"Svet4",173,604);
			AddParticleToObject(33,"Svet5",596,583);
			AddParticleToObject(100,"Svet6",596,583);
			AddParticleToObject(70,"Svet7",299,330);
			StartEmiter("Svet3");
			StartEmiter("Svet4");
			StartEmiter("Svet5");
			StartEmiter("Svet6");
			StartEmiter("Svet7");
			MoveEmiter("Svet3",815,503);
			MoveEmiter("Svet4",173,554);
			MoveEmiter("Svet5",212,356);
			MoveEmiter("Svet6",45,543);		
			MoveEmiter("Svet7",299,330);				
			ShowMenu(true);	
			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==70 then
				if attachedID == 245 then
				    playeffect("attach");	
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					flags.curtain=true;
					setcolor(36,0,0,0,1,1);
					setcolor(45,0,0,0,1,1);
					setcolor(46,0,0,0,1,1);
					setcolor(56,0,0,0,1,1);
					setcolor(60,0,0,0,1,1);
					setcolor(44,0,0,0,1,1);					
					MoveObjectY(34,-88,-700,6);
					speciale_action(2,70,true,2)
					speciale_action(2,69,true,3)
				return; end;		
				if (attachedID ~= 245) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"206");
				return; end;
			return; end;

			if obj_id==100 then
			if not flags.oillamp then
			if attachedID == 151 then
				playeffect("attach");	
			    StopEmiter("Svet6");
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				Set_Cursor(100,3);
				collaps_obj(115,0,0,10,1);
				playeffect("collaps");	
				AddElement("gr",115); 
				MoveObjectToTree(115);
				SetAlfaSheet(2.5)				
				flags.oillamp=true;
			return; end;			
			if (attachedID ~= 151) and (attachedID>-1) then
				CreateWindow(100,100,"205");
			return; end;			
			if attachedID==-1 then
				CreateWindow(100,100,"207");
			return; end;
			return; end;
			return; end;				

			if obj_id==33 then
				if attachedID == 115 then
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					SetAlfaSheet(2.0)
					playeffect("handle");	
					flags.hat=true;		
					StopEmiter("Svet5");					
					Set_Cursor(33,3);
					speciale_action(2,32,true);
					speciale_action(2,33,true);
					speciale_action(2,25,true);
					speciale_action(2,22,true);
					speciale_action(2,216,true);
					setcolor(22,0,0,0,1,1);
					setcolor(216,0,0,0,1,1);
				return; end;
				
				if (attachedID ~= 115) and (attachedID>-1) then
                    CreateWindow(100,100,"205");
				return; end;
				
				if attachedID==-1 then
                    CreateWindow(100,100,"208");
				return; end;
			return; end;	

			if obj_id==7 then
			if attachedID==-1 or attachedID==221 or attachedID==216 then
				RemoveFromMouse(attachedID);
				if not flags.minicomplete4 then 
				if flags.fourkilo and flags.sevenkilo then	
					DeleteElement("gr",221)
					DeleteElement("gr",216)				
					DarkScreen(true);		
					playeffect("mini");			
					add_free_leaf("Root","mini4",1,15);
					dofile("./data/1/15/res.lua");
					set_satelite_leaf("kulisi");
					dofile("data\\1\\15\\level.lua");
					mini_create();
					for i=1000,1010,1 do
						speciale_action(2,i,true);
					end;				
				return; end;
				CreateWindow(100,100,"209");
				return; end;	
			return; end;
			return; end;
			
	if attachedID==-1 then	
	

			if obj_id==101 then
				playeffect("spring");
			    StartAnimation(101,0,9);
			return;end;
			
			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==67 then
				setcurentleaf("grim",1,0);
				SwitchToSheet("re");
			return; end;
			
			
			if obj_id==30 then
			if not flags.minicomplete3 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini3",1,14);
				dofile("./data/1/14/res.lua");
				set_satelite_leaf("kulisi");
				dofile("data\\1\\14\\level.lua");
				mini_create();
				speciale_action(2,1000);
				for i=1008,1020,1 do
					speciale_action(2,i,true);
				end;			
			return; end;	
			return; end;

	


			if obj_id==36 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==9 then
				StopParticleSystem(9);
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"210");
				
			return; end;

			if obj_id==22 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==151 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==245 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==221 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);
				flags.fourkilo=true;
			return; end;			
	
			
			if obj_id==216 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);
				flags.sevenkilo=true;
			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.loc2 = true;
	return; end;		
end
