$(document).ready(function() {
	var html = $("#popover .middle .video").html();
	
	$("#dither, #popover .middle .close a").click(function(e) {
		which	= $("#popover .middle").children(".active").attr("class").match(/^\w+/);
		html = $("#popover .middle .video").html();
		fade_out("#popover .middle ." + which);
		$("#popover .middle .video").html("");
		e.stopPropagation();
	});
	$("#show .icons .news").click(function() {
		fade_in("#popover .middle .articles");
	});
	$("#show .icons .photos").click(function() {
		$("#popover").css({ display: "block" });
		$("#popover .thumbs").css({ display: "block" });
		$("#popover .middle .thumbs .row .photo .thumb img").each(function() {
			$(this).attr("title", $(this).height());
			if($(this).width() >= $(this).height()) {
				$(this).css({ width: 100 });
				padY	= Math.round((100 - $(this).height()) / 2);
				if(padY!=50)
					$(this).css({ marginTop: padY });
				else
					$(this).css({ marginTop: 0 });
			} else {
				$(this).css({ height: 100 });
				$(this).css({ marginTop: 0 });
			}
			$(this).click(function() {
				$div	= $("<div>").addClass("full-size").html("<a href=\"#\" onclick=\"return false\">Click here to close</a><br /><br />");
				$div.append($("<img>").attr("src", $(this).attr("src"))).css({ height: $(this).attr("title") + 20 });
				$div.click(function() {
					$(this).remove();
				});
				$("#popover .middle .thumbs").append($div);
			});
		});
		$("#popover .thumbs").css({ display: "none" });
		$("#popover").css({ display: "none" });
		fade_in("#popover .middle .thumbs");
	});
	$("#show .icons .video, #show .copy p .video").click(function() {
		$("#popover .middle .video").html(html);
		fade_in("#popover .middle .video");
	});
});
