(function($) {
	$.fn.scrollPagination = function(options) {	
		var settings = { 
			nop     : 10, 
			offset  : 0,
			error   : 'Load more', 
			user	: '',
			delay   : 100, 
			scroll  : false
		}	
		if(options) {
			$.extend(settings, options);
		}	
		return this.each(function() {				
			$this = $(this);
			$settings = settings;
			var offset = $settings.offset;
			var busy = false; 		
			if($settings.scroll == true) $initmessage = '';
			else $initmessage = '<a style="width:150px;" class="loadposts">'+$settings.error+'</a>';		
			$("#loadq").append($initmessage);		
			function getData() {
				var txt = $('.loadposts').html();
				$('.loadposts').html('<img src="../media/images/wait.gif" style="margin-bottom:2px;margin-top:2px">');
				$.post('ajax/getposts', {	
					user		  : $settings.user,
				    number        : $settings.nop,
				    offset        : offset 
				}, function(data) {
					if(data == "") { 
						$this.find('.loadposts').css('display','none');	
					}
					else {
					    offset = offset+$settings.nop; 
					   	$this.find('#questionpage').append(data);
						$('.loadposts').html(txt);
						$(".img").imgLiquid();
						busy = false;
					}							
				});				
			}				
			if($settings.scroll == true) {
				$(window).scroll(function() {					
					if($(window).scrollTop() + $(window).height() > $this.height() && !busy) {						
						busy = true;
						$this.find('.loadposts').html('');
						setTimeout(function() {							
							getData();
						}, $settings.delay);		
					}	
				});
			}
			$this.find('.loadposts').click(function() {		
				if(busy == false) {
					busy = true;
					getData();
				}
			});	
		});
	}
})(jQuery);