Cufon.replace('h1, h2, #main h3, header ul');

$(function() {

	$('html').removeClass('no-js');

	$('ul#projects li.item .img').each(function() {
		theThumb = $(this).find('li:first-child a').attr('href');
		$(this).find('li:first-child').addClass('on');
		$(this).prepend('<div class="large"><img src="' + theThumb + '" alt="" /></div>');
	});
	$('ul#projects li.item .img a').click(function() {
		if( $(this).parent().hasClass('on') || $('body').hasClass('animating') ) { /* do nothing */ } else {
			$('body').addClass('animating');
			theIndex = $(this).parent().parent().parent().parent();
			theIndex = theIndex.index('ul#projects li.item');
			theThumb = $(this).attr('href');
			$(this).parent().parent().find('li').removeClass('on');
			$(this).parent().addClass('on');
			$('<img />').attr('src', theThumb).load(function(){
				$('ul#projects li.item:eq(' + theIndex + ')').find('.large').prepend( $(this) );
				$('ul#projects li.item:eq(' + theIndex + ')').find('.large img:last-child').animate({
					left: '-440px'
				}, 'fast', function() {
					$(this).remove();
					$('body').removeClass('animating');
				});
			});
		}
		return false;
	});

});
