
$(init);



function init()
{
	var h3s = $(".entry-extras h3");
	
	if (h3s.length > 0)
	{
		var openAll = $('<div class="entry-extras entry-open-all"><a href="#">Open all</a></div>');
		
		openAll
			.click(function()
				{
					if ($(this).hasClass("entry-open-all-open"))
					{
						$("a", this).text("Open all");
						
						h3s
							.each(function()
								{
									if (!$(this).parents(".entry-extras").hasClass("closed"))
									{
										$(this).click();
									}
								}
							)
					}
					else
					{
						$("a", this).text("Close all");
						
						h3s
							.each(function()
								{
									if ($(this).parents(".entry-extras").hasClass("closed"))
									{
										$(this).click();
									}
								}
							)
					}
					
					$(this).toggleClass("entry-open-all-open");
				}
			)
			.insertBefore($(".entry-extras").eq(0))
	}
	
	h3s
		.each(function()
			{
				$(this).parents(".entry-extras").addClass("closed");
				$(this).wrapInner('<a href="#"></a>');
			}
		)
		.click(function()
			{
				$(this).parents(".entry-extras").toggleClass("closed");
			}
		)
		
	$(".entry-extras > a, .entry-extras h3 a")
		.click(function(event)
			{
				event.preventDefault();
			}
		)
}
