-- local x=0;
-- local y=0;

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

function PlaneSound()
	playeffect("prop");
return;end;

function PrintSound()
	playeffect("print");
return;end;

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

function SelectRandom(id)
	if not flags.byphoto then
		if flags.doorisopen then
			selectrandomobject(1.5,67);
		return;end;
		idObject=GetRandomObject();
		selectrandomobject(1.5,idObject);
	return;end;
	selectrandomobject(1.5,6);
end;
function SelectRandomRadar(idObject)
	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==35 then
		if obj_id==50 then
			StartAnimation(104,0,6);	
			StopOnMouseOver(50)
		return;end;	
		if obj_id==22 then
			StartAnimation(103,0,6);
			playeffect("prop");			
		return;end;
	return;end;
	

	
	if sender==26 then
		if obj_id==1 then
		   CreateWindow(100,100,"206",2);
			setcolor(6,1,0,0,1,1);
		   flags.byphoto=true;
		   SwitchToSheet("re");

		return;end;
		if obj_id==2 then
			speciale_action(2,105)
		  StartAnimation(105);
		return;end;	
		if obj_id==3 then
			CreateWindow(100,100,"211",6);
		
		return;end;		
		if obj_id==5 then
			  speciale_action(2,106)
			  StartAnimation(106);		
			  
			  flags.keys=true;
savegame(SaveLevel())			  
		return;end;
		if obj_id==6 then
			SwitchToSheet("gr");
			flags.onkeys=true;
			speciale_action(2,107)
			StartAnimation(107);	
savegame(SaveLevel())			
		return;end;		
		if obj_id==4 then
			CreateWindow(100,100,"214",5);
			
		return;end;
		if obj_id==7 then
			speciale_action(2,109);
			StartAnimation(109);
			flags.hint=true;
			savegame(SaveLevel())
		return;end;
		if obj_id==8 then
			
			speciale_action(2,108)
			StartAnimation(108);
			flags.exit=true;
			savegame(SaveLevel())
		return;end;
		
		if obj_id==9 then			
			speciale_action(2,110)
			StartAnimation(110);
			savegame(SaveLevel())
		return;end;	

		if obj_id==10 then			
			speciale_action(2,111)
			StartAnimation(111);
			savegame(SaveLevel())
		return;end;			
	return;end;

	if sender==12 then
	
	if SLevel==1.0 then return;end;
		if obj_id==40 then
		 	CreateWindow(100,100,"205",1);
			flags.photo=true;
		return;end;
		if flags.doorisopen then
			if not flags.allobject then
			    flags.allobject=true;
				CreateWindow(100,100,"204",3);
			return;end;
		return;end;
		if obj_id==42 then
		    flags.case = true;
			CreateWindow(100,100,"213",4);
		return;end;
		if obj_id==30 then
			CreateWindow(100,100,"208",10);
			flags.keys=false;
			
		return;end;
	return;end;
	
	
	if sender==16 then
		if obj_id==501 then

		   if flags.levelcomplete then
				speciale_action(2,500,true,2);
				speciale_action(4,500);
				BlockCursor(true);
				Set_Cursor(67,3);
			return;end;
			BlockCursor(false);
		return;end;
		
		if obj_id==502 then
		   BlockCursor(false);
		return;end;
		if obj_id==500 then
		   BlockCursor(false);		   
		return;end;
	
		if obj_id==22 then
			BlockCursor(false);
		return;end;
	return;end;

	
	if sender==15 then
		if obj_id==501 then
			flags.whole_darkness=false;
		return;end;
		if obj_id==502 then
		if not flags.levelcomplete then
			BlockCursor(false);
			CreateWindow(100,100,"198",9)
		    
			ShowMenu(true);
			StartAnimation(102)
			AddParticleToObject(67,"Door",390,291);
			MoveEmiter("Door",390,291);
			StartEmiter("Door");
			savegame(SaveLevel())
		return;end;	
		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==101 then
			StartAnimation(101,0,10);		
		return;end;

	if obj_id==67 then
		if not flags.case then  
		CreateWindow(100,100,"200");
		return;end;
		
		if flags.case then
		if flags.doorisopen then
			if attachedID==30  then			
                playeffect("door");				
				RemoveFromMouse(attachedID);
				DeleteElement("gr",attachedID);
				speciale_action(2,108)
				
				ShowMenu(false);
				flags.levelcomplete=true;
				DarkScreen(true);
			 return;end;		
			 if (attachedID>-1) and (attachedID~=30) then
				CreateWindow(100,100,"202");
			 return;end;
			 if (attachedID==-1)  then
				CreateWindow(100,100,"203");
			 return;end;
		return;end;
		if attachedID==30 and (not flags.doorisopen) then
			CreateWindow(100,100,"201");
		return;end;	
		CreateWindow(100,100,"203");
		return;end;			
	return;end;  

	if attachedID==-1 then

		
	

		
		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","kabinet");
				delete_tree_leaf("Root","comics");
				setnextlavel(22);--22
				loadlavel();				
			return;end;
				DarkScreen(false);
				speciale_action(2,502,true,2);
				speciale_action(4,502)
		return;end;	


		
		if obj_id==42 then
				speciale_action(2,110);
				SetCurrentRM("menu");
				    addstaticobjecttogame(777777777,"menubuttons",62,679,"",0,0,61,61);
					AddSheet(1001,"gr","green_b",62,679,61,61,"green",156,619,638,101,15,41,15,10,1,55,777777777,9);
					AddLeftScroller("gr",2000029,"leftbtn",nil,nil,nil,122,105,46,90)
					AddRightScroller("gr",2000030,"rightbtn",nil,nil,nil,782,100,46,90)					
				SetCurrentRM("main");
				playeffect("collaps");
				collaps_obj(obj_id,0,0,10,1);
		return; end;
		

			
		if flags.case then		
		
		if flags.keys then
			if obj_id==30 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				AddElement("gr",obj_id);
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
				SetAlfaSheet(2.5)
				speciale_action(2,106)
				flags.keys=false;
			return; end;			
		return;end;
		
		if obj_id==40 then
			speciale_action(2,111);
			collaps_obj(obj_id,0,0,10,1);
			StopSheet=true;
			playeffect("collaps");		
			AddImgToBook("photoaparat",838,580);
			AddHints()
			collaps_obj(obj_id,0,0,10,1);
			setcolor(obj_id,0,0,0,0.5,1);
		return;end;
		

		if flags.photo then
		
			if flags.byphoto then
				if obj_id==6 then
					setcolor(6,0,0,0,1,1);			
					speciale_action(2,105)					
					playeffect("collaps");
					collaps_obj(obj_id,0,0,10,1);	
					CreateWindow(100,100,"207",7);						
					flags.byphoto=false;				
				return;end;
			return;end;
			

			
			if obj_id > 0 and obj_id < 101 then
				if flags.hint then
					CreateWindow(100,100,"209");
					speciale_action(2,109);
					flags.hint=false;
				end;
				playeffect("collaps");
		        collaps_obj(obj_id,0,0,10,1);
	        return 0; end
	return; end;
	CreateWindow(100,100,"208");
	return; end;
	CreateWindow(100,100,"200");
	return; end;	
	
	return; end;
	
	if sender==14 then
	StopSheet=true;
	if flags.photo then
		if obj_id==30 then
			addObjectToMouse(obj_id);
			if not flags.exit then
			if flags.doorisopen then
				CreateWindow(100,100,"212",8);
				speciale_action(2,107)
				flags.onkeys=false;
			 return;end; 
			return;end;
		return;end;
		return;end;
		if obj_id>0 then
			addObjectToMouse(obj_id);
		return; end;
	return; end;	
	
	if sender==4 then	
		flags.doorisopen=true;
	return; end;		
	
end
