$(document).ready(function() {
	if ($.browser.opera) {
		$.support.opacity = true;
	}

	$("#caption").css("opacity", 0);
	$("img", "#archiveImages").css("opacity", 0.1);
	$("#archiveBackground").css("opacity", 0.2);

	$("#archiveImages").hover(function() {
		$("#archiveBackground").stop().animate({ opacity: 0.5 }, 200);
		$("img:not(.on)", "#archiveImages").stop().animate({ opacity: 0.3 }, 200);
	}, function() {
		$("#archiveBackground").stop().animate({ opacity: 0.2 }, 500);
		$("img:not(.on)", "#archiveImages").stop().animate({ opacity: 0.1 }, 500);
	});
	
	$("img", "#archiveImages").hover(function() {
		$(this).not(".on").stop().animate({ opacity: 1 }, 1);
	}, function() {
		$(this).not(".on").stop().animate({ opacity: 0.3 }, 800);
	});

	$("#photoBox").hover(function() {
		$("#caption").stop().animate({ opacity: 0.99999 }, 200); // to fix rendering bugs for various browsers
		$("#featured").stop().animate({ opacity: 0.2 }, 200);	
	}, function() {
		$("#featured").stop().animate({ opacity: 1 }, 500);
		$("#caption").stop().animate({ opacity: 0 }, 500);
	});

	$("img.on").css("opacity", 1);

	var count = 1;
	var selectedImg;

	$("img", "#archiveImages").each(function() {
		if ($(this).hasClass("on")) {
			selectedImg = count;
		}

		count++;
	});

	$("#archiveImages").css("height", $("#archiveImages ul").height() + "px");

	if (selectedImg >= 5) {
		// center vertically
		$("#archiveImages").css("top", "50%").css("margin-top", "-" + $("#archiveImages").height()/2 + "px");
	}

	$("#next, #previous").each(function() {
		title = $(this).children("a").html();
		$(this).attr("title", title);
	});

	$("a[rel^='prettyPhoto']").click(function() {
		$("#contentContainer").hide();
		$("#archiveBackground").hide();
		$("#archiveImages").hide();
	});

	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 700,
		padding: 0,
		opacity: 0.6,
		showTitle: false,
		allowresize: true,
		counter_separator_label: "/",
		callback: function() {
			$("#contentContainer").show();
			$("#archiveBackground").show();
			$("#archiveImages").show();
		}
	});
});