$(document).ready(function() {
  $('div.slideshow').slideshow();

  $('aaa#menu a').mouseover(function() {
    var div = $('<div/>').html($(this).html()).addClass('menuhover');
    $(this).before(div.fadeIn(200)
      .mousedown( function() {
        $(this).remove();
      })
      .mouseout( function() {
        $(this).fadeOut(200, function() { $(this).remove() } );
      }));
  });

  $("#page a[href$='.gif']").click( function(e) {
    var p = $(this).children('img').offset();
    var thumbw = $(this).width();
    var thumbh = $(this).height();

    var preloader = new Image();
    preloader.src = $(this).attr('href');
    // once image has loaded...
    preloader.onload = function() {
      // get image dimensions
      var w = thumbw;
      var h = thumbh;
      var l = p.left;
      var t = p.top+1;

      var div = $('<div/>').addClass('zoom').css({width:w, height:h, left:l, top:t, backgroundImage:'url('+preloader.src+')'});
      
      div.click( function() {
        $(this).fadeOut(400, function() { $(this).remove() });
      });
      
      $('#page').prepend(div);
      
      var l = p.left - preloader.width + thumbw - 2;

      div.animate({ 
        width:  preloader.width,
        height: preloader.height,
        left:l
      }, 500, 'swing' );
    
    }

    e.preventDefault();
  });
  
  $("#page a[href$='.gif']").focus( function() { $(this).blur() } );
});
