jQuery(function($) {
      $(document).ready(function() {
        $('.toolbar .sorter, .toolbar .pages, , .toolbar .limiter').hide();
		$('.toolbar').last().hide();
          var loader = '<div class="products-loader" style="display:none;">Lade weitere Artikel...</div>';
          $('.category-products').last().after(loader);
            var wait = 0;
            var page = 2;
            $('.back_to_top').css({'top':$(window).height(),
                                   'margin-left':($.browser.webkit?$('.category-products').outerWidth():0)});
          $(window).scroll(function() {
             if($('.pager .pages li a').first().lenth){
			                        var url  = $('.pager .pages li a').first().attr('href').replace(/p=([0-9])/, 'p='+page);
			                        var lastpagecheck = $('.toolbar').last().find('.pager .pages li').last().find('a').length &&
			                                   $('.toolbar').last().find('.pager .pages li').last().find('a').hasClass('next');
			                    }else if($('.pager .limiter option').first().length){
			                        var url = $('.pager .limiter option').first().val().replace(/limit=([0-9])/, '');
			                        url += '&p='+page;
			                        var lastpagecheck = (parseInt($('.toolbar .amount strong:eq(2)').text()) - parseInt($('.toolbar .amount strong:eq(1)').text()))>0?true:false;
			                    }

              if($(window).scrollTop()<=$('.back_to_top').outerHeight()){                 
                $('.back_to_top').css('top', $(window).height()-$(window).scrollTop())
              }else if(parseInt($('.back_to_top').css('top'))>$(window).height()-($('.back_to_top').outerHeight())){
                $('.back_to_top').css({'top': $(window).height()-$('.back_to_top').outerHeight()})
              }

              if (($(window).scrollTop() > $(document).height() - $(window).height()-($(window).height()*0.8))
                  && (lastpagecheck)
                  && (wait == 0)) {
                  wait = 1;
                  $('.category-products').last().after('<div class="newitem"></div>');
                  $('.products-loader').fadeIn();
                  $('.newitem').load(url+' .category-products', null, function(){
                      page++;
                      $('.newitem .category-products .toolbar').hide();
                      $('.newitem .category-products').addClass('new');
					                        	$.each($('.category-products.new .rowwrapper'), function(){
														maxPriceHeight = 0;
					//									maxSpecsHeight = 0;
														$.each($(this).find('.boxcontainer'),function(){

															if(parseInt($(this).find('.price-box').outerHeight())>maxPriceHeight) maxPriceHeight = $(this).find('.price-box').outerHeight();
					//										if(parseInt($(this).find('.product-specs').outerHeight())>maxSpecsHeight) maxSpecsHeight = $(this).find('.product-specs').outerHeight();
														})
														$(this).find('.boxcontainer .price-box').css('height', maxPriceHeight);
					//									$(this).find('.boxcontainer .product-specs').css('height', maxSpecsHeight);

													})
                      $('.toolbar .amount strong:eq(1)').text($('.newitem .category-products .product-box').length+parseInt($('.toolbar .amount strong:eq(1)').text()));
                      $('.newitem .category-products').hide().slideDown('normal', function(){                          
						  initProductOverlay(true);
					   	  $(this).unwrap().removeClass('new');
					      $('.products-loader').fadeOut();
                                             

                          wait = 0;
                      })
                  });
              } 
          });
      });
  });

