$(function() {
    
    var currentAnswer=null;
    
    function openAnswer(a, x) {
        $(x).attr("opened","1").show();
        $(a).css("background","url(" + scInteractiveContentInitConfig["mi"][0]["i"] + ") no-repeat left center");
    }
    
    function closeAnswer(a, x) {
        $(x).attr("opened","0").hide();
        $(a).css("background","url(" + scInteractiveContentInitConfig["pi"][0]["i"] + ") no-repeat left center");
    }
    
    $(".scInteractiveContentExpandAllContainer a").click(function() {
        
        var collapse=$(this).attr("c");
        
        if (collapse=="1") {
            $(this).attr("c",0);
            $("img",this).attr("src",scInteractiveContentInitConfig["ei"]);
        } else {
            $(this).attr("c",1);
            $("img",this).attr("src",scInteractiveContentInitConfig["ci"]);
        }
        
        $(".scInteractiveContent a.scInteractiveContentQuestion").each(function() {
        
            currentAnswer=null;
        
            if (collapse=="0" || collapse==undefined) {
                openAnswer(this, this.nextSibling)
            } else {
                closeAnswer(this, this.nextSibling)
            }
        });
    
    });
    
    $(".scInteractiveContent div.scInteractiveContentAnswer").attr("opened",0);
    
    $(".scInteractiveContent a.scInteractiveContentQuestion").each(function() {
        
        $(this).css("background","url(" + scInteractiveContentInitConfig["pi"][0]["i"] + ") no-repeat left center").click(function() {

            var a=this.nextSibling;

            var k=$(a).attr("opened");

            if (currentAnswer!=null) 
                closeAnswer(this,currentAnswer)

            if (k=="1") {
                closeAnswer(this,a);
                currentAnswer=null;
                return;
            }
            
            currentAnswer=a;
            
            
            
            if (k=="1") {
                closeAnswer(a)
                currentAnswer=null;
            }
            else {
                openAnswer(this,a);
            }
            

        });
    });
});
