XF 2.1 Showing Ads before 2nd last post IF total posts on page more than 6?

I would like to place an Ad before second last post IF there are more than 6 posts on that page.
Any ideas how I can do that?

P.S. I am also showing an Ad after 2nd post if there are more than 4 posts on that page and following code works fine for this:
HTML:
<xf:if is="$post.position % $xf.options.messagesPerPage==1 AND count($__globals.posts)>4">
        <!--AdCode here-->
</xf:if>
 
If anyone else wants, this seemed to do the trick for me:

HTML:
<xf:if is="$post.position == $xf.options.messagesPerPage - 3 OR $post.position % $xf.options.messagesPerPage + 3 == count($__globals.posts) AND count($__globals.posts) >= 6">
 
Top Bottom