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 not flags.caseopen then
		selectrandomobject(1.5,9);
	return;end;
	if not flags.minicomplete then
		if flags.handle and not flags.glass_in then
			selectrandomobject(1.5,30);
		return;end;
		selectrandomobject(1.5,27);
	return;end;
	if not flags.minicomplete1 then
		selectrandomobject(1.5,19);
	return;end;	
	if not flags.minicomplete2 then
		if flags.ashes and not flags.ash_in then
			selectrandomobject(1.5,40);
		return;end;
		selectrandomobject(1.5,14);
	return;end;		
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==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==21 then
			BlockCursor(false);
			CreateWindow(100,100,"198");
		return;end;		
	return;end;

	if sender==15 then
	
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			if flags.minitext1 then
				CreateWindow(100,100,"201",1);
				flags.minitext1=false;
				savegame(SaveLevel())
			end;
			if flags.minitext2 then
			    CreateWindow(100,100,"202",1);
				flags.minitext2=false;
				savegame(SaveLevel())
			end;
			if flags.minitext3 then
			    CreateWindow(100,100,"203",1);
				flags.minitext3=false;
				savegame(SaveLevel())
			end;			
		return;end;	
		
		if obj_id==503 then
			BlockCursor(false);
			ShowMenu(true);
			AddParticleToObject(37,"water",0,0,0,0);
			AddParticleToObject(35,"probirka_b",0,0,0,0);
			AddParticleToObject(36,"probirka_y",0,0,0,0);
			AddParticleToObject(41,"banka",0,0,0,0);	
			StartEmiter("water");
			MoveEmiter("water",126,391);			
			StartEmiter("probirka_b");
			MoveEmiter("probirka_b",202,283);
			StartEmiter("probirka_y");
			MoveEmiter("probirka_y",365,183);
			StartEmiter("banka");
			MoveEmiter("banka",400,189);	
			AddParticleToObject(9,"Bag",0,0);
			StartEmiter("Bag");
			MoveEmiter("Bag",213,474);
savegame(SaveLevel())			
		return;end;
	return;end;	
	

	
	if sender==26 then
		if obj_id==1 then
			if flags.minicomplete and flags.minicomplete1 and flags.minicomplete2 then
			    flags.levelcomplete=true;
				ShowMenu(false);
				DarkScreen(true)
			return; end;	
		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==27 then
			if not flags.minicomplete then
			if not flags.handle then 
				if attachedID==101 or attachedID==106 then
					playeffect("attach");
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					flags.handle=true;
					CreateWindow(100,100,"83");
				return; end;	
				if (attachedID ~= 101) and (attachedID ~= 106)and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"211");
				return; end;
			return;end;	
				if attachedID==106 or attachedID==101 or flags.minirun1 then
				   	RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					Set_Cursor(27,2);
					DarkScreen(true);
					playeffect("mini");
					add_free_leaf("Root","mini",6,11);
					dofile("./data/6/11/res.lua");
					set_satelite_leaf("photolab");
					dofile("data\\6\\11\\level.lua");
					mini_create();
					speciale_action(2,1000,true)
					for i=1002,1004,1 do
						speciale_action(2,i,true)
					end;
					for i=1006,1009,1 do
						speciale_action(2,i,true)
					end;
				return; end;	
				if (attachedID ~= 106) and (attachedID ~= 101) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"83");
				return; end;
			return;end;
			return;end;

			if obj_id==14 then
			if not flags.minicomplete2 then
			if not flags.ashes then
				if attachedID==104 or attachedID==102  then
				   	RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					flags.ashes=true;
					CreateWindow(100,100,"83");
					playeffect("attach");
				return; end;	
				if (attachedID ~= 104) and (attachedID ~= 102) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"207");
				return; end;				
			return; end;
				if attachedID==104 or attachedID==102 or flags.minirun3  then
				   	RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					Set_Cursor(14,2);
					DarkScreen(true);
					playeffect("mini");
					add_free_leaf("Root","mini1",6,13);
					dofile("./data/6/13/res.lua");
					set_satelite_leaf("photolab");
					dofile("data\\6\\13\\level.lua");
					mini_create();
					for i=1000,1002,1 do
						speciale_action(2,i,true)
					end;
					for i=1004,1005,1 do
						speciale_action(2,i,true)
					end;
				return; end;	
				if (attachedID ~= 104) and (attachedID ~= 102) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"83");
				return; end;			
			return; end;
			return; end;
			
			if obj_id==19 then
			if not flags.minicomplete1 then
				if attachedID==103 or flags.minirun2 then
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);	
					playeffect("mini");
					Set_Cursor(19,2);
					DarkScreen(true);
					add_free_leaf("Root","mini2",6,12);
					dofile("./data/6/12/res.lua");
					set_satelite_leaf("photolab");
					dofile("data\\6\\12\\level.lua");
					mini_create();
					speciale_action(2,1000,true)
					speciale_action(2,1001,true)
					speciale_action(2,1003,true)
					speciale_action(2,1004,true)
				return; end;			
				if (attachedID ~= 103) and (attachedID>-1) then
					CreateWindow(100,100,"205");
				return; end;				
				if attachedID==-1 then
					CreateWindow(100,100,"213");
				return; end;					
			return; end;	
			return; end;

		if attachedID==-1 then

			if obj_id==501 then
				if flags.levelcomplete then
					delete_tree_leaf("Root","photolab")
					delete_tree_leaf("Root","mini");
					delete_tree_leaf("Root","mini1");
					delete_tree_leaf("Root","mini2");
					delete_tree_leaf("Root","comics");
					setnextlavel(7);
					loadlavel();
				return;end;		
				DarkScreen(false);
				speciale_action(2,503,true);
			return;end;

			if obj_id==9 then
				if not flags.caseopen then
				playeffect("caseopen");
					speciale_action(2,9,true);
					speciale_action(2,10,true);
					AddElement("gr",101);
					AddElement("gr",102);
					AddElement("gr",103);
					MoveObjectToTree(101);
					MoveObjectToTree(102);
					MoveObjectToTree(103);
					flags.caseopen=true;
					AddParticleToObject(27,"Powder",0,0);
					AddParticleToObject(19,"MGlass",0,0);
					AddParticleToObject(14,"Micro",0,0);
					AddParticleToObject(30,"Glass",0,0);
					AddParticleToObject(40,"Ash",0,0);					
					StartEmiter("Powder");
					StartEmiter("MGlass");
					StartEmiter("Micro");
					StartEmiter("Glass");
					StartEmiter("Ash");					
					MoveEmiter("Powder",588,358);
					MoveEmiter("MGlass",589,446);
					MoveEmiter("Micro",430,420);	
					MoveEmiter("Glass",61,417);
					MoveEmiter("Ash",685,211);					
				return;end;
			return;end;

				if obj_id==10 then

				return;end;		
			
			
			if obj_id==100 then
				CreateWindow(100,100,"208");
			return; end;	
			
			if obj_id==1 then
				CreateWindow(100,100,"209");
			return; end;

			if obj_id==30 then
			if not flags.minicomplete then
			    StopEmiter("Glass")
				AddElement("gr",106);
				speciale_action(2,30);	
				StopParticleSystem(30);	
				flags.glass_in=true;				
			return; end;	
			CreateWindow(100,100,"210");			
			return; end;			

			if obj_id==2 then

				CreateWindow(100,100,"215");
			return; end;	
			
			if obj_id==8 then
				CreateWindow(100,100,"216");
			return; end;
			
			if obj_id==42 then
				CreateWindow(100,100,"214");
			return; end;

			if obj_id==40 then
			if not flags.minicomplete2 then
				StopEmiter("Ash")
				AddElement("gr",104);
				speciale_action(2,40);		
				flags.ash_in=true;
			return; end;
				CreateWindow(100,100,"217");
			return; end;			

			if obj_id==5 then
				CreateWindow(100,100,"201");
			return; end;

			if obj_id==28 then
				CreateWindow(100,100,"202");
			return; end;
			
			if obj_id==16 then
				CreateWindow(100,100,"203");
			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		

	return; end;	
end
