﻿/*
* FUNCTION FOR HILL'S PET NUTRITION - CAT CARE REFRESH
* CREATED BY: THOMAS WORONIAK
* CREATED ON: 12/05/09
*/
(function($) {
    $.fn.alternateToggle = function(){        
        // Give each list an unique id
        $('ul.listArticles').each(function(i){
            $(this).attr('id','List_' + i);                                            
        });        
        // Give each toggle an unique id
        $('p.articleToggle').each(function(i){
            $(this).attr('id','Toggle_' + i);                                            
        });                        
        // Create click toggle event for each article section
        $('div.articleListWrapper').each(function(i){
            var toggleID = '#Toggle_' + i;
            var listID = '#List_' + i;
            var hidden = '.hidden';                                  
            $(toggleID).click(function(event){
                // toggle hidden list items
                $(hidden, listID).slideToggle("slow");
                // Swap text on click event
                $(this).text($(this).text() == 'Show more articles' ? 'Hide articles' : 'Show more articles');
                // Swap arrow image on click event
                $(this).toggleClass("articleToggle_close");
            });
            // function to count list items, and if items are less than 5, hide the toggle switch
            $('li', listID).each(function(x){
                if(x <= 4){
                    $(toggleID).hide();
                } else {
                    $(toggleID).show();
                };                    
            });
        });    
    };
})(jQuery);
