// Sub Navigation
$('#subnavigation').css('height', '0px');
$('#navigation > li:eq(1)').hover(function(){
  $('#subnavigation').stop(true).animate({
    height : '220px'
  }, 'slow', function(){$(this).css('display', 'block')});
}, function(){
  $('#subnavigation').stop(true).animate({
    height : '0px'
  }, 'slow', function(){$(this).css('display', 'none')});
})


// Slideshow
var slideshows = $('.slideshow').css({
  'height' : '20px',
  'cursor' : 'pointer'
}).append('<div class="change">Loading slideshow, please wait.</div>');


// Onload of first image
slideshows.children('img:first-child').hide().each(function(){
  var slideshow = $(this).parent();

  $(this).load(function(){  
    slideshow.css('height', this.height + 20 + 'px')
             .find('.change').text('Click to Change');

    $(this).addClass('active').show();
  });

  if (this.complete)
  {
    $(this).trigger('load');
  }
});


// Slideshow click
slideshows.click(function(){
  var images = $(this).children(),
      next   = images.filter('.active').next('img');

  if (next.length == 0)
    next = images.filter(':first');

  images.filter('.active').removeClass('active').fadeOut('slow', function(){
    next.addClass('active').fadeIn('slow');
    next.parent().css('height', next.height()+ 20 + 'px');
  });
});


$('#links > li > a:last').attr('target', '_blank');


// Toggle Sections
$('h3.section').filter(function(){
  return $(this).next('div.products').length > 0;
})
.next()
  .hide()
.end()
.css('cursor', 'pointer')
.click(function(){
  $(this).next().toggle();
});