(function() {
  var showNextNewsItem;
  window.console = window.console || {
    log: function() {},
    warn: function() {},
    error: function() {}
  };
  showNextNewsItem = function() {
    var $current, $news, $next;
    $news = $('#news-ticker ul li');
    $current = $news.filter('.current').length ? $news.filter('.current') : $news.first();
    $next = $current.next('li').length ? $current.next('li') : $news.first();
    $current.removeClass('current').animate({
      left: 50,
      opacity: 0
    });
    return $next.addClass('current').animate({
      left: 0,
      opacity: 1
    });
  };
  $(function() {
    if ($('#news-ticker').length) {
      return setInterval(showNextNewsItem, 5000);
    }

    // Footer search filters
    var $filters = $('footer form ul.filters'),
        $toggle  = $('footer form a.filter-toggle'),
        originalToggleLabel = $toggle.text();

    $toggle.toggle(function(){
      $filters.show();
    }, function(){
      $filters.hide();
    });

    $filters.find('input').change(function(){
      $toggle.text($(this).parent('label').text());
      $filters.hide();
    });

    // empty search
    $('#search').submit(function(){
      if (!$.trim($(this).find('input#s').val()).length) {
        $(this).find('input#s').val(' ');
      }
    });

    // Slideshow
    $('#main-lift ul.content').slideshow({
      controls: '#main-lift .controls li',
      duration: 500
    });

    // Select replacement
    $('select.fancy').chosen();

    $('.isotope-container').isotope({
      //animationEngine : 'best-available',
      layoutMode : 'fitRows'
    });

    $('div.isotope-filters select').change(function(){
      var selectors = $('.isotope-filters option[data-filter!="*"]:selected')
        .map(function() {
          return $(this).data('filter');
        })
        .get()
        .join('');
      $('.isotope-container').isotope({ filter: selectors });
      if (!$('.isotope-container .product:not(.isotope-hidden)').length) {
        $('.product-categories .empty').show();
      } else {
        $('.product-categories .empty').hide();
      }
      return false;
    });

    return this;
  });

}).call(this);

