$(document).ready(function() {

    // If the page contains a subservice list then apply the dynamic functionality
    if ($("#subservicelist") != null) {
        // Here we are checking to see if a sub service has been specified
        var subServiceSpecified = false;
        $("#subservicelist .overline").each(function() {
            if ($(".additional_info", this).hasClass("open")) {
                subServiceSpecified = true;
            }
        });

        if (subServiceSpecified) {
            // When the page is first loaded hide all the subservice items except for any that contain the CSS class 'open'
            $("#subservicelist .additional_info:not(.open)").hide();

            // Attach a click event handler to slide the sub services open
            $("#subservicelist .expand_details").click(function() {
                $("#subservicelist .additional_info").slideUp("medium");
                $(this).parent().parent().find(".additional_info").slideDown("slow");
                return false;
            });
        }

        //  Additional logic added to deal with case where the focus subservice is specified in the url
        $("#subservicelist .overline").each(function() {
            if ($(".additional_info", this).hasClass("openitem")) {
                $("#subservicelist .additional_info").not("open").hide();
                $(".additional_info", this).slideDown("slow");                   
            }
        });

    }
});