$(document).ready(function() {
	if ($('body').hasClass('page-catalog')) {
	
		//Get the number of pages from the Views Pager (Use the full pager, it will be hidden with .infinitescroll() anyway.)
		lastPageHref = $(".pager-last").find('a').attr('href').toString(); 
		lastPageHref = lastPageHref.split("=");
		numOfPages = parseInt(lastPageHref[1]);
			
	    $('.view-content').infinitescroll({
	        navSelector  : ".page-catalog .view .pager",    // selector for the paged navigation 
	        nextSelector : ".page-catalog .view .pager .pager-next a",    // selector for the NEXT link (to page 2)
	        itemSelector : ".view-spectacles .views-row, .view-sunglasses .views-row, .view-readingglasses .views-row, .view-contactlenses .views-row",       // selector for all items you'll retrieve
	        loadingText     : "H&auml;mtar fler b&aring;gar...",
	        loadingImg : 'http://scandinavianeyes.se/sites/all/themes/yes/images/ajax-loader-1.gif',
	        donetext  : "Det var allt.",
	        debug: false,
			pages: numOfPages, //NEW OPTION: number of pages in the Views Pager
	        errorCallback: function() { 
	        	$('#infscr-loading').animate({opacity: 1},2000).fadeOut('normal');     // fade out the error message after 2 seconds
	        }
	    },
		    function() { 
		    	$('.view-content').append(this);
		    	$('#infscr-loading').animate({opacity: 1},1000).fadeOut('normal');
		    }
	    );
	}
});



