$(document).ready(function() {
    $("ul li:last-child").addClass('last');

    // Gallery
    $('.gallery_thumb').click( function(){
      image = $(this).attr('rel');

      $('.gallery_thumb').removeClass('current');
      $(this).addClass('current');

      $('.gallery_full_size:visible').fadeOut('slow');
      $(image).fadeIn('fast');

      return false;
    });

    $('.next').click(function() {
      var next = $('.current').next('a.gallery_thumb');

      next.length ? next.click() : $('a.gallery_thumb').first().click();
      return false;
    });

    $('.previous').click(function() {
      var prev = $('.current').prev('a.gallery_thumb');

      prev.length ? prev.click() : $('a.gallery_thumb').last().click();

      return false;
    });

    $('.gallery_thumb').first().click();

    $('.toggle_thumbnails').click(function() {
      $('#gallery_items').toggleClass('collapsed');

      $(this).text() == 'Hide Thumbnails' ? $(this).text('Show Thumbnails') : $(this).text('Hide Thumbnails');

      return false;
    });

    $('.home #slideshow').cycle({
        timeout: 9000,
        speed: 2000
    });

    $(document).keydown(function(e){
        if(e.keyCode == 37){
          $('.previous').click();
          return false;
        }
    });

    $(document).keydown(function(e){
        if(e.keyCode == 39){
          $('.next').click();
          return false;
        }
    });

});

