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.loc1 then
		if not flags.wardrobe then
			 selectrandomobject(1.5,68);
		return;end;
		if not flags.wardrobeopen then
			 selectrandomobject(1.5,66);
		return;end;
		if not flags.loc2 then
			selectrandomobject(1.5,71);
		return;end;
		selectrandomobject(1.5,62);
	return;end;
    idObject=GetRandomObject();	
	if idObject==172 then
		if not flags.cloth1 then
			selectrandomobject(1.5,57);
		return;end;
		if not flags.cloth2 then
			selectrandomobject(1.5,58);
		return;end;
		if not flags.cloth3 then
		    selectrandomobject(1.5,59);
		return;end;		
	return;end;
	if idObject==112  then
		if flags.minicomplete2  then
		    selectrandomobject(1.5,56);
		return;end;
		selectrandomobject(1.5,63);
	return;end	
	if idObject==113 and (not flags.minicomplete3) then
		    selectrandomobject(1.5,69);
	return;end	
	if idObject==160 and (not flags.minicomplete) then	
		selectrandomobject(1.5,40);
	return;end		
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==172 then
		if not flags.cloth1 then
			selectrandomobject(1.5,57);
		return;end;
		if not flags.cloth2 then
			selectrandomobject(1.5,58);
		return;end;
		if not flags.cloth3 then
		    selectrandomobject(1.5,59);
		return;end;		
	return;end;
	if idObject==112  then
		if flags.minicomplete2  then
		    selectrandomobject(1.5,56);
		return;end;
		selectrandomobject(1.5,63);
	return;end	
	if idObject==113 and (not flags.minicomplete3) then
		    selectrandomobject(1.5,69);
	return;end	
	if idObject==160 and (not flags.minicomplete) then	
		selectrandomobject(1.5,40);
	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.whole_darkness then
		if not flags.allobject1 then
		    flags.allobject1=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 obj_id==53 and  flags.curtout 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);
			return;end;
			BlockCursor(false);
		return;end;
		if obj_id==3 then
			CreateWindow(100,100,"198");
			BlockCursor(false);
		return;end;								
	return;end;
	
	if sender==15 then
		if obj_id==53 and  flags.curtout then
		savegame(SaveLevel())
		end;	
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			if flags.minitext then
				CreateWindow(100,100,"215");
				flags.minitext=false;
				
			return;end;			
			if flags.loc1 then
			if not flags.allobject1 then
				flags.allobject1=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(40,"Chess",0,0);
			StartEmiter("Chess");
			MoveEmiter("Chess",721,489);	
			AddParticleToObject(69,"Plitka",0,0);
			StartEmiter("Plitka");
			MoveEmiter("Plitka",402,562)	
			AddParticleToObject(63,"Pict",0,0);
			StartEmiter("Pict");
			MoveEmiter("Pict",903,336)	
			AddParticleToObject(1,"Door",0,0);
			StartEmiter("Door");
			MoveEmiter("Door",660,345)		
			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==68 then --закрытый гардероб
			if attachedID==160 then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("door");	
				flags.wardrobe=true;
				MoveEmiter("Door",688,265);
				speciale_action(2,66,true);
				speciale_action(2,68,true);
				Set_Cursor(68,3);
				Set_Cursor(66,2);
				--AddParticleToObject(66,"./particles/particle6.psi");
			return; end;
			if attachedID~=160 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"201");  
			return; end;
		return;end;	

		if obj_id==66 then --открытый гардероб
			if attachedID==172 then 
				flags.wardrobeopen=true;
				StopEmiter("Door");				
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");
				speciale_action(2,66,true);
				speciale_action(2,71,true);
				Set_Cursor(71,1);
				Set_Cursor(66,3);
			return; end;
			if attachedID~=172 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"212");  
			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==71 then
				if flags.firstloc2==true then
					BlockCursor(true)
					setcurentleaf("albert_kab",17,1);
					
					SwitchToSheet("re");
					flags.firstloc2 = false;
					DarkScreen(true);
					speciale_action(2,503,true);
					speciale_action(4,503)
				return; end;
				setcurentleaf("albert_kab",17,1);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;		
			
			if obj_id==62 then
				if flags.firstloc3==true then
					BlockCursor(true)
					setcurentleaf("anna_room",17,2);
					
					SwitchToSheet("re");
					flags.firstloc3 = false;
					DarkScreen(true);
					speciale_action(2,503,true);					
					speciale_action(4,503)
				return; end;
				setcurentleaf("anna_room",17,2);
				SwitchToSheet("re");
			return; end;
			

			
			
			if obj_id==40 then -- шахматная доска
			if not flags.minicomplete then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini",17,11);
				dofile("./data/17/11/res.lua");
				set_satelite_leaf("albert_house");
				dofile("data\\17\\11\\level.lua");
				mini_create();
				for i=1000,1011,1 do
					speciale_action(2,i,true)
				end;
			return; end;	
			return; end;	
			
			if obj_id==56 then -- сирень
			if not flags.minicomplete1 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini1",17,12);
				dofile("./data/17/12/res.lua");
				set_satelite_leaf("albert_house");
				dofile("data\\17\\12\\level.lua");
				mini_create();
				for i=1001,1007,1 do
					speciale_action(2,i)
				end;
			return; end;	
			return; end;	
			
			if obj_id==63 then -- две картины
			if not flags.minicomplete2 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini",17,13);
				dofile("./data/17/13/res.lua");
				set_satelite_leaf("albert_house");
				dofile("data\\17\\13\\level.lua");
				mini_create();
				speciale_action(2,1000,true);
				speciale_action(2,1021,true);
				speciale_action(2,1022,true);
				for i=1001,1019,2 do
					speciale_action(2,i,true);
				end;	
							return; end;	
			return; end;

			if obj_id==69 then -- плитка
			if not flags.minicomplete3 then
			    DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini3",17,14);
				dofile("./data/17/14/res.lua");
				set_satelite_leaf("albert_house");
				dofile("data\\17\\14\\level.lua");
				mini_create();
				for i=1001,1010,1 do
					speciale_action(2,i,true)
				end;
			return; end;	
			return; end;			

----------------- собирем вещи в шкаф----------------------------------
			if obj_id==57 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.cloth1=true;
				if flags.cloth2 and flags.cloth3 then
				   DeleteElement("gr",57);
				   DeleteElement("gr",58);
				   DeleteElement("gr",59);
				   collaps_obj(172,0,0,10,1);
				   AddElement("gr",172);
				   MoveObjectToTree(172); 	
					playeffect("1");				   
				return; end;
				playeffect("collaps");
			return; end;

			if obj_id==58 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.cloth2=true;
				if flags.cloth1 and flags.cloth3 then
				   DeleteElement("gr",57);
				   DeleteElement("gr",58);
				   DeleteElement("gr",59);
				   collaps_obj(172,0,0,10,1);
				   AddElement("gr",172);
				   MoveObjectToTree(172); 	
				   playeffect("1");	
				return; end;
				playeffect("collaps");
			return; end;
			
			if obj_id==59 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.cloth3=true;
				if flags.cloth1 and flags.cloth2 then
				   DeleteElement("gr",57);
				   DeleteElement("gr",58);
				   DeleteElement("gr",59);
				   collaps_obj(172,0,0,10,1);
				   AddElement("gr",172);
				   MoveObjectToTree(172); 	
				   playeffect("1");	
				return; end;
				playeffect("collaps");
			return; end;		



			if obj_id==113 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==160 then 
				StopParticleSystem(160); 
				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 > 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
	    -- CreateWindow(100,100,"199");
		if SLevel==1.0 then return;end;
		flags.loc1 = 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
