$(function() {
	
	if ($('html').hasClass('has-js')) return;
	
	$('html').addClass('has-js');
	
	var params = {
		wmode: 'transparent',
		allowscriptaccess: 'always'
	};
	var attrs = {	}
	//swfobject.embedSWF('/media/flash/flash-work.swf', 'FlashOverlay', $(window).width(), $(window).height(), '10.0.0', null, null, params, attrs, onSWFEmbed);

	
	// Listen for clicks on the different sections of the "work" list
	$('.work li h2').click(function() {
		
		var doExpand = !$(this).parent().hasClass('selected');
		
		collapseSection($('.work li.selected'));
		if (doExpand) expandSection($(this).parent());
		
		
		function expandSection(section) {
			
			section.addClass('selected');
			section.children('div').slideDown();
			
			var delay = 500;
			section.find('.tile').each(function() {
				$(this).hide();
				$(this).fadeIn(delay);
				delay += 500;
			});
		}
		
		
		function collapseSection(section) {
			
			section.children('div').slideUp();
			section.removeClass('selected');
			return section;
		}
	});
	
	
	$('#Flash').click(function() {
		$('#FlashOverlay').addClass('active');
	});
	
	
	$(window).resize(function() {
		
		console.log("resizing window");
		$('#FlashOverlay').attr('width', $(window).width());
		$('#FlashOverlay').attr('height', $(window).height());
	})
});


function onSWFEmbed(e) {
	
	console.log("swf embed");
}


function onFlashClose() {
	$('#FlashOverlay').removeClass('active');
}
