Ah, I see you use the "theValue" hidden input for the count. In that case instead of setting a global variable, set the hidden variable and you can set it directly without using JavaScript:
Code:
<input type="hidden" value="#count#" id="theValue" />
Comment