private function findNextPrev(LoopResultRow $loopResultRow, $imageId, $imageType, $currentPosition)
    {
        if ($imageType == 'product') {
            $imageRow = ProductImageQuery::create()
                ->filterById($imageId)
                ->findOne();

            if ($imageRow != null) {
                $previousQuery = ProductImageQuery::create()
                    ->filterByProductId($imageRow->getProductId())
                    ->filterByPosition($currentPosition, Criteria::LESS_THAN);

                $nextQuery = ProductImageQuery::create()
                    ->filterByProductId($imageRow->getProductId())
                    ->filterByPosition($currentPosition, Criteria::GREATER_THAN);

                if (!$this->getBackendContext()) {
                    $previousQuery->useProductQuery()
                        ->filterByVisible(true)
                        ->endUse();

                    $previousQuery->useProductQuery()
                        ->filterByVisible(true)
                        ->endUse();
                }

                $previous = $previousQuery
                    ->orderByPosition(Criteria::DESC)
                    ->findOne();

                $next = $nextQuery
                    ->orderByPosition(Criteria::ASC)
                    ->findOne();

                $loopResultRow
                    ->set("HAS_PREVIOUS", $previous != null ? 1 : 0)
                    ->set("HAS_NEXT", $next != null ? 1 : 0)
                    ->set("PREVIOUS", $previous != null ? $previous->getId() : -1)
                    ->set("NEXT", $next != null ? $next->getId() : -1);

                return;
            }
        }

        $loopResultRow
            ->set("HAS_PREVIOUS", 0)
            ->set("HAS_NEXT", 0);
    }