$(function() {
	
	var sizeContent = function() {
		
		var $content = $("#content");
		var $sidebar = $("#sidebar");
		
		if ($sidebar.height() > $content.height())
			$content.css("min-height", $sidebar.height());
		
	};
	
	$("#sidebar .widget_rmb_mega_archive").each(function() {
		
		var $container = $(this);
		
		$(".year").each(function() {
			
			var $yearContainer = $(this);
			var $monthContainer = $(".month-list", $yearContainer);
			
			$monthContainer.data("height", $monthContainer.height());
			
			if (!$yearContainer.is(".active")) {
				
				$monthContainer.height(0).hide();
				
			}
			
		}).children("a").click(function() {
			
			var $yearContainer = $(this).closest(".year");
			var $monthContainer = $(".month-list", $yearContainer);
			
			if (!$yearContainer.is(".active")) {
			
				var $monthContainerToHide = $yearContainer.addClass("active").siblings(".active").removeClass("active").children(".month-list");
				
				$monthContainerToHide.stop().animate({
					
					height: 0,
					opacity: 0
					
				}, {
					
					duration: $monthContainerToHide.height() / .4,
					complete: function() {
					
						if (parseInt($(this).height()) === 0)
							$(this).hide();
						
						if (parseFloat($(this).css("opacity")) === 0)
							$(this).css("opacity", "").hide();
						
						sizeContent();
					
					}
				
				});
				
				if (!$monthContainer.is(":visible"))
					$monthContainer.height(0).css("opacity", 0).show();
				
				$monthContainer.stop().animate({
					
					height: $monthContainer.data("height"),
					opacity: 1
					
				}, {
					
					duration: $monthContainer.data("height") / .4,
					complete: function() {
					
						if (parseFloat($(this).css("opacity")) === 1)
							$(this).css("opacity", "");
						
						sizeContent();
					
					}
					
				});
				
				return false;
				
			}
			
		});
		
	});
	
	sizeContent();
	
	$("a.lightbox").lightbox();
	
});
