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	   
		if GetActivCount()>1 then
			flags.HintCount=flags.HintCount+1;
			SelectRandom()		
		return;end;	
		if flags.mirror then
		selectrandomobject(1.5,100);
		return;end;
		if not flags.on then
			if not flags.clean then
				if flags.lamp then
					selectrandomobject(1.5,16);
				return;end;
				selectrandomobject(1.5,78);
			return;end;		
			if not flags.handle then
				selectrandomobject(1.5,51);
			return;end;		
			if not flags.minicomplete then
				selectrandomobject(1.5,53);
			return;end;
			selectrandomobject(1.5,49);	
		return;end;	
		selectrandomobject(1.5,52);	
	return;end;	
	if 	idObject==25 then
	    selectrandomobject(1.5,27);
	return;end;
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==100 then	   
		if flags.mirror then
		selectrandomobject(1.5,100);
		return;end;
		if not flags.on then
			if not flags.clean then
				if flags.lamp then
					selectrandomobject(1.5,16);
				return;end;
				selectrandomobject(1.5,78);
			return;end;		
			if not flags.handle then
				selectrandomobject(1.5,51);
			return;end;		
			if not flags.minicomplete then
				selectrandomobject(1.5,53);
			return;end;
			selectrandomobject(1.5,49);	
		return;end;	
		selectrandomobject(1.5,52);	
	return;end;	
	if 	idObject==25 then
	    selectrandomobject(1.5,27);
	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.levelcomplete then
		    DarkScreen(true);
			ShowMenu(false);
		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==9 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;
		return;end;		
		if obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(5,"Switch",0,0);
			StartEmiter("Switch");
			MoveEmiter("Switch",246,322);	
			AddParticleToObject(64,"TT",0,0);
			StartEmiter("TT");
			MoveEmiter("TT",67,270)
			AddParticleToObject(3,"Lamp",0,0);
			StartEmiter("Lamp");
			MoveEmiter("Lamp",653,152)	
			AddParticleToObject(1,"Water",0,0);
			StartEmiter("Water");
			MoveEmiter("Water",268,501)	
			playeffect("Igri");
			StartTimer(1111,43)		
		savegame(SaveLevel())			
		return;end;
	return;end;		

	if sender==36 then
		if obj_id==1111 then
			playeffect("Igri");
			StartTimer(1111,43)	
		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.water then
			if attachedID==26 then    
				flags.water=true;
				StopEmiter("Water");
				playeffect("attach");
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				collaps_obj(25,0,0,10,1);
				AddElement("gr",25);
				SetAlfaSheet(2.5)
				setcolor(25,0,0,0,0.5,1);
				MoveObjectToTree(25); 	
				Set_Cursor(27,3);					
			return; end;
			if attachedID~=26 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==78 then
		if not flags.on then
			if attachedID==19 then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				SetAlfaSheet(2.0)
				playeffect("attach");
				flags.lamp=true;
				speciale_action(2,78,true);
				speciale_action(2,16,true);
				Set_Cursor(16,4);
			return; end;					
			if attachedID~=19 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"201"); 
			return; end;
		return;end;	
		CreateWindow(100,100,"209"); 
		return; end;
		
		if obj_id==16 then
		if not flags.on then
			if flags.lamp and flags.clean then
					CreateWindow(100,100,"206");  
			return;end;
			if flags.lamp then
				if attachedID==25 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					SetAlfaSheet(2.0)
					playeffect("attach");
					flags.clean=true;
					Set_Cursor(16,3);
				return; end;					
				if attachedID~=25 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"206");  
				return; end;		
			return;end;
		return;end;
		if flags.on then
			if not flags.clean then 
				if attachedID ~=-1	then	
				CreateWindow(100,100,"209"); 
				return;end;
					CreateWindow(100,100,"203"); 
			return;end;
		return;end;
		return;end;

		if obj_id==51 then
		if not flags.handle then
			if attachedID==55 then    
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				Set_Cursor(51,3);					
				speciale_action(2,51,true);
				speciale_action(2,49,true);	
				Set_Cursor(49,4);				
				flags.handle=true;
				playeffect("attach");
				AddParticleToObject(53,"Handle",0,0);
				StartEmiter("Handle");
				MoveEmiter("Handle",232,285);
			return; end;
			if attachedID~=55 and attachedID>-1 then
				CreateWindow(100,100,"200");     
			return; end;
			if attachedID ==-1 then		
				CreateWindow(100,100,"204");  
			return; end;
		return; end;
		return; end;
		
		if attachedID==-1 then	


		
		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","black_rose");
				delete_tree_leaf("Root","mini");
				setnextlavel(11);
				loadlavel();	
				ShowMenu(false);
			return;end;	
			DarkScreen(false);
			speciale_action(2,503,true);
		return;end;			
			
			if obj_id==53 then
			    if not flags.minicomplete then
				if flags.handle then
				
				if not flags.on then
					DarkScreen(true);
					playeffect("mini");
					add_free_leaf("Root","mini",10,11);
					dofile("./data/10/11/res.lua");
					set_satelite_leaf("black_rose");
					dofile("data\\10\\11\\level.lua");
					mini_create();
					speciale_action(2,1010,true);
					for i=1017,1024,1 do
						speciale_action(2,i,true);
					end;
					for i=1032,1039,1 do
						speciale_action(2,i,true);
					end;
				return; end;	
					CreateWindow(100,100,"209");
				return; end;	
				
				CreateWindow(100,100,"210");
				return; end;					
			return; end;	
			

					

			
			if obj_id==49 then
				playeffect("handle");
   			    speciale_action(2,49); 
			    Set_Cursor(52,4);	
				Set_Cursor(49,3);					
				speciale_action(2,52);
				flags.on=true;				
				if flags.lamp then
				if flags.minicomplete then	
					 if flags.clean then
						speciale_action(2,17);
						flags.stand=true;
						speciale_action(2,100,true);
						setcolor(100,0,0,0,1,1);
						speciale_action(2,14);
						Set_Cursor(78,3);
						Set_Cursor(67,3);
						Set_Cursor(64,3);
						Set_Cursor(17,3);
						Set_Cursor(19,3);
						Set_Cursor(49,3);
						Set_Cursor(52,3);
						Set_Cursor(16,3);
						flags.mirror=true;		
						StopEmiter("Lamp");
						StopEmiter("TT");	
						StopEmiter("Switch"); 						
					 return;end
					 speciale_action(2,15);
					 Set_Cursor(15,2);			
				return;end;
				CreateWindow(100,100,"205");  					
				return;end;				
			return; end;
			
			if obj_id==52 then
			playeffect("handle");
			if not flags.mirror then
				speciale_action(2,52);
				Set_Cursor(52,3);	
				speciale_action(2,49);
				Set_Cursor(49,4);	
				flags.on=false;		
			if flags.lamp then
				if flags.minicomplete then				
				 if flags.clean then
					speciale_action(2,17);
					flags.stand=true;
				 return;end
				 speciale_action(2,15);	
				 Set_Cursor(15,3);
				return;end;		
				
				return;end 
			return; end;	
			return; end;
			

			if obj_id==15 then
				CreateWindow(100,100,"203"); 
			return;end;						
			if obj_id==64 then
			if not flags.mirror then
			   CreateWindow(100,100,"208");
			return; end;	
			return;end;

			if obj_id==55 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==19 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==26 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==100 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 > 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
		flags.levelcomplete=true;

	return; end;		
end
