/*	Project Thumbnail Switcher	*/
$(function (){
	
	$('a[rel=external]').click(function() {
	  window.open($(this).attr('href'));
	  return false;
	});
	
	$('#projects ul.thumbs li a').click(function(){
	  var $this = $(this);
	  var frame = $(this).parents('.thumbs').siblings('.main-img');
	  
	  if($this.attr('href') != frame.find('img:visible').attr('src')) {
  		var img = new Image();
		  
  		frame.find('img').fadeOut('fast',function() {
		    $orig_image = $(this);
		    
  		  $(img)
    		  .load(function(){
    		    
    		    $orig_image.remove();
    		    $(this).hide();
    		  	frame.find('a').append(this)
    		  	    .parent()
    			       .animate({height: $(this).attr('height')});
    			
            var larger_img = $this.attr('href').replace('_331.j','_750.j');
                    frame.children('a.popup').attr('href',larger_img);
    			  
    			  $(this).fadeIn();
    			  
    		  })
    		  .error(function() {
    		  	alert('Unable to load image');
    		  })
    		  .attr('src',$this.attr('href'));
		  
  		});
		}
		
		return false;	
	});
	
	
	$('.main-img a').fancybox();	
	
});	
