title: making function with multiple variables to pass javascript/jquery
body: <p>I have a little snippet I want to make into a function. But I'm new to javascript. Obviously there is something wrong with the way I pass variables or the way I call them...</p>
  
  <p>So in nutshell, this works: <a href="http://jsfiddle.net/kkvbz/" rel="nofollow">http://jsfiddle.net/kkvbz/</a>
  But this doesn't: <a href="http://jsfiddle.net/PrtD4/" rel="nofollow">http://jsfiddle.net/PrtD4/</a></p>
  
  <p>Problem is I need it as a function, so I've to make 1 version work.</p>
  
  <p>Full snippet:</p>
  
  <pre><code>function cutandMakeslides (containerid,liperslide) {
  //This is for footer slider, it rewrites 1 ul into several uls that contain 4 li max.
      // get the container, useful for later too...
      var container = $(containerid);
  
      // get all available UL and LI elements...
      var li_elements = container.find("&gt; UL &gt; LI").clone();
  
      // remove the current content so that we can rebuild it for the slider...
      container.find("&gt; UL").remove();
  
      // build the slider container...
      var slide_container = $("&lt;div /&gt;");
  
      // tricky part: looping through the LI's and building each of the slides...
      // first create some helpful variables...
      var li_elements_per_slide = liperslide;
      var li_counter = 0;
  
      // create the first slide, with a UL to hold the LI's...
      var current_li_div = $("&lt;div /&gt;");
      current_li_div.append($("&lt;ul /&gt;"));
  
      // loop through the LI's...
      li_elements.each(function(index, element){
  
          li_counter++;
          var current_li = $(element).clone();
          current_li_div.find("&gt; UL").append(current_li);
  
          if (li_counter % li_elements_per_slide == 0)
          {
              // we've hit 4 in this list, so add the slide and make
              // a new one, using same code as before...
              container.append(current_li_div);
              current_li_div = $("&lt;div /&gt;");
              current_li_div.append($("&lt;ul /&gt;"));
          }
  
      });
  
      // we might have an uneven number of LI's, so we need to check for this...
      if (li_counter % li_elements_per_slide != 0)
          container.append(current_li_div);
  } // end function cutandMakeslides
  
  
      //activate function above
      $(function() { cutandMakeslides(".fproductslides",3); });
  </code></pre>
  
  <p>Problematic parts:</p>
  
  <pre><code>function cutandMakeslides (containerid,liperslide) {
  var container = $(containerid);
  var li_elements_per_slide = liperslide;
  }
  $(function() { cutandMakeslides(".fproductslides",3); });
  </code></pre>