  jQuery(function($) {
  
    // Adds the scroll effect for anchor links in the menu and the back link
    $('#menu a, .back_link a').click(function(event) {
      $.scrollTo(this.hash, 1500, {axis:'x', offset:-50});
      event.preventDefault(); 
    });

    // Adds the scroll effect, show preview and show description to the thumbnail links.
    $('.thumbnails a').click(function(event) {
      var parent = "#" +this.rel;
      var link = this;
      var thumbnails_wrapper = $(parent + " .thumbnails_wrapper");
      var description = $(parent + " .description");
      var preview_img = $(parent + " .preview img");

      if (link.href == preview_img.attr("src")) {
        return false;
      }
      
      $.scrollTo(thumbnails_wrapper, 1500, {axis:'x', offset:-50});

      if (link.title) {
        description.fadeTo(200, 0.0001, function() {
          description.html(link.title).fadeTo(300, 1);
        });
      }

      preview_img.fadeTo(200, 0.0001, function() {
        preview_img.attr({src: link.href, alt: link.title}); 
      });

      preview_img.bind('load', function() {
        preview_img.fadeTo(300, 1);
      });
    
      event.preventDefault();
    });

    // Adds the scroll effect for anchor links in the thumbnails controller
    $('.thumbnails_controller a').click(function(event) {
      var page = this.innerHTML - 1;
      var thumbnails = $(this.hash + " .thumbnails");
      var width = 220;

      //$.scrollTo(this.hash, 1500, {axis:'x', offset:-50});
      thumbnails.scrollTo(width * page, 1000, {axis:'x'});

      event.preventDefault(); 
    });
   			
  });