jQuery(function(){
	
	// slide-down images on homepage
	jQuery('#portfolio_grid li').hover(function(){
		jQuery(this).find('img').animate({top:'154px'},{queue:false,duration:500});
	}, function(){
		jQuery(this).find('img').animate({top:'0px'},{queue:false,duration:500});
	});

	jQuery('#gallery').gallerify();
	
	// easter egg :)
	jQuery('<div id="worm"></div>').appendTo('#footer_sleeve').toggle(
		function(){
			jQuery(this).parents('#footer_sleeve').animate({height:'835px'},{queue:false,duration:2000});
			jQuery('html,body').animate({scrollTop:jQuery('#footer_sleeve').offset().top + 865},{queue:false,duration:2000});
		}, function(){
			jQuery(this).parents('#footer_sleeve').animate({height:'70px'},{queue:false,duration:2000});
		});
});

	jQuery.fn.gallerify = function() {
		return this.each(function(){
			var images = jQuery('img.thumb',this);
			images.hide().css({opacity:0});
			jQuery(images[0]).show().css({opacity:1});
			
			if (images.length > 1) {
				jQuery(this).after('<ul id="gallery_changer"></ul>');
				var changer = jQuery('+ul',this);
				images.each(function(){
					var numberLink = (images.index(this)+1).toString();
					if (numberLink.length == 1) numberLink = '0' + numberLink;
					jQuery('<li><a href="#">'+numberLink+'</a></li>').click(showImage).appendTo(changer);
				});
				jQuery('li:first',changer).addClass('first current');
			}

			function showImage() {
				jQuery(this).addClass('current').siblings().removeClass('current');
				var clicked = this;
				images.each(function(){
					if (jQuery(this).is(':visible')) {
						jQuery(this).animate({opacity:0},200,function(){
							jQuery(this).hide();
							jQuery(images[jQuery(clicked).parent().children('li').index(clicked)]).css({display:'block'}).animate({opacity:1},200);
						});
					}
				});
				return false;
			}
		});
	}
	
// fancybox

jQuery(document).ready(function() {

	$("a.fbox_normal").fancybox({
		'titleShow'	: 'false',
        'transitionIn'   : 'fade',
        'transitionOut'  : 'fade'
	});
	
	$("a.fbox_movie").fancybox({
        'width'                 : 1000,
        'height'                : 605, // includes 35px for nav/scrubber
        'autoScale'             : false,
        'transitionIn'          : 'none',
        'transitionOut'         : 'fade',
		'scrolling'				: 'no',
        'type'                  : 'iframe'
	});

	$("a.fbox_form").fancybox({
		'width'				: '400px',
		'height'			: '400px',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

});
