jQuery(function(){
    
    
    
    
    
    jQuery('.categoryFilters').each(function(){
        var cats = $("li:gt(4)", this);
        
        var add_less_button=function(){
            var show_less=$('<li class="showMoreCategories"><a href="">show less</a></li>');
           console.log(show_less);
           
           sl_click=function(){
                
                cats.hide();
                
                add_more_button();
                $(this).remove();
                return false;
            }
           
           
            show_less.click(sl_click);
  
            $(cats[cats.length-1 ]).after(show_less);
            
        }
        
        add_more_button=function(){
            var show_more = $('<li class="showMoreCategories"><a href="">show more</a></li>').click(function(){
                
                cats.show();
                
                add_less_button();
                $(this).remove();
                return false;
            })
            $(cats[cats.length-1 ]).after(show_more);
             
            
        }
        
        if (cats.length > 0) { // this is the "intelligence", if there are at least 3 more than 5, trigger  show more
            cats.hide();
            add_more_button();
            
        }
        
        
        
        
    })
})

