Most of this isn't needed.
If you only want to show ads on a thread which has a certain number of replies, then you will just want this:
HTML:
<xf:if is="$thread.reply_count > 2">
<!-- blah -->
</xf:if>
If you want it dependent on the number of posts on the page then you could always use __globals:
HTML:
<xf:if is="count($__globals.posts) > 2">
<!-- blah -->
</xf:if>