var dfs = {
	projects: function() {
		var cache = [], img = $( "img#project-gallery-image" ), ul = $( "div#project-gallery ul" ), anchors = $( "a", ul );
		
		anchors.each( function() {
			var cacheImage = document.createElement( "img" );
			cacheImage.src = $( this ).attr( "href" );
			cache.push( cacheImage );
		});
		
		anchors.click( function() {
			var anchor = $( this ), current = $( "a.current", ul );
			
			current.animate({ opacity: 0.5 }, 400, function() {
				current.removeClass( "current" );
			});
			
			anchor.animate({ opacity: 1 }, 400, function() {
				anchor.addClass( "current" );
			});
			
			img.animate({ opacity: 0 }, 400, function() {
				img.attr( "src", anchor.attr( "href" ) ).animate({ opacity: 1 }, 400 );
			});
			
			return false;
		});
		
		var head = document.getElementsByTagName( "head" )[0];
		
		if ( head ) {
			var ss = document.createElement( "link" );
			ss.rel = "stylesheet";
			ss.type = "text/css";
			ss.href = "stylesheets/jquery.fancybox-1.3.1.css";
			head.appendChild( ss );
		}
		
		if ( window.XMLHttpRequest ) { // Prevents IE6 from executing the following
			$( "ul#projects-thumbnails a" ).fancybox({
				titleShow: false
			});
		}		
	}
};

$().ready( function() {
	if ( $( "body#page-projects" ).length ) dfs.projects();
});
