﻿$(document).ready(function () {
    var jf = new JsonAccordianFunctions();

    $(".accordian dd").hide();

    $(".accordian dt").hover(
            function () {
                var tip = "<span>expand</span>";
                if ($(this).next().is(":visible")) {
                    tip = "<span>collapse</span>";
                }
                $(this).prepend(tip);
            },
            function () {
                $(this).find("span:first").remove();
            }
        );

    $(".accordian dt").click(function () {
        if (!$(this).next().is(":visible")) {
            var htmlId = $(this).attr("id");
            var id = htmlId.substring(4)
            var faq = jf.getFaqById(id);
            $(".accordian dd").hide();
            $(".accordian dt").css("background-image", "url('../img/backgrounds/grey-gradient.gif')");
            $(this).next().html(faq.answer);
            $(this).next().show("fast");

            $(this).find("span:first").text("collapse");
            $(this).css("background-image", "url('../img/backgrounds/green-gradient.gif')");
        } else {
            $(".accordian dd").hide("fast");

            $(this).find("span:first").text("expand");
            $(this).css("background-image", "url('../img/backgrounds/grey-gradient.gif')");
        }
    });
});