/***************************************************
 *
 *  Helper functions for tag browsing
 *  
 *  Copyright (c) Inter-Varsity Press 2010   
 *
 **************************************************/  

$(document).ready(function() {
    // Only do any set up if we're in tag browsing mode!
    if ($('#TagBrowser').length == 1)
    {
      // Close any tag list there currently is
      var h = $('#taglist').height();
      $('#taglist').addClass("closed");
      var hPrime = $('#taglist').height();
      if (h <= hPrime) return;
      // Create the 'more' link
      var moreLink =$("<a href=''class='more'></a>").text("more...");
      moreLink.click(function(e) {
        if( $(this).text() == "less..." )
        {
          $(this).text("more...").addClass('more').removeClass('less')
          //$('#taglist').slideUp('fast').addClass('closed').removeClass('opened').slideDown('fast')
          $('#taglist').animate({ height:'80px'});
          
          // In some versions of firefox, the searchresults box will not slide back up when the tag list is closed.
          // Adding the following line gives the box a nudge to get going.  
          $('.info-pane').animate({ padding:'1px' });
        }
        else
        {
          $(this).text("less...").addClass('less').removeClass('more')
          //$('#taglist').slideUp('fast').addClass('opened').removeClass('closed').slideDown('fast')
          $('#taglist').animate({ height:h+'px'});
        }
        return false;
      });
      // Add it to a div after the tag list      
      $("<div id='taglistMore'></div>").append(moreLink).insertAfter("#taglist");
      
    }
 });  
