------Emitters-------------------
AddParticleToObject(1000,"lever");
MoveEmiter("lever",250,450);

AddParticleToObject(22,"lever2");
MoveEmiter("lever2",140,350);

AddParticleToObject(201,"wheel");
MoveEmiter("wheel",400,440);


------End Emitters------------


local speed = 1;


last_id = nil;

n = 0;

WaitRender();

function gameinput( sender,obj_id,attachedID )
	if SLevel==1.0 then return; end;
	 if (sender == 1  or sender==5) and not isTimes  and imagetex~=-1 then
			set_visible_object(obj.plashechka.id,false)
			set_visible_object(obj[imagetex].id,false)
			del_object_from_game(5654547)		
			gameinput(26,imageid)	
del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)				
	end
	
	if sender == 6 then
		if flags.first_time_load then
			flags.first_time_load = false;			
		end;
	end;	
	if sender ==41 then	
	RotateHandler(obj_id);
if obj_id ==obj.dragonfly.id then	
	StartAnimation( 5555555555,1,5 );
	return;end;	
	return;end;
	if sender == 33 then	
	
	
	 if flags.mini_complete then
		
			if flags.n>=15 and not miniend then
				CreatePlashechka(79,"102","goodgirl")	
				miniend=true
			elseif not miniend then 
				CreatePlashechka(7954,"303","goodgirl")
			
			end			
			
			ShowMenu(true)
		end
			
			
		if not flags.finish then
			ShowMenu(true);
			SwitchToSheet("re");
		end;
	end;
	
	if sender == 2 then
		RemoveFromMouse(object);
		MessageProc(sender,obj_id);
	return;end;	
	if sender==777 then
		if  flags.comics1 then			
					
					StartTimer(43342,0.5,"conv22")
			function conv22()
					CreatePlashechka(79,"100","goodgirl")	
			end		
					ShowMenu(true)
					SwitchToSheet("re")
					flags.comics1=false;
		return;end
	if flags.startmini then	
		flags.startmini=false
		leafobj={2234}
		GetRenderTarget(2234,"rendertar");	
		mininame="mini";
		mininum1=22;
		mininum2=10;
		mininame2="lava";	
	return ;end
	
		
		if top_plush_id then		
		ShowMenu(true)
		end	
	end

	
	if sender == 100 then	
	
		if  not flags.kluch  then
		
				flags.kluch= true;
				AddElement(sheet,obj.kluch22.id);
				MoveObjectToTree(obj.kluch22.id);		
				obj.kluch22.is_stored = true;			
		end	
			
		if flags.parts_plased < 9 then
			StartEmiter("wheel");
		end;
		
		if not flags.mini_complete and flags.mini_start then
			ShowMenu(false)
			start_mini();
		return;end;
		
		if flags.first_time_load then
			flags.first_time_load=false
			set_visible_object(obj.intro.id,true);
			speciale_action(4,obj.intro.id);
			-- StartEmiter("Level");
		return; end;		
		
		
		if flags.mini_complete then
			set_visible_object(9,false);
			set_visible_object(11,false);
			set_visible_object(12,false);
			StartAnimation(obj.lava.id);			
			speciale_action(4,22,true);
			speciale_action(2,20,true);
			speciale_action(2,21,true);
			flags.mini1 = false;
			StopEmiter("lever");
			StartEmiter("lever2");
			Set_Cursor(1000,3);
			set_visible_object(8,false);
			RotateObject(66,0,360,4,true);
			set_visible_object(obj.mechano.id,true);
			StartAnimation(obj.mechano.id);
		end;
		
		-- Starting Opening Plushes --
		if flags.start_draw then	
			flags.start_draw = false;
		return;		
		end;
		-- End Starting Opening Plushes --
	return; end;

	
	if sender == 8 or sender==44 then
		HideGlove();
		HideScaner();
		HideRentgen()
		HideNvg();
		takeobjecttohand=false	
		if myid~=-1 then
		StopColorCollapse(myid)
		myid=-1;
		end
		
	return end;

	if sender==12 then
		if not flags.items_collected then
	 if obj_id >= obj.planka_22.id and obj_id <= obj.planka_22.id + 8 then
			
	 flags.storedobj= flags.storedobj+1
	if flags.storedobj==8 and flags.n==15 then			
		for i,v in pairs(obj) do
		if obj[i].id == obj_id then
			AddElement(sheet,obj[i.."1"].id);
			MoveObjectToTree(obj[i.."1"].id);			
			obj[i.."1"].is_stored = true;
			switched=true;			
			takeobjecttohand=false
		return; end;
	end;
	return end
	StoreObj(obj_id);
		
	 end
	
	if  flags.n >= 15 then
		
		
		if not flags.mini_complete then
			CreatePlashechka(794636,"101","goodgirl")	
		else
			CreatePlashechka(79,"102","goodgirl")
		end
		StartTimer(234234,1,"Switch22")
		function Switch22()
			SwitchToSheet("gr")
		end
		
					
		
	flags.items_collected=true;
	return;end;
	
	return;end;
	end
	if sender == 1 then
			
		if attachedID ~=-1 and attachedID == obj.planka_221.id  and obj_id == 7000 then
			if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.planka_22 = detail(1,obj.planka_221.id);
			playeffect("134")
			speciale_action(2,1)
			speciale_action(2,111)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.gear1_221.id  and obj_id == 7000 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear1_22 = detail(2,obj.gear1_221.id);
			playeffect("134")
			speciale_action(2,22222)
			speciale_action(2,22222222)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.gear2_221.id  and obj_id == 7000 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear2_22 = detail(3, obj.gear2_221.id);
			playeffect("134")
			speciale_action(2,3)
			speciale_action(2,33)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.gear3_221.id  and obj_id == 7000 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear3_22 = detail(4,obj.gear3_221.id );
			playeffect("134")
			speciale_action(2,4)
			speciale_action(2,44)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.gear4_221.id  and obj_id == 7000 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear4_22 = detail(5,obj.gear4_221.id);
			playeffect("134")
			speciale_action(2,5)
			speciale_action(2,55)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.gear5_221.id  and obj_id == 7000 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear5_22 = detail(6,obj.gear5_221.id);
			playeffect("134")
			speciale_action(2,6)
			speciale_action(2,66)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.pruzhina_221.id  and obj_id == 7000 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.pruzhina_22 = detail(7,obj.pruzhina_221.id);
			playeffect("134")
			speciale_action(2,7)
			speciale_action(2,77)
		return;end;
		
		if attachedID ~=-1 and  attachedID == obj.gear6_221.id  and obj_id == 7000 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear6_22 = detail(8, obj.gear6_221.id);
			playeffect("134")
			speciale_action(2,8)
			speciale_action(2,88)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.rychag_221.id  and obj_id == 7000 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.rychag_22 = detail(10,obj.rychag_221.id);
			playeffect("134")
			speciale_action(2,10)
			speciale_action(2,1000)			
		return;end;
		
		if attachedID == -1 then
			if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			if (obj_id ==7000) and flags.parts_plased < 9 then
				CreatePlashechka(5,"205","goodgirl")
			return;end;
			if obj_id == obj.nozhnicy_22.id then
				CollapseObj(obj_id);
				speciale_action(2,25);
				last_id = obj_id;
				flags.n = flags.n + 1;
				
			end;
			if obj_id == obj.marker_22.id then
				CollapseObj(obj_id);
				speciale_action(2,27);
				last_id = obj_id;
				flags.n = flags.n + 1;
			end;
			if obj_id == obj.vinograd_22.id then
				CollapseObj(obj_id);
				speciale_action(2,26);
				last_id = obj_id;
				flags.n = flags.n + 1;
			end;
			if obj_id == obj.ruletka_22.id or obj_id == obj.molotok_22.id or 
			obj_id == obj.sverlo_22.id then
				CollapseObj(obj_id);
				last_id = obj_id;
				flags.n = flags.n + 1;
			end;
			if obj_id >= obj.planka_22.id and obj_id <= obj.planka_22.id + 8 then
				CollapseObj(obj_id);
				-- StoreObj(obj_id);
				-- AlternateTimer("SwitchSheet",4000)
				last_id = obj_id;
				flags.n = flags.n + 1;
			end;
			if obj_id == 1000 and flags.parts_plased >= 9 and flags.mini1 then
				-- if flags.n >= 15 then
				
				AlternateTimer("SwitchSheet1",1000)	
				speciale_action(2,8);
				speciale_action(2,obj.mechano.id);
				StartAnimation(obj.mechano.id);
				StartTimer(4234234,1.5,"start_mini");
				canmenu=true
				flags.mini_start=true;	
				speciale_action(2,11);					
				set_visible_object(10,false);
				set_visible_object(1000,false);
				set_visible_object(77,false);
				set_visible_object(7,false);									
				speciale_action(2,obj.prujina.id,true);
				
			end;
			if obj_id == 22   then
			 if flags.n >=15 then
				flags.finish = true;
							
				-- ClosePlushes();
				-- LevelEnd(23)
				RemoveFromMouse(obj.kluch22.id)
				SwitchToSheet("gr")		
				DeleteElement("gr",obj.kluch22.id)
				
				ShowMenu(false);
				StartTimer(24242342,0.01,"endloc22")		
				function endloc22()
					del_object_from_game(obj.dragonfly.id)
					leafobj={2234}
					GetRenderTarget(2234,"rendertar");	
					minigg=true;
					levelnext=23;
				end
		
			
			else
				CreatePlashechka(7954,"303","goodgirl")
			end
			end;
			c(flags.n)
			
		return;end;
	return; end;

	
	if sender == 14 then
		if scaner_on then return;end
		takeobjecttohand=true;
			if obj_id==obj.planka_221.id then
			addObjectToMouse(obj_id);			
			myid=1;
			ColorCollapse(1,100,3,0.5)
			return;end
			
			if obj_id==obj.gear1_221.id then
			addObjectToMouse(obj_id);			
			myid=2;
			ColorCollapse(2,100,3,0.5)
			return;end
			
			if obj_id==obj.gear2_221.id then
			addObjectToMouse(obj_id);			
			myid=3;
			ColorCollapse(3,100,3,0.5)
			return;end
			
			if obj_id==obj.gear3_221.id then
			addObjectToMouse(obj_id);			
			myid=4;
			ColorCollapse(4,100,3,0.5)
			return;end
			
			if obj_id==obj.gear4_221.id then
			addObjectToMouse(obj_id);			
			myid=5;
			ColorCollapse(5,100,3,0.5)
			return;end
			
			if obj_id==obj.gear5_221.id then
			addObjectToMouse(obj_id);			
			myid=6;
			ColorCollapse(6,100,3,0.5)
			return;end
			
			if obj_id==obj.pruzhina_221.id then
			addObjectToMouse(obj_id);			
			myid=7;
			ColorCollapse(7,100,3,0.5)
			return;end
			
			if obj_id==obj.gear6_221.id then
			addObjectToMouse(obj_id);			
			myid=8;
			ColorCollapse(8,100,3,0.5)
			return;end
			
			if obj_id==obj.rychag_221.id then
			addObjectToMouse(obj_id);			
			myid=10;
			ColorCollapse(10,100,3,0.5)
			return;end
		addObjectToMouse(obj_id);		
	return;end;
	
	-- if sender == 35 then
		if flags.all_items then
			-- if (obj_id > 0) or (obj_id < 10) or (obj_id == 11) then
				-- setcolor(obj_id,0.5,0.5,0.5,0.5);
			-- return;end
		end;
	-- return;end;
	
	-- if sender == 39 then
		-- if (obj_id > 0) or (obj_id < 10) or (obj_id == 11) then
			-- setcolor(obj_id,1,1,1,0.1);
		-- return;end
	-- return;end;
		
	
end;

function SelectRandom()
local dist=-1;local a=-1;local b=-1;local v=100;local t=-1;local diag=-1;
local width = -1;local height = -1;local radius=1.2;
				
	if flags.n >= 15 then
		if flags.mini1 then
		computation(10);			
		return;end;
		computation( 22);		
		
	return;	end
	
	ok = false
	while not ok do
		help_id = GetRandomObject();
		for i,v in pairs(obj) do
			if v.id == help_id and not v.is_collapsed then
				ok = true
				x,y=GetObjectPosition(v.id);
				x1,y1=GetObjectPosition(obj.dragonfly.id);
				width,height = GetObjectSize(v.id)
				a= (x-x1); b= (y-y1);  dist= math.sqrt (a^2+b^2);				
		        t=dist/400;		
                r = (math.sqrt(width^2+height^2)*0.5);		
				
				if r<50 then	r=75;	radius=4;	end  -- при радиусе меньше 50 определяем время кружения и радиус стрекозы
				
				if r>50 and r <100 then	r=87 radius=2.5;  end  --при радиусе больше 50 и меньше 100
				
				if r>100 then 	r=100 	radius=0.75;  end  -- при радиусе больше 100
				
			StartBigTravel(obj.dragonfly.id, v.id, 0, t, r/90, t, 2 ,radius);
			return end
		end
	end
end;



function start_mini()
	flags.mini1 = false;
	ClosePlushes()	
	RemoveFromMouse(obj.kluch22.id)
	HideGlove()
	HideScaner()
	flags.startmini=true;
return;end;