$(document).ready(function(){
	$('#content ul#photoOptions li a').click(
		function(e){
			e.preventDefault();
			$(this).parents('ul').find('li.selected').removeClass('selected');
			$(this).parent().addClass('selected');
			
			var groupName = $(this).attr('class'),
				bin = $('#photoContainer');
				
			$('#frame').children().fadeOut('fast', function(){
				$(this).remove();
			});
			$('#frame').append('<iframe src="pictures-' + groupName + '.html" scrolling="no"></iframe>').hide().fadeIn(400);
		}
	);
	$('#photoContainer div.thumbsBin a').click(
		function(e){
			e.preventDefault();
		
			var imgSrc = $(this).attr('href'),
				photoBin = $('#photoContainer div.photoBin'),
				
				img = new Image();	
				
			photoBin.children().fadeOut('fast').remove();
			photoBin.addClass('loading');		
			$(img).attr('src', imgSrc).attr('class', 'loadedImg').load(function(){
				$(this).hide();
				photoBin.removeClass('loading').append(this);
				photoBin.animate({width: $('img.loadedImg').outerWidth() + 'px'}, 400, function(){
					$('#photoContainer div.photoBin img.loadedImg').fadeIn(400)
				});
			}).error(function(){
				alert('There was an error loading the image.  Please try again.')
			});
		}
	);
	$('#media a.viewDemo, #home a.viewDemo').click(function(e){
		e.preventDefault();
		var winWidth = $(window).width(),
			winHeight = $(window).height();
		$('#modal').fadeIn(400, function(){
			$('#videoContainer').slideDown(400, function(){
				$('#player').show();
				$('#videoContainer a.closeVideo').fadeIn(300)
			})
		});
	});
	$('#videoContainer a.closeVideo').click(function(e){
		e.preventDefault();
		$(this).hide();
		$('#player').hide();
		$('#videoContainer').slideUp(400, function(){
			$('#modal').fadeOut(200, function(){
				$('#video').empty().load('video.html #player');
			})
		})
	});
});

