//Updates scroll down and load on demand
var scrollTolerance = 0.9;
var scrollAllowed = true;
$(window).scroll(function() {
	var scrollTop = $(this).scrollTop();
	var windowHeight = $(this).height();
	var documentHeight = $(document).height();
	if(scrollTolerance < (scrollTop + windowHeight) / documentHeight && scrollAllowed) {
		// Disable scroll
		scrollAllowed = false;
		
		// Show loader
		$('#search-loader').show('slow');
		
		// Load updates for this period and add to list
		$.ajax({
			type:'GET',
			url:'/hdvideos-period.php',
			data:{ fromVideo:lastVideoVisible },
			success:function(data) {
				// Hide loader
				$('#search-loader').hide('slow');
				
				// Append data to list
				$('#videos-on-demand')[0].innerHTML += data;
				
				// Set last video visible
				lastVideoVisible += 12;
				// Allow scroll
				scrollAllowed = true;
				
				// Refresh headlines (Cufon rendering)
				Cufon.refresh();
			}
		});

	}
});