$(function() {
  var base_url = $('base', 'head').attr('href');
  
  // Auto submit category/brand search dropdowns on change
  $('#category_select, #brand_select').change(function() {
    window.location = base_url + $(this).find(':selected').attr('data-url');
  }).next(':submit').hide();
  
  // Homepage Flash
  if ($('#flash', '#homepage').length > 0) {
    swfobject.embedSWF(base_url + "flash/index-anim.swf", 'flash', 504, 520, '9.0.0', base_url + "flash/expressInstall.swf", {}, { wmode: 'opaque' });
  }
  
  $('.inquire').fancybox({
    padding: 20,
    titleShow: false
  });
  
  // Centralize item count updating
  var $inquireInfo = $('#inquire-info'),
      itemCount = parseInt($inquireInfo.find('var').text(), 10);
  $inquireInfo.bind('updateCount', function(event, count) {
    if (typeof(count) == 'string') {
      itemCount = eval(itemCount + count);
    } else {
      itemCount = count;
    }
    
    $inquireInfo.find('var').text(itemCount + ' item' + (itemCount==1 ? '' : 's'));
    if (itemCount === 0) { $inquireInfo.fadeOut(); }
    else                 { $inquireInfo.fadeIn(); }
  });
  
  // Product thumbnail lightboxes
  $('dl.product .img a').fancybox({
    padding: 50,
    titleShow: false
  });
  
});

