$(document).ready(function() {

  /*Note - using ids for the list items, and class for a subcategory ul - look at products.js*/
  var body_class = $('body').attr('class');
  /*See if the active page - lies in a subcategory*/
  var location = $('.side_nav>ul>li').index($('li#' + body_class));
  if (location < 0) {
    $('li#' + body_class).parent('ul').addClass('nohide');
  }
  /*Create the array of ul's to be hidden - do not include if the active class is same as body class or if it's in a subcategory*/
  var prod_groups = $('.side_nav ul ul').not('.' + body_class).not('.nohide');

  $(prod_groups).each(function() {
    $(this).hide();
    $(this).parent('li').hover(function() {
      $(this).addClass('alight');
      $(this).find('ul').stop(true, true).slideDown();
    }, function() {
      $(this).removeClass('alight');
      $(this).find('ul').slideUp();
    });
  });

  /*For the mini-image gallery*/
  $('.photo_gallery li:eq(0)').addClass('active');
  $('.product_image h3').text($('.main_image img').attr('alt'));
  if ($('.product_image h3').text() == "") {
    $('.product_image h3').hide();
  }

  $('.photo_gallery img').click(function() {
    if (!($(this).parent().hasClass('.active'))) {

      $('.preloader').show();
      var thisImage = $(this);
      var target = thisImage.attr('src');
      var title = thisImage.attr('alt');
      $('.main_image img').attr('src', target.replace('_thumb.jpg', '.jpg'));
      $('.main_image img').load(function() {
        $('.preloader').hide();
        $('.product_image h3').text(title);
        thisImage.parent().addClass('active').siblings().removeClass('active');
      });
    }
  });
});


/*Tool tips*/

