$(document).ready(function(){
    
	$('#header .films-toggle').click(function(event){
		event.preventDefault();									  
		
		if( $('#header .films-dd').is(':visible')	) {
			$('#header .films-dd').fadeOut('fast');	
			$(this).removeClass('current');
		} else {
			$('#header .films-dd').fadeIn('fast');
			$(this).addClass('current');
		}
	});
	
	
	$('#header a.handshake').click(function(event){
		event.preventDefault();
		
		if( $('#header .navigation').is(':visible')	) {
			$('#header .navigation').fadeOut('fast', function(){
				$('#header .login').fadeIn('fast');											  
			});	
		} else {
			$('#header .login').fadeOut('fast', function(){
				$('#header .navigation').fadeIn('fast');											  
			});	
		}
	});
	
	
	$('#page-work-landing .filter li a').click(function(event){
		event.preventDefault();
		
		$('#page-work-landing .filter li a').removeClass('current');	
		$(this).addClass('current');
		
		var target = $(this).attr('href').substring(1);
		
		if(target == 'all'){
			$('#page-work-landing .projects li:hidden').fadeIn(400); // show all previously hidden items
		} else {
			$('#page-work-landing .projects li:not(.cat-'+target+'):visible').fadeOut(400); // hide visible items not in choosen category
			$('#page-work-landing .projects li.cat-'+target+':hidden').fadeIn(400); // show items previously hidden that are in category
		}
	});
	
	
	$('.photostream .tiles a').click(function(event){
		event.preventDefault();
		$('.photostream .main img').attr('src', $(this).attr('name'));										  
	});
	
	
	
	// Our Story
	$('#page-ourstory .people li a').click(function(event){
		event.preventDefault();
		
		var targetHeight = $('.our-story-wrapper').height();
		//console.log(targetHeight);
		
		$('#page-ourstory .people li a').removeClass('current');	
		$(this).addClass('current');
		
		var target = $(this).attr('href').substring(1);
		$('.our-story-wrapper').addClass('show-bio');
		$('.bio').hide();
		$('#bio-'+target).height(targetHeight - 138);
		$('#bio-'+target).show();
		
		
		$('#page-ourstory .people li a:not(.current)').each(function(){
			var target = $(this).attr('href').substring(1);
			$('.portrait', this).css('background-image', 'url('+peopleMap[target]['normal']+')');															 
		});
		
		
		var target = $(this).attr('href').substring(1);
		
	});
	
	$('.bio .close').click(function(event){
		event.preventDefault();	
		$('.bio').hide();
		$('.our-story-wrapper').removeClass('show-bio');
		
		$('#page-ourstory .people li a').removeClass('current');
		$('#page-ourstory .people li a').each(function(){
			var target = $(this).attr('href').substring(1);
			$('.portrait', this).css('background-image', 'url('+peopleMap[target]['normal']+')');															 
		});
	});
	
	$('#page-ourstory .people li a').mouseenter(function(){
		var target = $(this).attr('href').substring(1);
		$('.portrait', this).css('background-image', 'url('+peopleMap[target]['rollover']+')');													 
	})
	.mouseleave(function(){
		if($(this).hasClass('current') == false){
			var target = $(this).attr('href').substring(1);
			$('.portrait', this).css('background-image', 'url('+peopleMap[target]['normal']+')');
		}
	});
	
});
