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.loc3 then
		selectrandomobject(1.5,45);
	return;end;
    idObject=GetRandomObject();	
	if idObject==335 then
		selectrandomobject(1.5,42);
	return;end	
	if idObject==47 then
	    if not flags.minicomplete9 then
			if GetActivCount()>1 then
				flags.HintCount=flags.HintCount+1;
				SelectRandom()		
			return;end;				
			if not flags.pianoopen then
				selectrandomobject(1.5,40);
			return;end;	
			selectrandomobject(1.5,41);
		return;end;	
		selectrandomobject(1.5,39);
	return;end		
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==335 then
		selectrandomobject(1.5,42);
	return;end	
	if idObject==47 then
	    if not flags.minicomplete9 then			
			if not flags.pianoopen then
				selectrandomobject(1.5,40);
			return;end;	
			selectrandomobject(1.5,41);
		return;end;	
		selectrandomobject(1.5,39);
	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.loc3 then
		if not flags.whole_darkness then
		if not flags.allobject3 then
		    flags.allobject3=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==39 and  flags.diaryout then
		savegame(SaveLevel())
		end;
		if obj_id==503 or obj_id==500 then
		   BlockCursor(false);
		return;end;
		if obj_id==501 then
		--	flags.whole_darkness=true;
		   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==2 then
			CreateWindow(100,100,"197");
			BlockCursor(false);
		return;end;										
	return;end;
	
	if sender==15 then
		if obj_id==39 and  flags.diaryout then
		savegame(SaveLevel())
		end;	
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			if flags.loc2 then
			if not flags.allobject2 then
		    flags.allobject2=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(42,"Mirror",0,0);
			StartEmiter("Mirror");
			MoveEmiter("Mirror",903,405);	
			AddParticleToObject(40,"ForKey",0,0);
			StartEmiter("ForKey");
			MoveEmiter("ForKey",162,510)
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==41 then -- пианино
			if not flags.minicomplete9 then
				if attachedID==335 or flags.minirun9 then    
    				RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					playeffect("mini");
					Set_Cursor(41,2)
					DarkScreen(true);
					add_free_leaf("Root","mini9",17,20);
					dofile("./data/17/20/res.lua");
					set_satelite_leaf("anna_room");
					dofile("data\\17\\20\\level.lua");
					mini_create();
					speciale_action(2,1000,true);
					for i=1008,1018,1 do
						speciale_action(2,i,true)
					end;
				return; end;
				if attachedID~=335 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"207");   
				return; end;
			return; end;	
			return; end;
			
			if obj_id==40 then
				if attachedID==114  then    
    				RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
					Set_Cursor(40,3)
					speciale_action(2,40,true);
					flags.pianoopen=true;
					speciale_action(2,41,true);
					Set_Cursor(41,4);
					StopEmiter("ForKey");
					AddParticleToObject(41,"Piano",0,0);
					StartEmiter("Piano");
					MoveEmiter("Piano",127,558)						
					--AddParticleToObject(41,"./particles/particle2.psi");
				return; end;
				if attachedID~=114 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"208");  
				return; end;
			return;end;
			
			if obj_id==39 then -- дневник
				if not flags.mirror and flags.minicomplete10 then
					if attachedID==-1 or attachedID==328 then
						RemoveFromMouse(attachedID);					
						DarkScreen(true);
						playeffect("mini");
						add_free_leaf("Root","mini10",17,21);
						dofile("./data/17/21/res.lua");
						set_satelite_leaf("anna_room");
						dofile("data\\17\\21\\level.lua");
						mini_create();
						for i=1000,1017,1 do
							speciale_action(2,i,true);
						end;					
					return; end;
				return; end;
				if attachedID==-1 then	
					if not flags.mirror then
						DarkScreen(true);
						playeffect("mini");
						add_free_leaf("Root","mini10",17,21);
						dofile("./data/17/21/res.lua");
						set_satelite_leaf("anna_room");
						dofile("data\\17\\21\\level.lua");
						mini_create();
						for i=1000,1017,1 do
							speciale_action(2,i,true);
						end;
					return; end;	
				return; end;		
			return; end;
			
		if attachedID==-1 then	
	

		if obj_id==101 then
			StartAnimation(101,0,5)
		return;end;
		
		if obj_id==102 then
			StartAnimation(102,0,5)
		return;end;
		
		if obj_id==103 then
		   StartAnimation(103,0,3)
		return;end;
		
		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==45 then
				setcurentleaf("albert_house",17,0);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;	
			
			if obj_id==42 then -- трюмо
			if not flags.minicomplete8 then
				DarkScreen(true);
				playeffect("mini");
				add_free_leaf("Root","mini8",17,19);
				dofile("./data/17/19/res.lua");
				set_satelite_leaf("anna_room");
				dofile("data\\17\\19\\level.lua");
				mini_create();
				for i=1009,1016,1 do
					speciale_action(2,i,true);
				end;
				speciale_action(2,1021,true);
			return; end;	
			return; end;
			

			

			


			if obj_id==328 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 > 0 and obj_id < 400 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.loc3 = true;
		--messageboxi(sender)
		
		
		-- if flags.loc1 and flags.loc2 and flags.loc3 then
			-- flags.levelcomplete=true;
			-- speciale_action(2,501,true,2);
		-- return; end;			
	return; end;		
end
