.namespace DocumentManager

oldphase = ""
curdocname = ""
g_interaction= ""
function OpenDocument(documentimg,documentname, interaction)
	-- AssertPopup(type(documentimg) == "string", "prop param opendocument")
	 Cursor.ChangeCursor(0)
	 documents_img.Image = documentimg
	 curdocname = ""
	 if documentname ~= nil then
		curdocname = documentname
	 end

	if string.find(GetCurrentManager().Name,"SearchSite") then
		oldphase = "SearchSite"
	else
		oldphase = "Closeup"
	end
	OPLog.Log(oldphase)
	 SetVariables("CurrentGamePhase","Document")
	 documents_parent.Enabled = true	
	 SetCenter(documents_img, Vector:new(735,400))
	 if documents_img.Position_X < 400 then
		documents_img.Position_X = 400
	 end
	 document_quit_txt.Text = GlobalFunctions.GetText("int_doc_close")
	if interaction == "none" then
		-- OPLog.Log("hello")
		g_interaction = "none"
		document_use.Flags_Visible = false
		document_quit.Position_Y = 38
	else
		document_use_txt.Text = GlobalFunctions.GetText("int_doc_use")
		document_use.Flags_Visible = true
		document_quit.Position_Y = 130
		g_interaction = ""
	 end
	 SpriteFader.Fade(documents_img,true,0.8)

end

function OnEnable()

end



function OnWbpMouseLUp()

	
	
	if self.Name == "document_use" then
		if g_interaction == "none" then
			return
		end
		SetVariables("CurrentGamePhase",oldphase) 
		if GetCurrentManager().OnDocumentUse ~= nil and curdocname ~= "" then
			if not GetCurrentManager().OnDocumentUse(curdocname) then
				SequencePlayer.PlayRandomSequence({"OB_0","OB_1","OB_2","OB_3","OB_4"},nil,nil)	
			end
		else
			SequencePlayer.PlayRandomSequence({"OB_0","OB_1","OB_2","OB_3","OB_4"},nil,nil)	
		end
	end
	if self.Name == "document_quit" then
		SetVariables("CurrentGamePhase",oldphase) 
		if GetCurrentManager().OnDocumentLeave ~= nil and curdocname ~= "" then
			GetCurrentManager().OnDocumentLeave(curdocname)
		end
	end
	
		SpriteFader.Fade(documents_img,false,0.4,self)
		 return true
end

function OnFaderEnd()
		
	  documents_parent.Enabled = false


end

