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

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

function SelectRandom()
    idObject=GetRandomObject();	
	if idObject==100 then
		selectrandomobject(1.5,59);
	return;end	
	if idObject==48 then
		if not flags.spool then
		   selectrandomobject(1.5,23);
		return;end;
		if not flags.cane then
		   selectrandomobject(1.5,39);
		return;end;
		if not flags.earring then
		   selectrandomobject(1.5,11);
		return;end;		
	return;end;
	if idObject==17 and (not flags.minicomplete) then
		selectrandomobject(1.5,62);
	return;end		
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==100 then
		selectrandomobject(1.5,59);
	return;end	
	if idObject==48 then
		if not flags.spool then
		   selectrandomobject(1.5,23);
		return;end;
		if not flags.cane then
		   selectrandomobject(1.5,39);
		return;end;
		if not flags.earring then
		   selectrandomobject(1.5,11);
		return;end;		
	return;end;
	if idObject==17 and (not flags.minicomplete) then
		selectrandomobject(1.5,62);
	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 then
	if flags.levelcomplete then
		DarkScreen(true);
	return;end;
	return;end;

	
	if sender==26 then
		if obj_id==1 then
			if flags.all then
					flags.levelcomplete=true;
					ShowMenu(false);
					DarkScreen(true);
				return;end;			
		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
		   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==10 then
			CreateWindow(100,100,"198");
			BlockCursor(false);
		return;end;										
	return;end;
	
	if sender==15 then

		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			if flags.minitext1 then
			   flags.minitext1=false;
			   CreateWindow(100,100,"206",1);  
			   savegame(SaveLevel())
			return;end;
		return;end;			
		if obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(62,"Mirror",0,0);
			StartEmiter("Mirror");
			MoveEmiter("Mirror",69,408);	
			AddParticleToObject(59,"Aqua",0,0);
			StartEmiter("Aqua");
			MoveEmiter("Aqua",775,340)	
			AddParticleToObject(52,"Map",0,0);
			StartEmiter("Map");
			MoveEmiter("Map",852,84)
			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==52 then --карта города
			if flags.chair then
				if attachedID==13 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					
					collaps_obj(obj_id,0,0,10,1);
					AddElement("gr",obj_id);
					setcolor(obj_id,0,0,0,0.5,1);
					MoveObjectToTree(obj_id);
					Set_Cursor(52,3);		
					flags.map=true;
					StopEmiter("Map");
					if flags.newspaper then
						DeleteElement("gr",17);
						DeleteElement("gr",52);		
						DarkScreen(true);	
						playeffect("mini");	
						add_free_leaf("Root","mini1",18,12);
						dofile("./data/18/12/res.lua");
						set_satelite_leaf("mother_room");
						dofile("data\\18\\12\\level.lua");
						mini_create();	
						for i=1001,1008,1 do
							speciale_action(2,i,true)
						end;
						for i=1010,1012,1 do
							speciale_action(2,i,true)
						end;						
					return;end;
					SetAlfaSheet(2.5)
					playeffect("collaps");
				return; end;
				if attachedID~=13 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"201"); 
				return; end;
			return; end;
				if attachedID==54 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
					speciale_action(2,53,true);
					flags.chair=true;
				return; end;
				if attachedID~=54 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"202"); 
				return; end;	
		return;end;		

		if obj_id==59 then --аквариум
		if not flags.wardrobe then
			if attachedID==48 or flags.minirun2 then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.5)
				playeffect("attach");
				flags.wardrobe=true;
				speciale_action(2,1);
				collaps_obj(100,0,0,10,1);
				AddElement("gr",100);
				setcolor(100,0,0,0,0.5,1);
				MoveObjectToTree(100); 
				 CreateWindow(100,100,"205",1);  
				Set_Cursor(59,3);
				StopEmiter("Aqua");
			return; end;
			if attachedID~=47 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 attachedID==-1 then	
	

		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","mother_room");
				delete_tree_leaf("Root","mini1");
				delete_tree_leaf("Root","mini2");
				delete_tree_leaf("Root","mini");
				DeleteElement("gr",100);
				setnextlavel(19);
				loadlavel();
			return;end;	
			DarkScreen(false);
			speciale_action(2,503,true);
		return;end;			
		
		if obj_id==62 then -- трюмо
		if not flags.minicomplete then
		    DarkScreen(true);
			playeffect("mini");	
			add_free_leaf("Root","mini",18,11);
			dofile("./data/18/11/res.lua");
			set_satelite_leaf("mother_room");
			dofile("data\\18\\11\\level.lua");
			mini_create();
			-- speciale_action(2,1000,true);
			-- for i=1001,1040,1 do
				-- speciale_action(2,i,true)
			-- end;
			-- for i=1029,1040,1 do
				-- speciale_action(2,i,true)
			-- end;
		return; end;	
		return; end;



		
		if obj_id==54 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==13 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==17 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.newspaper=true;
			if flags.map then
				DeleteElement("gr",17);
				DeleteElement("gr",52);			
				DarkScreen(true);
				add_free_leaf("Root","mini1",18,12);
				dofile("./data/18/12/res.lua");
				set_satelite_leaf("mother_room");
				dofile("data\\18\\12\\level.lua");
				mini_create();		
				for i=1001,1008,1 do
					speciale_action(2,i,true)
				end;
				for i=1010,1012,1 do
					speciale_action(2,i,true)
				end;					
			return;end;
		return; end;

		if obj_id==100 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); 
			CreateWindow(100,100,"205");  
		return; end;		
		
		if obj_id==25 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==13 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==23 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.spool=true;
			if flags.cane and flags.earring then
				DeleteElement("gr",23);
				DeleteElement("gr",65);
				DeleteElement("gr",11);
				collaps_obj(48,0,0,10,1);
				AddElement("gr",48);
				setcolor(48,0,0,0,0.5,1);
				MoveObjectToTree(48);
				playeffect("1");				
			return; end;
			playeffect("collaps");
		return; end;	
		
		if obj_id==39 then 
			collaps_obj(obj_id,0,0,10,1);
			collaps_obj(65,0,0,10,1);
			AddElement("gr",65);
			SetAlfaSheet(2.5)
			setcolor(obj_id,0,0,0,0.5,1);
			MoveObjectToTree(65); 
			flags.cane=true;
			if flags.spool and flags.earring then
				DeleteElement("gr",23);
				DeleteElement("gr",65);
				DeleteElement("gr",11);
				collaps_obj(48,0,0,10,1);
				AddElement("gr",48);
				setcolor(48,0,0,0,0.5,1);
				MoveObjectToTree(48);	
				playeffect("1");				
			return; end;
			playeffect("collaps");
		return; end;
		
		if obj_id==11 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.earring=true;
			if flags.cane and flags.spool then
				DeleteElement("gr",23);
				DeleteElement("gr",65);
				DeleteElement("gr",11);
				playeffect("1");
				collaps_obj(48,0,0,10,1);
				AddElement("gr",48);
				setcolor(48,0,0,0,0.5,1);
				MoveObjectToTree(48);				
			return; end;
			playeffect("collaps");
		return; end;				
-------------------------------------------------
		
		if obj_id > 0 and obj_id < 52 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
	flags.all=true;
	if flags.minicomplete1 then
		flags.levelcomplete=true;
	return;end;	
	return; end;		
end
