
$(document).ready(function(){

    /* Navigation menu animation. */

	if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientWidth <= 480) {
		return;
	}

    /*
     * Depending on the content of the page and which parts are expanded, the navigation may be the tallest column.
     * This means that as parts of the navigation are expanded, the footer slides around.  In order to stop this,
     * we set the height of the navigation explicitly while it is still completely expanded.  This means that no
     * matter which sections are expanded, its height is unaffected, and so the footer stays in place.
     */
    $("#navigation").height($("#navigation").height());

    $("#navigation ul ul").css("display", "none");

    /* The section containing the current page should be expanded by default. */
    $("#navigation a.selected").parents("ul").addClass("open").show();

    $("#navigation h2, #navigation h3").css("cursor", "pointer");
    $("#navigation h2, #navigation h3").click(function(event) {
        var hide = false;
        if ($(event.target).next().hasClass("open")) {
            /* Visitor has clicked on an open section, so we should just hide it. */
            hide = true;
        }
        $(event.target).parent().parent().find("ul.open").hide("fast").removeClass("open");
        if (!hide) {
            $(event.target).next().addClass("open");
			if (jQuery.browser.safari) { /* && jQuery.browser.version > 419 */
	            $(event.target).next().show("fast");
			} else {
	            $(event.target).next().show();
			}
        }
    });

    /* Client list drop-down optimisation. */

    $("#client-menu").submit(function(event) {
        var client = $(event.target).find("select").val();
        if (client != "") {
            window.location = "/clients/" + client + "/";
        }
        event.preventDefault();
    });

});

