﻿//----------- accordion----------------
$(function () {
    $(".question").each(function () {
        var random = Math.floor(Math.random() * 100000);

        $(this).attr("id", "question" + random);
        $(this).next().attr("id", random);
    });

    $(".answer").attr("style", "display:none");

    $(".question").click(function () {
        var qId = $(this).attr("id").split("question");

        $("#" + $(this).attr("id") + " .ImageButton_Accordion").attr("rel", qId);


        if ($("#" + qId[1]).attr("style") == "display: block;" || $("#" + qId[1]).attr("style") == "display:block" || $("#" + qId[1]).attr("style") == "display: block") {
            $(".answer").slideUp();
            $(this).attr("style", "background-image: url(../Templates/Images/AEins/arrow-down.png);");
        }
        else {
            $('.answer').each(function () {

                if ($(this).attr("id") != qId[1]) {
                    $(this).slideUp();
                    $('.question').attr("style", "background-image: url(../Templates/Images/AEins/arrow-down.png);");
                }
            });
            $("#" + qId[1]).slideDown();
            $(this).attr("style", "background-image: url(../Templates/Images/AEins/arrow-up.png);");
            $("#" + qId[1]).promise().done(function () {
                $("#" + qId[1]).attr("style", "display:block");
            });

        }
    });
});



//$(function() {
//        $(".question").each(function () {
//            var random = Math.floor(Math.random() * 100000);

//            $(this).attr("id", "question" + random);
//            $(this).next().attr("id", random);
//        });

//        $(".answer").attr("style", "display:none");

//        $(".question").click(function () {
//            var qId = $(this).attr("id").split("question");
//            
//            if ($("#" + qId[1]).attr("style") == "display:block") {                
//                $(".answer").slideUp();
//            }
//            else {                
//                $('.answer').each(function () {

//                    if ($(this).attr("id") != qId[1]) {
//                        $(this).slideUp();
//                    }
//                });
//                $("#" + qId[1]).slideDown();
//                $("#" + qId[1]).promise().done(function () {
//                    $("#" + qId[1]).attr("style", "display:block");
//                });

//            }
//        });
//    });

