function ListProducts(){

/* write page changers */

TotalItem = $('#product-list .pro-box').length; // count item total
Pages = Math.ceil(TotalItem/Items); //count page total

if($.cookie('searchparams')){
   searchP = $.cookie('searchparams').split('&');
}

  if(Pages == 1){
  $('#product-list-head').hide(); //hide page changers/view all button if only 1 page
  $('#product-list-foot').hide();
  }else{
Arrows = 0;

    for(var p=1;p<=Pages;p++){



      if((p-1)%3 == 0 && p!=1){ // write arrows every 3 pages
        PreviousSet = p - 1;
        Arrows = Arrows + 1;
        $('<a href="#product-list" class="PageArrow" onclick="ChangePage('+p+','+Arrows+',0);">>></a>').insertAfter('#product-list-head .PageChanger:last');
        $('<a href="#product-list" class="PageArrow" onclick="ChangePage('+p+','+Arrows+',0);">>></a>').insertAfter('#product-list-foot .PageChanger:last');
        Arrows = Arrows + 1;
        $('<a href="#product-list" class="PageArrow" onclick="ChangePage('+p+'-1,0,'+Arrows+');"><<</a>').insertAfter('#product-list-head .PageArrow:last');
        $('<a href="#product-list" class="PageChanger" onclick="ChangePage('+p+',0,0);">'+p+'</a>').insertAfter('#product-list-head .PageArrow:last');
        $('<a href="#product-list" class="PageArrow" onclick="ChangePage('+p+'-1,0,'+Arrows+');"><<</a>').insertAfter('#product-list-foot .PageArrow:last');
        $('<a href="#product-list" class="PageChanger" onclick="ChangePage('+p+',0,0);">'+p+'</a>').insertAfter('#product-list-foot .PageArrow:last');
      }else{

      $('<a href="#product-list" class="PageChanger" onclick="ChangePage('+p+',0,0);">'+p+'</a>').insertAfter('#product-list-head .PageChanger:last');
      $('<a href="#product-list" class="PageChanger" onclick="ChangePage('+p+',0,0);">'+p+'</a>').insertAfter('#product-list-foot .PageChanger:last');

      }
    }

    $('#product-list-head .PageChanger').slice(0,Math.min(Pages+1,4)).show();
    $('#product-list-head .PageArrow').slice(1,Math.min(2,('#product-list-foot .PageArrow').length+1)).show();
    $('#product-list-foot .PageChanger').slice(0,Math.min(Pages+1,4)).show();
    $('#product-list-foot .PageArrow').slice(1,Math.min(2,('#product-list-foot .PageArrow').length+1)).show();

  }

/* end write page changers */

/* go to specified page */

if($.cookie('ViewAll') == '1'){
  ViewAll();
  $.cookie('PageNo',0,{path:'/'});   // delete cookie
  $.cookie('ArrowNo',0,{path:'/'});  // delete cookie
}else{
  $('#product-list-head .div-viewAll').show();
  $('#product-list-foot .div-viewAll').show();

if(searchP != null){

   for(i=0;i<searchP.length;i++){
      if(searchP[i].indexOf('searchpath=') != -1){
         sPath = searchP[i].split('=')[1];
         if(sPath != $.cookie('searchPath')){
             $.cookie('searchPath',sPath,{path:'/'});
             $.cookie('PageNo',0,{path:'/'});   // delete cookie
             $.cookie('ArrowNo',0,{path:'/'});  // delete cookie
             ChangePage(1,0,0);
         }else{
             if($.cookie('PageNo')>0){
               thisPage = new Number($.cookie('PageNo'));
                 if($.cookie('ArrowNo')>0){
                 thisArrow = new Number($.cookie('ArrowNo'));
                 }else{
                 thisArrow = 0;
                 }
               ChangePage(thisPage,thisArrow,0);
             }else{
               ChangePage(1,0,0); //no page # defined, go to page 1
             }
         }
      }
   } // end for loop
}else{
    ChangePage(1,0,0);
} // end if searchparams

}// end if ViewAll

/* end go to specified page */

/* highlight current category link on left */

if(searchP != null){
   for(i=0;i<searchP.length;i++){
      if(searchP[i].indexOf('category=') != -1){
         cPath = searchP[i].split('=')[1];
             plusSign = /\+/g;
             colon = /\:/g;
             iComma = /\'/g;
             cPath = cPath.replace(plusSign, '')
             cPath = cPath.replace(colon, '-');
             cPath = cPath.replace(iComma, '');
             //$('#'+cPath).css("color","#635A45");
			 $('#'+cPath).css("color",focusCat);
      }
   } // end for loop
}

/* end highlight current category link on left */

}

function ChangePage(Page,Arrow,ArrowBack){

  $.cookie('PageNo',Page,{path:'/'}); // set page number to cookies

 var Start = (Page - 1) * Items;
 var End = Start + Items;

   $('#product-list .pro-box').hide();
   $('#product-list .pro-box').slice(Start,End).show();
   $('.PageChanger').css("color",ChangerColor2);
   $('#product-list-head .PageChanger').slice(0,1).css("color",ChangerColor);
   $('#product-list-foot .PageChanger').slice(0,1).css("color",ChangerColor);
   $('#product-list-head .PageChanger').slice(Page,Page+1).css("color",ChangerColor); 
   $('#product-list-foot .PageChanger').slice(Page,Page+1).css("color",ChangerColor);

   if(Arrow){

     if(Page%3 == 2){
       Page = Page - 1;
     }

     if(Page%3 == 0){
       Page = Page - 2;
     }

     $('#product-list-head .PageChanger').slice(1).hide();
     $('#product-list-head .PageArrow').hide();
     $('#product-list-head .PageChanger').slice(Page,Math.min(Page+3,Pages+1)).show();
     $('#product-list-head .PageArrow').slice(Arrow+1,Math.min(Arrow+3,Arrows+2)).show();
     $('#product-list-foot .PageChanger').slice(1).hide();
     $('#product-list-foot .PageArrow').hide();
     $('#product-list-foot .PageChanger').slice(Page,Math.min(Page+3,Pages+1)).show();
     $('#product-list-foot .PageArrow').slice(Arrow+1,Math.min(Arrow+3,Arrows+2)).show();
     $.cookie('ArrowNo',Arrow,{path:'/'});
   }

   if(ArrowBack){

     $('#product-list-head .PageChanger').slice(1).hide();
     $('#product-list-head .PageArrow').hide();
     $('#product-list-head .PageChanger').slice(Page-2,Page+1).show();
     $('#product-list-head .PageArrow').slice(Math.max(1,ArrowBack-2),ArrowBack).show();
     $('#product-list-foot .PageChanger').slice(1).hide();
     $('#product-list-foot .PageArrow').hide();
     $('#product-list-foot .PageChanger').slice(Page-2,Page+1).show();
     $('#product-list-foot .PageArrow').slice(Math.max(1,ArrowBack-2),ArrowBack).show();
     $.cookie('ArrowNo',ArrowBack-3,{path:'/'});
   }

}

function ViewAll(){
      $('#product-list .pro-box').show();
      $('#product-list-head .div-viewPage').show();
      $('#product-list-foot .div-viewPage').show();
      $('#product-list-head .div-viewAll').hide();
      $('#product-list-foot .div-viewAll').hide();
      $.cookie('ViewAll','1',{path:'/'});
}

function ViewPage(){

      $('#product-list-head .div-viewPage').hide();
      $('#product-list-foot .div-viewPage').hide();
      $('#product-list-head .div-viewAll').show();
      $('#product-list-foot .div-viewAll').show();
      $('.PageChanger').css("color",ChangerColor2);
      $('#product-list-head .PageChanger').slice(0,1).css("color",ChangerColor);
      $('#product-list-head .PageChanger').slice(0,1).css("color",ChangerColor);
      $('#product-list-head .PageChanger').slice(1,2).css("color",ChangerColor); 
      $('#product-list-foot .PageChanger').slice(1,2).css("color",ChangerColor);
      $.cookie('ViewAll','0',{path:'/'});

  if($.cookie('PageNo')>0){
    thisPage = new Number($.cookie('PageNo'));
      if($.cookie('ArrowNo')>0){
      thisArrow = new Number($.cookie('ArrowNo'));
      }else{
      thisArrow = 0;
      }
    ChangePage(thisPage,thisArrow,0);
  }else{
    ChangePage(1,0,0);
  }
}