$(function() {
  // top nav dropdown menus
  var navz = 200; //initial z-index to clear text effects
  $('#nav>ul>li').hoverIntent({
    interval: 50,
    over: function() {
      $(this).find('ul:first').css('z-index', navz++).slideDown('fast');
    },
    timeout: 200,
    out: function() {
      $(this).find('ul:first').slideUp('fast');
    }
  });

  // product and homepage tab switching
  $('.producttabs>ul a, #top .imgtabs a').click(function() {
    var li = $(this).parent();
    if (!li.hasClass('active')) {
      li.addClass('active').siblings().removeClass('active');
      var index = li.prevAll().length;
      var blocks = li.parent().nextAll();
      if (!blocks.length) blocks = li.parent().parent().nextAll();
/*
      blocks.filter(':visible').slideUp('normal', function() {
        blocks.eq(index).slideDown('normal');
      });
*/
      blocks.filter(':visible').hide();
      blocks.eq(index).show();
    }
    return false;
  });

  // equal height columns for product listings
  var products = $('.view-content .product, .related .product').height('auto');
  var cols = $('body').hasClass('wide') ? 4 : 3;
  for (i = 0; i < products.length; i += cols) {
    var row = products.slice(i, i+cols);
    var h2max = 0;
    var pmax = 0;
    var kitchens = [];
    var others = [];
    row.each(function() {
        var box = $(this);
        h2max = Math.max(h2max, box.find('h2').height());
        pmax = Math.max(pmax, box.find('p:first').height());
        if (box.hasClass('kitchen')) {
          kitchens.push(this);
        }
        else {
          others.push(this);
        }
    });
    row.find('h2').height(h2max);
    row.find('p:first').height(pmax);
    if (kitchens.length && others.length) {
      var diff = $(others[0]).height() - $(kitchens[0]).height();
      $(kitchens).find('.more').before('<div style="height:'+diff+'px;"></div>');
    }
  }

  // help popups
  $('.ajax-help').click(function() {
    $.get(this.href, function(html) {
alert(html);
    });
    return false;
  });
});
