-- DocViewer for "Authentic documents"
-- 7.9 (79mxm@rambler.ru)

local item_view = ""

function update()
	if db.actor:active_slot() == 1 then
		item = db.actor:active_item():section()
		if system_ini():line_exist(item, "doc_view") then
			if item ~= item_view then doc_view_on(item) end
		else
		doc_view_off()
		end
	else
		doc_view_off()
	end
end

function doc_view_on(item)
	if item then
		item_view = system_ini():r_string(item,"img_path")
		if item_view == "auto" then item_view = "docs\\"..item end
		pos_x = system_ini():r_s32(item,"pos_x")
		pos_y = system_ini():r_s32(item,"pos_y")
		X = CUIStatic()
		X:Init(item_view,pos_x,pos_y,0,0)
		get_hud():AddCustomStatic("doc_viewer", true)
		get_hud():GetCustomStatic("doc_viewer"):wnd():AttachChild(X)
		item_view = item
	end
end

function doc_view_off()
	if get_hud():GetCustomStatic("doc_viewer") then
		get_hud():RemoveCustomStatic("doc_viewer")
		item_view = ""
	end
end
