
--------------------------------------------------------------------------------
function CreateNavigaionPanel(screen, tab, parent, x,y, buttonsEventMap)

    -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	local auxCreateNavigationButton = function(tab, parent, x,y, name, buttonPressHandlerName, active)
		assert(screen ~= nil);

   	    local button = MakeButton(x, y, 50, 50);
		button:DisableIfHidden(true);
   	    button:GetCaption():SetFont(BUTTONS_FONT);
   		button:GetCaption():SetScale(0.8);
   		button:SetZ(1.0);

		if (active == false) then
			button:Stop();
			button:SetVisible(false);
		else
			button:Go();
			button:SetVisible(true);
		end
    	
   		button:AttachTo(parent);
   		if (buttonPressHandlerName) then
   		    button:SetAction(buttonPressHandlerName);
   		end
   		button:SetSpriteUp('ButtonNavigate'..name);
   		button:SetSpriteOver('ButtonNavigate'..name..'Over');
   		button:SetSpriteDown('ButtonNavigate'..name..'Down');
   		button:SetActionSound('Menu_button_click');

		tab.navigationButtons[name] = button;
	end

	if (buttonsEventMap ~= nil) then
		local navigationPavel = screen:CreateAnimation('data/Texture/GUI/Extras/navigationButtonsPanel.png');
		navigationPavel:AttachTo(parent);
        navigationPavel:SetHotSpot(70, 27);
        navigationPavel:SetXY(x, y);
        navigationPavel:SetZ(1.0);
        
		tab.navigationPanel = navigationPavel;
		if (tab.navigationButtons == nil) then
			tab.navigationButtons = {};
		end

		for buttonName, eventHandlerName in pairs(buttonsEventMap) do
			if     (buttonName == 'Prev') then
				auxCreateNavigationButton(tab, navigationPavel, -40, 0, 'Prev', eventHandlerName);
			elseif (buttonName == 'Play') then
				auxCreateNavigationButton(tab, navigationPavel,   0, 0, 'Play', eventHandlerName);
			elseif (buttonName == 'Stop') then
				auxCreateNavigationButton(tab, navigationPavel,   0, 0, 'Stop', eventHandlerName, false);
			elseif (buttonName == 'Next') then
				auxCreateNavigationButton(tab, navigationPavel,  40, 0, 'Next', eventHandlerName);
			elseif (buttonName == 'Save' or buttonName == 'Set') then
				assert((buttonsEventMap.Save and buttonsEventMap.Set == nil) or
					   (buttonsEventMap.Save == nil and buttonsEventMap.Set));

	    	    local SaveButton = MakeButton(380 - 235, 0, 100, 40);
				SaveButton:DisableIfHidden(true);
	    	    SaveButton:GetCaption():SetFont(BUTTONS_FONT);
	    		SaveButton:GetCaption():SetScale(0.8);
	    		SaveButton:SetZ(1.0);
    	
	    		SaveButton:AttachTo(navigationPavel);
	    		SaveButton:SetAction(eventHandlerName);
				if (buttonName == 'Save') then
		    		SaveButton:SetSpriteUp('ButtonSave');
		    		SaveButton:SetSpriteOver('ButtonSaveOver');
		    		SaveButton:SetSpriteDown('ButtonSaveDown');
				else
		    		SaveButton:SetSpriteUp('ButtonSet');
		    		SaveButton:SetSpriteOver('ButtonSetOver');
		    		SaveButton:SetSpriteDown('ButtonSetDown');
				end
	    		SaveButton:SetActionSound('Menu_button_click');
	    		
	    		tab.navigationButtons[buttonName] = SaveButton;
			else
				assert(Log('Unknown button name was specified') or false);
			end
    	end
	end
end
