I am using the following ajax jquery function to track scrolling. It works fine for me. Pay no attention to the %% parameters they are substituted at run time.

Code:
<script type="text/javascript">
$(document).ready(function(){
    setInterval(function() {
 		x=GetScrolledTop();
 		y=document.body.scrollHeight;
 		z=$(window).height();
 		j=$(document).height();
        jQuery.ajax({
            type: "GET",
            url: "scrollposition.blp?z="+x+"-"+y+"-"+z+"-"+j+"&bar="+%barid%+"&lid=%landingid%"+"&sid=%sessionid%"+"&sh="+screen.height+"&sw="+screen.width ,
            dataType:"json",
            success:function(response){
	        }
        });
    }, 5000);
});

I want to limit this function to run for a total specified time max. For example, this snippet polls every 5 seconds. I need to have this function stop after x polls or x minutes total to prevent a rogue page which gets left open in a browser from consuming useless resources. What is the easiest way to accomplish this?

Thanks in advance for any assistance...