$.fn.image = function(src, f){
   return this.each(function(){
     $("<img />").appendTo(this).each(function(){
        this.src = src;
        $(this).load(f);
     });
   });
}



$(document).ready(function() {
  
  
  
  
  $('#test').click(function() {
    
    alert($('#projects_bigimage').find('img').height());
    
    
  });
  
  
  $('.thumbImage').css('opacity','0.5');

  $('.thumbImage').click(function() {
    
    var newlargeurl=$(this).attr('rel');
    
    
    $('#projects_bigimage').hide();
    $('#ajaxloading').show();
  
    $('#myFlash').find('img').attr('src','lib/backgrounds/gallery-plain.jpg');
    
    
    $("#projects_bigimage").image(newlargeurl,function(){
      
      $('#projects_bigimage img:first').remove();
      
      
      
      $('#ajaxloading').fadeOut(250, function() {
        $('#projects_bigimage').fadeIn(200);
        
        if(newlargeurl.substr(newlargeurl.length-9,9) == 'landscape'){
          $('#imagemask_landscape').show();
          $('#imagemask_portrait').hide();
          $('#projects_bigimage').css('right','21px').css('bottom','153px');
          
        }else{
          $('#imagemask_landscape').hide();
          $('#imagemask_portrait').show();
          $('#projects_bigimage').css('right','80px').css('bottom','97px');
        }
        
      });

    });

    
    $('.thumbImage').css('opacity','0.5');
    $(this).css('opacity','1.0');
    
  });
  
  $('.thumbImage:first').click();
  
  
  
  
  
});
