var tab_actions = {
  
  options: {
    searchPlaceholder: 'Search the glossary...',
    function_name: ''
  },
  
  tabClicked: function(function_name){
    
    this.options.function_name = function_name;
    
    log('setting function_name: ' + function_name + ' | ' + this.options.function_name);
    
    switch(function_name)
    {
      case 'search-tab':
        log('tab_action.tabClicked | clicked: search');
        
        // set sort flag
        jQuery('#sort').val('relevance');
        
        // get search
        this.runSearch();
        
        break;
      case 'az-tab':
        log('tab_action.tabClicked | clicked: az');
        
        // set sort flag
        jQuery('#sort').val('az');
        
        // get search
        this.runSearch();
        
        break;
      case 'za-tab':
        log('tab_action.tabClicked | clicked: za');
        
        // set sort flag
        jQuery('#sort').val('za');
        
        // get search
        this.runSearch();
        
        break;
    }
    
  },
  
  runSearch: function(){
    
    log(jQuery('#searchForm').attr('action'));
    
    // get search query
    if(jQuery('#search_str').val() == this.options.searchPlaceholder)
    {
      var search_str = '';
    }
    else
    {
      var search_str = jQuery('#search_str').val();
    }
    
    // save cookies
    setCookies('glossary', this.options.function_name, search_str, jQuery('#current_page').val());
    
    // show loading
    jQuery('#searchResults').html('<h3>Loading...</h3>');
    
    jQuery.post(
      jQuery('#searchForm').attr('action'),
      {
        sort: jQuery('#sort').val(),
        query: search_str,
        current_page: jQuery('#current_page').val()
      },
      function(data){
        
        // get matches
        var matches = data.matches;
        
        // clear search result area
        jQuery('#searchResults').html('');
        
        if(matches && matches.length > 0)
        {
          // parse data
          for(var i = 0; i < matches.length; i++)
          {
            if(matches[i] != null_var)
            {
              var html =	'<div class="glossaryBox">'
                +	'	<strong><a href="#{glossary_url}">' + matches[i].title + '</a></strong>'
                + '<div class="description">' + matches[i].content + '</div>'
                +	'</div>';

              jQuery('#searchResults').append(jQuery(html));
            }
            
          }
          
          // add pagers
          jQuery.tabs_v2_pager.init(data.searchInfo.total, data.searchInfo.resultsPerPage, data.searchInfo.rows);
        }
        else
        {
          emptySearch();
        }
      },
      'json'
    );
  },

  /**
   * runs when page initially loaded.
   */
  loadPage: function(){

    // check for cookies
    if(jQuery('#search_str').val() == this.options.searchPlaceholder && jQuery.cookie('SEARCH_ZONE') == 'glossary' && jQuery('#' + jQuery.cookie('SEARCH_TAB')).length == 1)
    {
      // set tab active
      // make all inactive
      jQuery('div.tab').removeClass('active');

      // make this active
      jQuery('#' + jQuery.cookie('SEARCH_TAB')).addClass('active');

      // set search str
      jQuery('#search_str').val(jQuery.cookie('SEARCH_STRING'));
      jQuery('#search_str').attr('value', jQuery.cookie('SEARCH_STRING'));

      // set page
      jQuery('#current_page').val(jQuery.cookie('SEARCH_PAGE'));
    }

    // click active tab
    jQuery('.tab.active').trigger('click');

  }
  
};
