$(function() {
    faq.init();
});

var faq = {
    init: function() {
        var $open = $([]);
        $(".answer").hide();
        $(".question").click(function() {

            // First close the already open question. If this is the first question to be opened, nothing will be closed
            $open.slideUp(200);

            var $thisAnswer = $("+.answer", this);
            // If the user clicks the question of an already open answer, close it, instead of closing and reopening it.
            $open = ($thisAnswer[0] != $open[0]) ? $thisAnswer.slideToggle(200) : $([]);

            return false;
        });
    }
};