help_window = {}

help_window.BonusInfoIconPos = {}
help_window.BonusInfoIconPos.X = 70
help_window.BonusInfoIconPos.Y = 100

help_window.BonusInfoTextPos = {}
help_window.BonusInfoTextPos.X = 130
help_window.BonusInfoTextPos.Y = 70
help_window.BonusInfoTextPos.Width = 250
help_window.BonusInfoTextPos.Height = 10


help_window.BonusInfo = {}
function help_window.LoadBonusesInfo()
	bonus_info_table = {}
	local num_children = sf.core.g_Application.GetSettings().GetChild(_T("Bonuses"), false).EnumChildren(_T(""))
	local bonus = sf.core.g_Application.GetSettings().GetChild(_T("Bonuses"), false).GetFirstChild()
	local bonus_templates_group = sf.core.g_Application.GetSettings().GetChild(_T("GUITemplates"), true)
	
	


	
	for i = 1, num_children do
		if bonus.GetId() == _T("bonus") then 
			local bonus_id = bonus.GetValue(_T("id"))
			if bonus_id then
				bonus_info_table[T_(bonus_id).c_str()] = {}
				bonus_info_table[T_(bonus_id).c_str()].ImageId = T_(bonus.GetValue(_T("image")))
				bonus_info_table[T_(bonus_id).c_str()].BackImageId = T_(bonus_templates_group.GetChildByAttribute(_T("bonus_icon_template"), _T("id"), bonus.GetValue(_T("icon_template")), true).GetValue(_T("bonus_back_image")))
				bonus_info_table[T_(bonus_id).c_str()].GlareImageId = "game_bonus_logos_bonus_glare" --"game_bonus_logos_bonus_glare"
				bonus_info_table[T_(bonus_id).c_str()].Name = sf.misc.g_StringTable.Instance().FormatByStringsID(bonus.GetValue(_T("bonus_name")))
				bonus_info_table[T_(bonus_id).c_str()].Description = sf.misc.g_StringTable.Instance().FormatByStringsID(bonus.GetValue(_T("bonus_description")))
			end
		end
		bonus = bonus.GetNextSibling()
	end	
	return bonus_info_table
end


function help_window.form_cell_window(_table, _rows_count, _cols_count, _flags) 
	_table.SizeInCells = {}
	_table.SizeInCells.X = _cols_count
	_table.SizeInCells.Y = _rows_count
	_table.Cells = {}	
	for i = 1,_rows_count do
		_table.Cells[i] = {}
		for j = 1,_cols_count do
			_table.Cells[i][j] = {}
			_table.Cells[i][j].Flags = _flags
			_table.Cells[i][j].BonusId = ""
			_table.Cells[i][j].HintText = ""
		end
	end
end

help_window.PageButtonsIds = {}
help_window.PageButtonsIds[1] = _T("page2_button")

help_window.PageWindowTitles = {}
help_window.PageWindowTitles[1] = _T("$142")

help_window.PageFixedTablesIds = {}

help_window.PageFixedTablesIds[1] = {}
help_window.PageFixedTablesIds[1].Id = _T("bonus_fixed_table")
help_window.PageFixedTablesIds[1].Widget = false
help_window.PageFixedTablesIds[1].SelectMode = s4.CFixedTableWidget.ModeOverSelect
help_window.PageFixedTablesIds[1].RowCount = 5
help_window.PageFixedTablesIds[1].Offset = {}
help_window.PageFixedTablesIds[1].Offset.X = 27
help_window.PageFixedTablesIds[1].Offset.Y = 78
help_window.PageFixedTablesIds[1].ChildWidgets = {}
help_window.PageFixedTablesIds[1].ChildWidgets["label_click_bonus_message"] = true

help_window.g_ShowedCellFlags = sf.misc.BitwiseOr(sf.misc.BitwiseOr(s4.CFixedTableWidget.FlagCellEnabled, s4.CFixedTableWidget.FlagCellVisible), s4.CFixedTableWidget.FlagCellShowHint)
help_window.form_cell_window(help_window.PageFixedTablesIds[1], help_window.PageFixedTablesIds[1].RowCount, 9, help_window.g_ShowedCellFlags)

-- основные
help_window.PageFixedTablesIds[1].Cells[1][1].BonusId = "three_ball_split" 
help_window.PageFixedTablesIds[1].Cells[1][2].BonusId = "eight_ball_split" 
help_window.PageFixedTablesIds[1].Cells[1][3].BonusId = "super_three_ball_split" 
help_window.PageFixedTablesIds[1].Cells[1][4].BonusId = "barrier" 
help_window.PageFixedTablesIds[1].Cells[1][5].BonusId = "ball_catcher" 
help_window.PageFixedTablesIds[1].Cells[1][6].BonusId = "droid" 
help_window.PageFixedTablesIds[1].Cells[1][7].BonusId = "bonus_magnet" 
help_window.PageFixedTablesIds[1].Cells[1][8].BonusId = "bonus_brick_ball" 
help_window.PageFixedTablesIds[1].Cells[1][9].BonusId = "warp_level" 
help_window.PageFixedTablesIds[1].Cells[2][1].BonusId = "extra_points" 
help_window.PageFixedTablesIds[1].Cells[2][2].BonusId = "vertical_lighting" 
help_window.PageFixedTablesIds[1].Cells[2][3].BonusId = "horizontal_lighting" 
help_window.PageFixedTablesIds[1].Cells[2][4].BonusId = "laser_shock" 
help_window.PageFixedTablesIds[1].Cells[2][5].BonusId = "laser_gun" 
help_window.PageFixedTablesIds[1].Cells[2][6].BonusId = "cannon" 
help_window.PageFixedTablesIds[1].Cells[2][7].BonusId = "flame_thrower" 
help_window.PageFixedTablesIds[1].Cells[2][8].BonusId = "rockets" 
help_window.PageFixedTablesIds[1].Cells[2][9].BonusId = "chain_lighting_gun" 
help_window.PageFixedTablesIds[1].Cells[3][1].BonusId = "force_field"
help_window.PageFixedTablesIds[1].Cells[3][2].BonusId = "indestructible_explosion"
help_window.PageFixedTablesIds[1].Cells[3][3].BonusId = "balloons" 
help_window.PageFixedTablesIds[1].Cells[3][4].BonusId = "balls_magnet" 
help_window.PageFixedTablesIds[1].Cells[3][5].BonusId = "aim_ball" 
help_window.PageFixedTablesIds[1].Cells[3][6].BonusId = "gold_ball" 
help_window.PageFixedTablesIds[1].Cells[3][7].BonusId = "plasma_ball" 
help_window.PageFixedTablesIds[1].Cells[3][8].BonusId = "vacuum_ball" 
help_window.PageFixedTablesIds[1].Cells[3][9].BonusId = "nuke" 
-- добавочные
help_window.PageFixedTablesIds[1].Cells[4][1].BonusId = "expand_board" 
help_window.PageFixedTablesIds[1].Cells[4][2].BonusId = "extra_life" 
help_window.PageFixedTablesIds[1].Cells[4][3].BonusId = "rail_ball" 
help_window.PageFixedTablesIds[1].Cells[4][4].BonusId = "grow_ball" 
help_window.PageFixedTablesIds[1].Cells[4][5].BonusId = "gravitation_ball" 
help_window.PageFixedTablesIds[1].Cells[4][6].BonusId = "fire_ball" 
help_window.PageFixedTablesIds[1].Cells[4][7].BonusId = "slow_ball" 
help_window.PageFixedTablesIds[1].Cells[4][8].BonusId = "detonate_ball" 
help_window.PageFixedTablesIds[1].Cells[4][9].BonusId = "mine" 
help_window.PageFixedTablesIds[1].Cells[5][1].BonusId = "shrink_board" 
help_window.PageFixedTablesIds[1].Cells[5][2].BonusId = "life_loss" 
help_window.PageFixedTablesIds[1].Cells[5][3].BonusId = "angry_ball" 
help_window.PageFixedTablesIds[1].Cells[5][4].BonusId = "shrink_ball" 
help_window.PageFixedTablesIds[1].Cells[5][5].BonusId = "anti_gravitation_ball" 
help_window.PageFixedTablesIds[1].Cells[5][6].BonusId = "crazy_ball" 
help_window.PageFixedTablesIds[1].Cells[5][7].BonusId = "fast_ball" 
help_window.PageFixedTablesIds[1].Cells[5][8].BonusId = "air_ball" 
help_window.PageFixedTablesIds[1].Cells[5][9].BonusId = "random_bonus" 


-- загрузка инфы о бонусах
help_window.BonusInfo = help_window.LoadBonusesInfo()

function help_window.SetCellCenterOffset(_widget_ptr, _cell_size)
	image_size = _widget_ptr.get().GetSize()
	_widget_ptr.get().SetOffset(_cell_size.X/2 -  image_size.X/2, _cell_size.Y/2 -  image_size.Y/2)
end

function help_window.run_about_window(_owner)
	
	local app = sf.core.g_Application
	local window = s4.COnKeyDownWindow()
	window.Load(
		app.GetSettings().GetChild(_T("GUI"), false).GetChildByAttribute(_T("window"), _T("id"), _T("s4_about_window"), true), 
		app.GetSettings().GetChild(_T("GUITemplates"), false))
	local widget = s4.CTextSlideWidget()
	local widget_ptr = sf.gui.CWidgetPtrT(widget)
	widget_ptr.SetOffset(0, 0)
	widget_ptr.SetLayer(2)
	window.UpdateLayout()
	widget_ptr.SetSize(window.GetSize().X, window.GetSize().Y)
	widget.Detect(
_T("\
{{600}\
[logo_stargaze]\
{{10}\
<255 255 255 255>{0.5}$104\
<255 255 255 255>{0.4}$105\
\
<255 255 255 255>{0.5}$108\
<255 255 255 255>{0.4}$109\n$159\
\
<255 255 255 255>{0.5}$106\
<255 255 255 255>{0.4}$107\n$416\n$415\n$417\n$105\
\
<255 255 255 255>{0.5}$110\
<255 255 255 255>{0.4}$111\n$418\n$112\
\
<255 255 255 255>{0.5}$444\
<255 255 255 255>{0.4}$445\
\
<255 255 255 255>{0.5}$419\
<255 255 255 255>{0.4}$420\
\
<255 255 255 255>{0.5}$119\
<255 255 255 255>{0.4}$120\
\
<255 255 255 255>{0.5}$117\
<255 255 255 255>{0.4}$118\n$443\
\
<255 255 255 255>{0.5}$113\
<255 255 255 255>{0.4}$114\
\
<255 255 255 255>{0.5}$884\
<255 255 255 255>{0.4}$887\
\
[logo_physx]\
[logo_lua]"),_T("giant_text"))
	window.AddWidget(widget_ptr)
	MoveWindowToCenter(_owner, window)

	local window_ptr = sf.gui.CBaseWindowPtrT(window)
	set_widget_flag_value(_owner, sf.gui.CBaseWidget.FlagHidden, true)
	_owner.DoModal(window_ptr) 
	set_widget_flag_value(_owner, sf.gui.CBaseWidget.FlagHidden, false)
end

function help_window.fill_bonus_info_window(_window ,_bonus_id)
	local current_bonus_info = help_window.BonusInfo[_bonus_id]
	if current_bonus_info == nil then 
		return nil
	end

	local app = sf.core.g_Application
	_window.Load(
		app.GetSettings().GetChild(_T("GUI"), false).GetChildByAttribute(_T("window"), _T("id"), _T("s4_bonus_info_window"), true), 
		app.GetSettings().GetChild(_T("GUITemplates"), false))
	
	local title_label_wiget = __cast(_window.GetWidget(_T("title_label")).get(), "sf.gui.CLabelWidget")
	if title_label_wiget then
		title_label_wiget.SetText(current_bonus_info.Name)
	end
	_window.UpdateLayout()
	
	
	local bonus_info_label = __cast(_window.GetWidget(_T("bonus_info_label")).get(), "sf.gui.CLabelWidget")
	bonus_info_label.SetSize(help_window.BonusInfoTextPos.Width, help_window.BonusInfoTextPos.Height)
	bonus_info_label.SetText(current_bonus_info.Description)
	bonus_info_label.ResizeToFitText(true)
	bonus_info_label.SetOffset(help_window.BonusInfoTextPos.X, help_window.BonusInfoTextPos.Y)
	
	if _bonus_id and _bonus_id ~= "" then
		local bonus_image = sf.graphics.CImage(_T(current_bonus_info.BackImageId))
		if bonus_image then
			local bonus_widget = sf.gui.CWidgetPtrT(sf.gui.CImageWidget(bonus_image, _T("bonus_image_widget"), 0, 0))
			if bonus_widget then
				image_size = bonus_widget.get().GetSize()
				bonus_widget.get().SetOffset(help_window.BonusInfoIconPos.X - image_size.X/2, help_window.BonusInfoIconPos.Y - image_size.Y/2)
				_window.AddWidget(bonus_widget)
			end
		end

		bonus_image = sf.graphics.CImage(_T(current_bonus_info.ImageId))
		if bonus_image then
			local bonus_widget = sf.gui.CWidgetPtrT(sf.gui.CImageWidget(bonus_image, _T("bonus_image_widget"), 0, 0))
			if bonus_widget then
				image_size = bonus_widget.get().GetSize()
				bonus_widget.get().SetOffset(help_window.BonusInfoIconPos.X - image_size.X/2, help_window.BonusInfoIconPos.Y - image_size.Y/2)
				_window.AddWidget(bonus_widget)
			end
		end

		bonus_image = sf.graphics.CImage(_T(current_bonus_info.GlareImageId))
		if bonus_image then
			local bonus_widget = sf.gui.CWidgetPtrT(sf.gui.CImageWidget(bonus_image, _T("bonus_image_widget"), 0, 0))
			if bonus_widget then
				image_size = bonus_widget.get().GetSize()
				bonus_widget.get().SetOffset(help_window.BonusInfoIconPos.X - image_size.X/2, help_window.BonusInfoIconPos.Y - image_size.Y/2)
				_window.AddWidget(bonus_widget)
			end
		end
		
	end

	return sf.gui.CBaseWindowPtrT(_window)
end

function help_window.create_bonus_info_window(_bonus_id)
	local window = s4.COnKeyDownWindow()
	return help_window.fill_bonus_info_window(window, _bonus_id)
end

function help_window.run_bonus_info_window(_owner, _bonus_id)
--	local current_bonus_info = help_window.BonusInfo[_bonus_id]
--	if current_bonus_info then 
--[[		local app = sf.core.g_Application
		local window = sf.gui.CWindow()
		window.Load(
			app.GetSettings().GetChild(_T("GUI"), false).GetChildByAttribute(_T("window"), _T("id"), _T("s4_bonus_info_window"), true), 
			app.GetSettings().GetChild(_T("GUITemplates"), false))
		
		local title_label_wiget = __cast(window.GetWidget(_T("title_label")).get(), "sf.gui.CLabelWidget")
		if title_label_wiget then
			title_label_wiget.SetText(current_bonus_info.Name)
		end
		window.UpdateLayout()
		MoveWindowToCenter(_owner, window)
		
		local bonus_info_label = __cast(window.GetWidget(_T("bonus_info_label")).get(), "sf.gui.CLabelWidget")
		bonus_info_label.SetSize(help_window.BonusInfoTextPos.Width, help_window.BonusInfoTextPos.Height)
		bonus_info_label.SetText(current_bonus_info.Description)
		bonus_info_label.ResizeToFitText(true)
		bonus_info_label.SetOffset(help_window.BonusInfoTextPos.X, help_window.BonusInfoTextPos.Y)
				
		if _bonus_id and _bonus_id ~= "" then
			local bonus_image = sf.graphics.CImage(_T(current_bonus_info.BackImageId))
			if bonus_image then
				local bonus_widget = sf.gui.CWidgetPtrT(sf.gui.CImageWidget(bonus_image, _T("bonus_image_widget"), 0, 0))
				if bonus_widget then
					image_size = bonus_widget.get().GetSize()
					bonus_widget.get().SetOffset(help_window.BonusInfoIconPos.X - image_size.X/2, help_window.BonusInfoIconPos.Y - image_size.Y/2)
					window.AddWidget(bonus_widget)
				end
			end

			bonus_image = sf.graphics.CImage(_T(current_bonus_info.ImageId))
			if bonus_image then
				local bonus_widget = sf.gui.CWidgetPtrT(sf.gui.CImageWidget(bonus_image, _T("bonus_image_widget"), 0, 0))
				if bonus_widget then
					image_size = bonus_widget.get().GetSize()
					bonus_widget.get().SetOffset(help_window.BonusInfoIconPos.X - image_size.X/2, help_window.BonusInfoIconPos.Y - image_size.Y/2)
					window.AddWidget(bonus_widget)
				end
			end

			bonus_image = sf.graphics.CImage(_T(current_bonus_info.GlareImageId))
			if bonus_image then
				local bonus_widget = sf.gui.CWidgetPtrT(sf.gui.CImageWidget(bonus_image, _T("bonus_image_widget"), 0, 0))
				if bonus_widget then
					image_size = bonus_widget.get().GetSize()
					bonus_widget.get().SetOffset(help_window.BonusInfoIconPos.X - image_size.X/2, help_window.BonusInfoIconPos.Y - image_size.Y/2)
					window.AddWidget(bonus_widget)
				end
			end
			
		end

		]]
		local window_ptr = help_window.create_bonus_info_window(_bonus_id)
		
		if	window_ptr then
			MoveWindowToCenter(_owner, window_ptr)
			_owner.DoModal(window_ptr) 
		end
--	end
end


function help_window.run_help_window(_owner)
	help_window.BonusInfo = help_window.LoadBonusesInfo()
	
	local app = sf.core.g_Application
	local window = s4.COnKeyDownWindow()
	window.Load(
		app.GetSettings().GetChild(_T("GUI"), false).GetChildByAttribute(_T("window"), _T("id"), _T("s4_help_window"), true), 
		app.GetSettings().GetChild(_T("GUITemplates"), false))
	window.UpdateLayout()
	MoveWindowToCenter(_owner, window)
	for table_index in pairs(help_window.PageFixedTablesIds) do
		local current_table = help_window.PageFixedTablesIds[table_index]
		for child_widget_id in pairs(current_table.ChildWidgets) do
			local child_widget = window.GetWidget(_T(child_widget_id)).get()
			if child_widget then
				current_table.ChildWidgets[child_widget_id] = child_widget
				set_widget_flag_value(current_table.ChildWidgets[child_widget_id], sf.gui.CBaseWidget.FlagHidden, true)
				set_widget_flag_value(current_table.ChildWidgets[child_widget_id], sf.gui.CBaseWidget.FlagDisabled, true)
				
			end
		end
	

		local table_widget = __cast(window.GetWidget(current_table.Id).get(), "s4.CFixedTableWidget")
		if table_widget then
			local cell_size = table_widget.GetCellSize()
			current_table.Widget = table_widget
			table_widget.SetSelectMode(help_window.PageFixedTablesIds[table_index].SelectMode)
			local original_size = table_widget.GetSizeInCells()
			table_widget.SetOffset(current_table.Offset.X, current_table.Offset.Y)
			for i = 0,current_table.RowCount-2 do
				table_widget.AddRow()
			end
			table_widget.SetVisibleSizeInCells(current_table.RowCount, original_size.X)
			set_widget_flag_value(table_widget, sf.gui.CBaseWidget.FlagHidden, true)
			set_widget_flag_value(table_widget, sf.gui.CBaseWidget.FlagDisabled, true)
			
			for i = 1, current_table.SizeInCells.Y do
				for j = 1, current_table.SizeInCells.X do
					table_widget.SetFlagsToCell(i-1, j-1, current_table.Cells[i][j].Flags)					
					if current_table.Cells[i][j].BonusId ~= "" then
						local current_bonus_info = help_window.BonusInfo[current_table.Cells[i][j].BonusId]
						if current_bonus_info then
							table_widget.SetHintToCell(i-1, j-1, current_bonus_info.Name)
							local back_image = sf.graphics.CImage(_T(current_bonus_info.BackImageId))
							if back_image then
								
								local back_widget = sf.gui.CWidgetPtrT(sf.gui.CImageWidget(back_image, _T(current_table.Cells[i][j].BonusId.."_back_image_widget"), 0, 0))
								if back_widget then
									__cast(back_widget.get(), "sf.gui.CImageWidget").GetImage().SetAnimationK(0)
									help_window.SetCellCenterOffset(back_widget, cell_size)
									table_widget.GetCell(i-1, j-1).AddWidget(back_widget)
								end
							end
							
							local bonus_image = sf.graphics.CImage(_T(current_bonus_info.ImageId))
							if bonus_image then
								local bonus_widget = sf.gui.CWidgetPtrT(sf.gui.CImageWidget(bonus_image, _T(current_table.Cells[i][j].BonusId.."_icon_image_widget"), 0, 0))
								if bonus_widget then
									__cast(bonus_widget.get(), "sf.gui.CImageWidget").GetImage().SetAnimationK(0)
									help_window.SetCellCenterOffset(bonus_widget, cell_size)
									table_widget.GetCell(i-1, j-1).AddWidget(bonus_widget)
								end
							end
							
							local glare_image = sf.graphics.CImage(_T(current_bonus_info.GlareImageId))
							if glare_image then
								
								local glare_widget = sf.gui.CWidgetPtrT(sf.gui.CImageWidget(glare_image, _T(current_table.Cells[i][j].BonusId.."_glare_image_widget"), 0, 0))
								if glare_widget then
									__cast(glare_widget.get(), "sf.gui.CImageWidget").GetImage().SetAnimationK(0)
									help_window.SetCellCenterOffset(glare_widget, cell_size)
									table_widget.GetCell(i-1, j-1).AddWidget(glare_widget)
								end
							end
							
							
						end
					end
				end
			end
		end
	end

	


	help_window.activate_page_help(window, 1)

	local window_ptr = sf.gui.CBaseWindowPtrT(window)
	set_widget_flag_value(_owner, sf.gui.CBaseWidget.FlagHidden, true)
	_owner.DoModal(window_ptr) 
	set_widget_flag_value(_owner, sf.gui.CBaseWidget.FlagHidden, false)
	
end

function help_window.activate_page_help(_owner, _page_number)

	local title_label = __cast(_owner.GetWidget(_T("title_label")).get(), "sf.gui.CLabelWidget")
	title_label.SetText(sf.misc.g_StringTable.Instance().FormatByStringsID(help_window.PageWindowTitles[_page_number]))
	
-- активирую все кнопки страниц
	for button_index in pairs(help_window.PageButtonsIds) do
		local button_widget = __cast(_owner.GetWidget(help_window.PageButtonsIds[button_index]), sf.gui.CButtonWidget)
		if button_widget then
			button_widget.DisableButton(false)
		end
	end
	
-- дезаблю кнопку текущей страницы
	local button_widget = __cast(_owner.GetWidget(help_window.PageButtonsIds[_page_number]), sf.gui.CButtonWidget)
	if button_widget then
		button_widget.DisableButton(true)
	end
	
--дизеблю все таблицы	
	for table_index in pairs(help_window.PageFixedTablesIds) do
		local table_widget = __cast(_owner.GetWidget(help_window.PageFixedTablesIds[table_index].Id), s4.CFixedTableWidget)
		if table_widget then
			set_widget_flag_value(table_widget, sf.gui.CBaseWidget.FlagHidden, true)
			set_widget_flag_value(table_widget, sf.gui.CBaseWidget.FlagDisabled, true)
		end
		local current_table = help_window.PageFixedTablesIds[table_index]
		for child_widgedt_id in pairs(current_table.ChildWidgets) do
			set_widget_flag_value(current_table.ChildWidgets[child_widgedt_id], sf.gui.CBaseWidget.FlagHidden, true)
			set_widget_flag_value(current_table.ChildWidgets[child_widgedt_id], sf.gui.CBaseWidget.FlagDisabled, true)
		end
		
	end

--активирую таблицу текущей страницы
	local table_widget = __cast(_owner.GetWidget(help_window.PageFixedTablesIds[_page_number].Id), s4.CFixedTableWidget)
	if table_widget then
		set_widget_flag_value(table_widget, sf.gui.CBaseWidget.FlagHidden, false)
		set_widget_flag_value(table_widget, sf.gui.CBaseWidget.FlagDisabled, false)
	end
																		
	

	local current_table = help_window.PageFixedTablesIds[_page_number]
	for child_widgedt_id in pairs(current_table.ChildWidgets) do
		set_widget_flag_value(current_table.ChildWidgets[child_widgedt_id], sf.gui.CBaseWidget.FlagHidden, false)
		set_widget_flag_value(current_table.ChildWidgets[child_widgedt_id], sf.gui.CBaseWidget.FlagDisabled, false)
	end
	
	
end

function help_window.help_window_script(_owner, _action, _child)
	if _child.GetId()==_T("about_button") and _action==_T("pressed") then
		help_window.run_about_window(_owner)
	elseif _child.GetId()==_T("page1_button") and _action==_T("pressed") then
		help_window.activate_page_help(_owner, 1)
	elseif _child.GetId()==_T("page2_button") and _action==_T("pressed") then
		help_window.activate_page_help(_owner, 2)
	elseif _child.GetId()==_T("ok_button") and _action==_T("pressed") or _action == _T("key_down_enter") or _action == _T("key_down_escape") then
		_owner.EndModal(1)
	elseif _child.GetId()==_T("bonus_fixed_table") and _action==_T("cell_selected") then
		--[[
		local table_widget = __cast(_owner.GetWidget(_T("bonus_fixed_table")).get(), "s4.CFixedTableWidget")
		if table_widget then
			local selected_cell = table_widget.GetSelectedCell()
			log("selected cell = ".."("..tostring(selected_cell.X).."."..tostring(selected_cell.Y)..")" )
			local current_table = help_window.PageFixedTablesIds[1]
			if table_widget then
				for i = 1, current_table.SizeInCells.Y do
					for j = 1, current_table.SizeInCells.X do
						
						if selected_cell.Y == i-1 and selected_cell.X == j-1 then
								log("skip dis")
						else
							
							current_cell = table_widget.GetCell(i-1, j-1)
							local widget = current_cell.GetWidgets()
							while not widget.IsEnd() do 
								--
								local image_widget = __cast(widget.Get().get(), "sf.gui.CImageWidget")
								if image_widget then
									
									image_widget.GetImage().SetAnimationK(0)
									image_widget.GetImage().SetFrame(0)
									log("dis"..T_(image_widget.GetId()).c_str())
								end
								widget.Next()
							end	
						end
						
					end
				end
			end
			
			if selected_cell.X ~= -1 and selected_cell.Y ~= -1 then
				current_cell = table_widget.GetCell(selected_cell.Y, selected_cell.X)
				local widget = current_cell.GetWidgets()
				while not widget.IsEnd() do 
					--
					local image_widget = __cast(widget.Get().get(), "sf.gui.CImageWidget")
					if image_widget then
						image_widget.GetImage().SetAnimationK(1)
						log("en"..T_(image_widget.GetId()).c_str())
					end
					widget.Next()
				end	
			end
			
		end
	]]
	elseif _child.GetId()==_T("bonus_fixed_table") and _action==_T("mouse_click") then
		local table_widget = __cast(_owner.GetWidget(_T("bonus_fixed_table")).get(), "s4.CFixedTableWidget")
		if table_widget then
			local celected_cell = table_widget.GetSelectedCell()
			if celected_cell.X ~= -1 and celected_cell.Y ~= -1 then
				local bonus_id = help_window.PageFixedTablesIds[1].Cells[celected_cell.Y+1][celected_cell.X+1].BonusId
				help_window.run_bonus_info_window(_owner, bonus_id)		
			end
			
		end
	end
end

function help_window.about_window_script(_owner, _action, _child)
	if _action==_T("key_down_enter") then
		_owner.EndModal(1)
	elseif _action==_T("key_down_escape") then
		_owner.EndModal(0)
	elseif _child.GetId()==_T("ok_button") and _action==_T("pressed") then
		_owner.EndModal(1)
	end
end

function help_window.bonus_info_window_script(_owner, _action, _child)
	if _action==_T("key_down_enter") then
		_owner.EndModal(1)
	elseif _action==_T("key_down_escape") then
		_owner.EndModal(0)
	elseif _child.GetId()==_T("ok_button") and _action==_T("pressed") then
		_owner.EndModal(1)
	end
end
