$(function(){
    /* hide all answers and set link icons closed */
    if ($("#faqs h3 q").length == 0){
        $("#faqs dl dd").css({'display' : 'none'});
        $("#faqs dl dt a").toggleClass("plus");
    } else {
        $("#faqs a.toggle_section").toggleClass("open");
    }

    /* toggle whole section */
    $("#faqs a.toggle_section").click(function () {
        $(this).toggleClass("open");
        question_minus = $(this).parent().children("dl").children("dt").children("a").not("a.plus");
        question_plus = $(this).parent().children("dl").children("dt").children("a.plus");

        if ($(this).hasClass("open")){
            /* opening */
            question_plus.toggleClass("plus").parent().next().slideToggle("normal");
        } else {
            /* closing */
            question_minus.toggleClass("plus").parent().next().slideToggle("normal");
        }
        return false;
    });

    /* toggle question */
    $("#faqs dl dt a").click(function () {
        $(this).toggleClass("plus").parent().next().slideToggle("normal");
        /* check for section toggle */
        openeditems = $(this).parents("div.dl_container").children("dl").children("dt").children("a").not("a.plus").length;
        closeditems = $(this).parents("div.dl_container").children("dl").children("dt").children("a.plus").length;
        if(openeditems == 0 || closeditems == 0){
            $(this).parents("div.dl_container").children("a.toggle_section").toggleClass("open");
        }
        return false;
    });

});
