var _portraitPasswords = [];

$(document).ready(function(){
	
	var _opacityGrayDefault = 0.08,
		_opacityGrayDarker = 0.12
		_opacityGrayDark = 0.25,
		_opacityAquaDefault = 0.3,
		_opacityAquaDark = 0.6;

	$('a.default', $('#nav li')).css({
		opacity:_opacityGrayDefault
	});
	$('a.hover', $('#nav li')).css({
		opacity:_opacityAquaDefault
	});

	var _run = false;
	var _that;
	var _animateSpeed = 1200;
	var _animateEasing = 'easeOutCubic';	
	
	var reset = function(el){
		$('a.default', $(el)).stop().animate({
			opacity:0.15
		}, 200, 'easeInCubic', function(){
			$(this).animate({
				opacity:_opacityGrayDark
			}, 500, 'easeOutCubic', function(){
				var that = this;
				setTimeout(function(){
					$(that).animate({
						opacity: _opacityGrayDefault
					}, 500, 'easeOutCubic')
				}, 200);
			});
		});
		$('a.hover', $(el)).stop().animate({
			opacity:_opacityAquaDefault
		}, 200);
	}
	
	var aqua = function(el, speed){
		$('a.hover', $(el)).stop().animate({
			opacity:_opacityAquaDark
		}, speed, _animateEasing)
	};
	
	var gray = function(el, speed){
		$('a.default', $(el)).stop().animate({
			opacity:_opacityGrayDark
		}, speed, _animateEasing, function(){
			aqua(el, speed);
			$(this).animate({
				opacity:_opacityGrayDarker
			}, speed, 'easeInCubic');
		});
	};

	$('#nav li').hover(function(){
		_that = this;
		gray(_that, _animateSpeed);
	}, function(){
		_that = this;
		reset(_that);
	});
	
	$('#homelinks li a').css('opacity', 0.75).hover(function(){
		$(this).stop().animate({
			opacity: 1
		}, 500);
	}, function(){
		$(this).stop().animate({
			opacity: 0.75
		}, 500);
	});
	
	$('#portraits #slide .image a').click(function(e){
		var that = this;
		var index = $('#portraits #slide .image').index($(this).parent());
		if (_portraitPasswords[index] && _portraitPasswords[index] !== '') {
			var overlay = $('<div class="overlay"/>').css('opacity', 0.7).appendTo($('#portraits #slide .image').eq(index));
			var form = $('<form class="overlay"/>');
			var txt = $('<input class="text" type="password" id="portrait-password"/>').appendTo(form);
			form.appendTo($('#portraits #slide .image').eq(index));
			form.submit(function(){return false;});
			txt.focus();
			txt.keypress(function(e){
				if (e.keyCode === 13 && $('#portrait-password').val() === _portraitPasswords[index]) {
					window.location = $(that).attr('href');
				};
			});
			e.preventDefault();
		}
	});

});