
(function($)
{
  $(document).ready(function()
  {
    $('input#s')
      .focus(function(event) 
      {
        $(this).val('');
      })
      .click(function(event)
      {
        if (event.pageX - this.offsetLeft > 355)
        {
          $(this).parents('form:first').submit();
        }
      })
      .val('Search');
      
    if ($('#feature-navigation-bullets').length > 0)
    {
      brb_featured();
    }
    
    if ($('.tab-set').length > 0)
    {
      brb_tabs();
    }
    
    brb_banners();
    
    brb_menu();
    
    // $('select, input:checkbox, input:radio').uniform();
  });

  function brb_menu()
  {
    $('#menu-primary-menu .menu-item').hoverIntent({
      interval: 200
      ,over: brb_menu_show
      ,timeout: 150
      ,out: brb_menu_hide
    });
    
    $('#menu-primary-menu .menu-item').addClass('with-js');
  }
  
  function brb_menu_show()
  { 
    $(this).addClass('show'); 
    $(this).removeClass('with-js'); 
  }
  
  function brb_menu_hide()
  { 
    $(this).removeClass('show'); 
    $(this).addClass('with-js'); 
  }

  var $feature;
  
  function brb_banners()
  {
    $('#banner-container h3.widget-title').click(function()
    {
      window.location.href = $(this).next('a:first').attr('href');
      return false;
    });
  }
  
  function brb_tabs()
  {
    $('.tab-set > div:not(:first)').hide(); 
    
    $('ul.tabs a').click(function() 
    { 
      $('ul.tabs a.selected').removeClass('selected'); 
      $('.tab-set > div').hide();
      $($(this).attr('href')).show(); 
      $(this).addClass('selected'); 
  
      return false; 
    });

    var tab = window.location.hash;
    
    if ($('a[href=' + tab + ']').length > 0)
    {
      $('a[href=' + tab + ']').trigger('click');
    }
  }
  
  function brb_featured()
  {
    $feature = $('#feature').cycle({
      speed: 800 
      ,timeout: 5000
      ,timeoutFn: function(currSlideElement, nextSlideElement, options, forwardFlag)
      {
        $('#feature-navigation-bullets a').each(function(i)
        {
          if (i == options.currSlide)
          {
            $(this).addClass('current');
          }
          else
          {
            $(this).removeClass('current').blur();
          }
        });

        show_hide('#feature-info .feature-info', options.currSlide);
        
        function show_hide(list, current)
        {
          $(list).each(function(i)
          {
            if (i == current)
            {
              $(this).css('display', 'block');
            }
            else
            {
              $(this).css('display', 'none');
            }
          });
        }
        
        return options.timeout;
      }
    });
    
    $feature.children().each(function(i)
    {
      $('<a href="#">&nbsp;</a>')
        .addClass(i == 0 ? 'current' : '')
        .appendTo($('#feature-navigation-bullets'))
        .click(function()
        {
          $feature.cycle($('#feature-navigation-bullets a').index(this)); 
        
          return false;
        });
    });
  }  
  
})(jQuery);
