duplicate functions, how may I combine them?
<p>I have a function that remains pretty much constant except for the changing class names. I was hoping to make the code a little less text heavy. How may I go about making it just a small function instead of repeating it <em>n times</em>. My concern is also about removing the active class for the last li that was clicked. I've provided only 2 instances here, but this code is repeated <em>n</em> number of times.Any ideas would be much appreciated.         </p>

<pre><code>        $('a.app1-preview').click(function() {
            //remove last active classes
                    $(".app2").removeClass('active');
                    $(".app2-preview").removeClass('active');
                    //Add active class for this 
            $(this).parent().addClass('active');
            $(this).addClass('active');
            $('.app-preview-2').fadeOut("slow", function () {
                $('.app-preview-1').fadeIn("slow");

            });        
        });

        $('a.app2-preview').click(function() {
            //remove last active classes
                    $(".app1").removeClass('active');
                    $(".app1-preview").removeClass('active');
                    //Add active class for this 
                    $(this).parent().addClass('active');
            $(this).addClass('active');
            $('.app-preview-1').fadeOut("slow", function () {
                $('.app-preview-2').fadeIn("slow");
            });        
        });
</code></pre>

<p>HTML code: </p>

<pre><code> &lt;div class="app-container"&gt;
                &lt;ul class="apps"&gt;
                  &lt;li class="app1"&gt; 
                      &lt;a title href="#" class="app1-preview blocklink"&gt;
                            &lt;span&gt;ANOTHER&lt;br /&gt; APP&lt;/span&gt;
                      &lt;/a&gt; 
                  &lt;/li&gt;
                  &lt;li class="app2"&gt; 
                      &lt;a title href="#" class="app2-preview blocklink"&gt;
                            &lt;span&gt;SECOND&lt;br /&gt; APP&lt;/span&gt;
                      &lt;/a&gt; 
                  &lt;/li&gt;
&lt;/div&gt;
</code></pre>
