// relies on jquery library

$(document).ready(function(){
	
	// when a select box is clicked, change the class of the parent to "selected"
	$("#pub-notification-list input").click(function () {
		$(this).parent().toggleClass("selected");
	});



	// create notification control div underneath list, add class if it's meant to be closed by default
	$("div.default-closed").before('<div class="add-notification collapsed"></div>');
	$("div.default-open").before('<div class="add-notification"></div>');


	// create 'select all' link for notification list
	$("#pub-notification-list .divider").prepend('<a href="#" id="select-all">(Select All)</a>');
	$("#select-all").toggle(
		function() {
			$("#select-all").text("(Select None)");
			$("#pub-notification-list .publication input").attr("checked", "checked").parent().addClass("selected");
			return false;
		},
		function() {
			$("#select-all").text("(Select All)");
			$("#pub-notification-list .publication input").attr("checked", "").parent().removeClass("selected");
			return false;
		}
	);

	// if wildcard checkbox is selected, check all
	$("#wildcard").click(
		function() {
			$("#pub-notification-list input").attr("checked", "").parent().removeClass("selected");
			$(this).attr("checked", "checked").parent().addClass("selected");
		}
	);


	// keep form hidden by default
	$("div.default-closed").hide();
	// add form-opening button
	$("div.collapsed").append('<p><input type="image" src="/i/ui/button-notify.gif" value="Notify Me of Publication" /></p>');
	// show form upon clicking the button
	$("div.add-notification input").click(function() {
		$(this).hide("fast");
		$("#name-address").show("fast");
		return false;
	});

});
