
$(document).ready(function(){
	$('.closeShadowbox').click(function(){
		window.parent.Shadowbox.close();
	});
	
	var init = true;
	
	var thumbs = [];
	$('.bioGalleryImages img').each(function() {
		$full = $(this).attr('height', 222).attr('width', 263);
		$thumb = $full.clone().attr('height', 31).attr('width', 47);
		var $thumbLink = $(document.createElement('a'));
		$thumbLink.attr('href', 'javascript:void(0);');
		$thumbLink.data('fullImg', $full);
		$thumbLink.click(function() {
			var $link = $(this);
			if ( init ) {
				$('.bioGalleryImg').empty().append($link.data('fullImg').clone());
			}
			else {
				$('.bioGalleryImg').fadeTo('fast', 0.01, function() {
					$(this).empty().append($link.data('fullImg').clone());
					$(this).fadeTo('fast', 1);
				});
			}
			return false;
		});
		$thumbLink.append($thumb);
		thumbs.push($thumbLink);
	});
	
	if ( thumbs.length ) {
		while ( thumbs.length ) {
			var $row = $(document.createElement('div'));
			$row.attr('class', 'thumbs clearfix');
			for ( var i = 0; i < 5; ++i ) {
				var $thumb = thumbs.shift();
				$row.append($thumb);
			}
			$('.bioGalleryThumbs').append($row);
		}
		$('.bioGalleryThumbs').css('display', '');
		$('.bioGalleryThumbs a:first').click();
	}
	
	$('.favorites>ul>li').each(function() {
		var $this = $(this);
		var $link = $this.children('a');
		var $container = $this.children('div');
		
		$link.attr('href', 'javascript:void(0);');
		$link.click(function() {
			$('.favorites li.active>div').css('display', 'none');
			$('.favorites li.active').removeClass('active');
			$(this).parent().addClass('active');
			$(this).siblings('div').css('display', '');
		});
		
		$container.css('display', 'none');
	});
	$('.favorites>ul>li>a:first').click();
	
	init = false;
});
