/* Scripts for the OT Old Skool skin */

$(document).ready(function() {

	// Show/hide menus in top nav
	$("ul.MainNav > li > a").hover(
		function() {
			$(this).closest("li").addClass("Active");
			$("ul.Secondary").hide();
		},
		function() {
			$(this).closest("li").removeClass("Active");
		}
	);
	$(".Menu").hover(function() {
		$(this).siblings("ul.Secondary").show();
		$(this).siblings("ul.Secondary").closest("li").addClass("ShowMenu");
		return false;
	});
	$("ul.MainNav li ul.Secondary li a").hover(
		function() {
			$(this).addClass("Active");
		},
		function() {
			$(this).removeClass("Active");
		}
	);
	$("ul.Secondary").hover(
		function() {
			$(this).show();
			$(this).siblings(".Menu").closest("li").addClass("Active")
		},
		function() {
			$(this).fadeOut(150);
			$(this).siblings(".Menu").closest("li").removeClass("Active");
			$(this).closest("li").removeClass("ShowMenu");
		}
	);

	// Show/hide ignored posts
	$(".PostIgnoreMessage a").click(function() {
		var postClass = "div." + $(this).attr("class");
		$(this).closest("div").hide("blind", { direction: "vertical" }, 500);
		$(postClass).show("blind", { direction: "vertical" }, 500);
		return false;
	});

	// Show/hide post quick edit forms
	$("a.PostQuickEdit").click(function() {
		$(this).closest("div.TopicPost").find(".PostText").hide();
		$(this).closest("div.TopicPost").find(".PostQuickEditFormBox").show();
		return false;
	});
	$("form.PostQuickEditForm input[value='cancel']").click(function() {
		$(this).closest("div.TopicPost").find(".PostText").show();
		$(this).closest("div.TopicPost").find(".PostQuickEditFormBox").hide();
	});

	// Select all private message action checkboxes
	$(".PMSelectAll").click(function() {
		if ( $(this).html() == "Select All" )
			{
			$(".PMActionCheckbox").attr("checked", true);
			$(".PMListBox .PMSelectAll").html("Deselect All");
			return false;
			}
		else if ( $(this).html() == "Deselect All" )
			{
			$(".PMActionCheckbox").attr("checked", false);
			$(".PMListBox .PMSelectAll").html("Select All");
			return false;
			}
	});

	// Confirmation dialogs
	$("body.Subscriptions ul.ListActions li.Unsubscribe a").click(function() {
		return confirm('Are you sure you want to unsubscribe from this topic?');
	});
	$("body.Bookmarks ul.ListActions li.Delete a").click(function() {
		return confirm('Are you sure you want to delete this bookmark?');
	});
	$("body.PostDrafts ul.ListActions li.Delete a").click(function() {
		return confirm('Are you sure you want to delete this draft post?');
	});

	// Prevent erroneous clicks on forms (double posts)
	$("div.FormButtonRow input[type=submit]").click(function() {
		var inputValue = $(this).attr("value");
		$(this).closest("form").find("input[type=submit]").attr("disabled", "disabled");
		$(this).closest("form").append('<input name="formsubmit" type="hidden" value="' + inputValue + '" />');
		$(this).closest("form").submit();
	});

});