title: Adding ScrollTo in the jQuery UI Accordion script
body: <p>I've search high and low and have not found a post that has helped my specific situation.  I am new to jQuery and love its wide range of uses.  I have an issue with my accordion script and I need to add the ScrollTo so that when a section if selected it scrolls the window up if it is above the view.  I hope this makes sense.  Thank you for the help.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          /* &lt;![CDATA[ */
          jQuery().ready(function(){
              jQuery('#leftnav-navigation').accordion({
                  active: false,
                  header: '.head',
                  navigation: true,
                  collapsible: true,
                  animated: 'easeslide',
                  autoheight: false,
                  alwaysOpen: false,
              });
  
              var accordions = jQuery('#leftnav-navigation'); 
  
              jQuery('#switch select').change(function() {
                  accordions.accordion("activate", this.selectedIndex-1);
              });
              jQuery('#close').click(function() {
                  accordions.accordion("activate", -1);
              });
              jQuery('#switch2').change(function() {
                  accordions.accordion("activate", this.value);
              });
              jQuery('#enable').click(function() {
                  accordions.accordion("enable");
              });
              jQuery('#disable').click(function() {
                  accordions.accordion("disable");
              });
              jQuery('#remove').click(function() {
                  accordions.accordion("destroy");
                  wizardButtons.unbind("click");
              });
              return false;
          });
          /* ]]&gt; */
      &lt;/script&gt;
  </code></pre>
  
  <p>Thanks to ckaufman for his help.  Here is the final working code.  I hope this helps someone in need.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          /* &lt;![CDATA[ */
          jQuery().ready(function(){
              jQuery('#leftnav-navigation').accordion({
                  active: false,
                  header: '.head',
                  navigation: true,
                  collapsible: true,
                  animated: 'easeslide',
                  autoheight: false,
                  alwaysOpen: false,
              });
  
              var accordions = jQuery('#leftnav-navigation'); 
  
              jQuery('#switch select').change(function() {
                  accordions.accordion("activate", this.selectedIndex-1);
              });
              jQuery('#close').click(function() {
                  accordions.accordion("activate", -1);
              });
              jQuery('#switch2').change(function() {
                  accordions.accordion("activate", this.value);
              });
              jQuery('#enable').click(function() {
                  accordions.accordion("enable");
              });
              jQuery('#disable').click(function() {
                  accordions.accordion("disable");
              });
              jQuery('#remove').click(function() {
                  accordions.accordion("destroy");
                  wizardButtons.unbind("click");
              });
  
              jQuery('#leftnav-navigation').click(
                  function() {
                      var window_top = $(window).scrollTop();
                      var div_top = $(this).offset().top;
                          if (window_top &gt; div_top){
                              $('html, body').animate({scrollTop:div_top}, 300);
                  }
              });
  
              return false;
          });
          /* ]]&gt; */
      &lt;/script&gt;
  </code></pre>