public function generatePageNavigation($positionCount = 0)
    {
        startProfile('generatePageNavigation');

        $pageNavigation = new StdClass();

        $pageNavigation->NrOfPages = $this->_iCntPages;
        $activePage = $this->getActPage();
        $pageNavigation->actPage = $activePage + 1;
        $url = $this->generatePageNavigationUrl();

        if ($positionCount == 0 || ($positionCount >= $pageNavigation->NrOfPages)) {
            $startNo = 2;
            $finishNo = $pageNavigation->NrOfPages;
        } else {
            $tmpVal = $positionCount - 3;
            $tmpVal2 = floor(($positionCount - 4) / 2);

            // actual page is at the start
            if ($pageNavigation->actPage <= $tmpVal) {
                $startNo = 2;
                $finishNo = $tmpVal + 1;
                // actual page is at the end
            } elseif ($pageNavigation->actPage >= $pageNavigation->NrOfPages - $tmpVal + 1) {
                $startNo = $pageNavigation->NrOfPages - $tmpVal;
                $finishNo = $pageNavigation->NrOfPages - 1;
                // actual page is in the middle
            } else {
                $startNo = $pageNavigation->actPage - $tmpVal2;
                $finishNo = $pageNavigation->actPage + $tmpVal2;
            }
        }

        if ($activePage > 0) {
            $pageNavigation->previousPage = $this->_addPageNrParam($url, $activePage - 1);
        }

        if ($activePage < $pageNavigation->NrOfPages - 1) {
            $pageNavigation->nextPage = $this->_addPageNrParam($url, $activePage + 1);
        }

        if ($pageNavigation->NrOfPages > 1) {
            for ($i = 1; $i < $pageNavigation->NrOfPages + 1; $i++) {
                if ($i == 1 || $i == $pageNavigation->NrOfPages || ($i >= $startNo && $i <= $finishNo)) {
                    $page = new stdClass();
                    $page->url = $this->_addPageNrParam($url, $i - 1);
                    $page->selected = ($i == $pageNavigation->actPage) ? 1 : 0;
                    $pageNavigation->changePage[$i] = $page;
                }
            }

            // first/last one
            $pageNavigation->firstpage = $this->_addPageNrParam($url, 0);
            $pageNavigation->lastpage = $this->_addPageNrParam($url, $pageNavigation->NrOfPages - 1);
        }

        stopProfile('generatePageNavigation');

        return $pageNavigation;
    }