var DNDClassification = {};
DNDClassification.questionData = {};
DNDClassification.currentAttempt = 0;
DNDClassification.activityIntialized = false;
DNDClassification.activityCompleted = false;
let _shell_wrapper = $('#shell_wrapper');

DNDClassification.initialize = function (data) {
    //DataManager.isSliderLocked = true;
    DNDClassification.questionData = data;
    DNDClassification.mainContainer = $("#dndContainer");
    $("#questionTxt").html(DNDClassification.questionData.question);
    $("#instructionTxt").html("<span>" + DNDClassification.questionData.instruction + "</span>");

    $(".dropWrap .title").each(function (i) {
        $(this).html(DNDClassification.questionData.droppableItems.items[i].header)
    })
    DNDClassification.activityIntialized = false;
    DNDClassification.activityCompleted = false;

    DNDClassification.enableButton("solutionBtn", false);
    DNDClassification.enableButton("buttonReset", false);
    SubmitButton.init($("#dndContainer").find("#submitBtn"));
    $("#buttonReset").on('click', DNDClassification.resetOptions);

    DNDClassification.createDraggables();
    DNDClassification.createTragets();
    $("#dndFeedbackBox1").css("z-index", 9999)

}

DNDClassification.createDraggables = function () {
    for (var d = 0; d < DNDClassification.questionData.draggableItems.items.length; d++) {
        var dragItem = DNDClassification.mainContainer.find(".tempDragOption").clone();
        dragItem.removeClass("tempDragOption");
        dragItem.find("img").attr("src", DNDClassification.questionData.draggableItems.items[d].image);
        dragItem.find("#dragContent").html("<span>" + DNDClassification.questionData.draggableItems.items[d].content + "</span>");
        dragItem.attr("id", "drag_" + (d + 1));
        dragItem.attr("correctTarget", DNDClassification.questionData.draggableItems.items[d].target);
        dragItem.attr("dropTarget", "none");
        DNDClassification.mainContainer.find("#dragHolder").append("<div class='dragItemHolder dragParent" + (d + 1) + "'></div>")
        DNDClassification.mainContainer.find("#dragHolder .dragParent" + (d + 1)).append(dragItem);

    }
    $(".tempDragOption").hide();
}

DNDClassification.createTragets = function () {
    var count = -1;
    DNDClassification.mainContainer.find(".dropWrap").each(function () {
        count++;
        $(this).attr("totalPlaced", 0);
        $(this).attr("maxDrop", DNDClassification.questionData.droppableItems.items[count].maxDrop);
    });
}
scalePercentage = 1;
DNDClassification.addListeners = function () {
    if (!DNDClassification.activityIntialized) {
        DNDClassification.enableButton("solutionBtn", false);

        DNDClassification.activityIntialized = true;
        for (var d = 0; d < DNDClassification.questionData.draggableItems.items.length; d++) {
            var dragItem = DNDClassification.mainContainer.find("#dragHolder").find("#drag_" + (d + 1));
            $(dragItem).draggable({
                containment: $(".containment"),
                start: DNDClassification.dragStart,
                stop: DNDClassification.dragStop,
                revert: DNDClassification.dragRevert,
                drag: function (event, ui) {
                    if (scalePercentage < 1) {
                        var changeLeft = ui.position.left - ui.originalPosition.left;
                        var newLeft = ui.originalPosition.left + changeLeft / ((scalePercentage));
                        var changeTop = ui.position.top - ui.originalPosition.top;
                        var newTop = ui.originalPosition.top + changeTop / scalePercentage;
                        ui.position.left = newLeft;
                        ui.position.top = newTop;
                    }

                }
            });
        }
        $(".dropWrap").droppable({
            accept: '.dragItem',
            drop: DNDClassification.onDrop
        });
        $(".dragItem").on('keydown', DNDClassification.keyDownFunction)

    }


}
DNDClassification.keyDownFunction = function (e) {
    if ($(this).hasClass("disabled"))
        return false;
    var keyNo = e.which - 96;
    if (keyNo >= 1 && keyNo < 3) {
        if ($('#dropHolder' + keyNo).attr("totalPlaced") < $('#dropHolder' + keyNo).attr("maxDrop")) {

            var dropId = keyNo;
            if ($('#dropHolder' + keyNo).attr("dropTarget") == dropId)
                return;

            var pl = $('#dropHolder' + keyNo).attr("totalPlaced");
            if (pl < $('#dropHolder' + keyNo).attr("maxDrop")) {
                if ($(this).attr("dropTarget") != "none") {
                    var myDropTarget = DNDClassification.mainContainer.find("#dropHolder" + $(this).attr("dropTarget"));
                    var placed = myDropTarget.attr("totalPlaced") - 1;
                    myDropTarget.attr("totalPlaced", placed);
                }

                $(this).css("top", "0px");
                $(this).css("left", "0px");
                $(this).css("z-index", 2);
                //alert($(".dragWrap").children("#"+$(ui.draggable).attr("id")).attr("id"));	
                var thisid = $(this).attr("id")
                setTimeout(function () {
                    //$(".dragParent"+)
                    $(".dragWrap").find("#" + thisid).addClass("opacity");
                    $(".dropWrap").find("#" + thisid).removeClass("opacity");
                }, 100)

                if ($(this).attr("dropTarget") != "none") {
                    $('#dropHolder' + keyNo).append($(this));
                } else {
                    var temp = $(this).clone();
                    temp.attr("dropTarget", dropId);

                    $(temp).draggable({
                        containment: $("#dndContainer"),
                        start: DNDClassification.dragStart,
                        stop: DNDClassification.dragStop,
                        revert: DNDClassification.dragRevert
                    });
                    $(temp).on('keydown', DNDClassification.keyDownFunction)
                    $('#dropHolder' + keyNo).append(temp);
                }
                pl++;
                $('#dropHolder' + keyNo).attr("totalPlaced", pl);
                DNDClassification.checkAllPlaced();
            } else {
                pl++;
                $('#dropHolder' + keyNo).attr("totalPlaced", pl);
            }

            if ($(this).attr("dropTarget") != dropId) {
                //alert($(this).attr("dropTarget"))
                if ($(this).attr("dropTarget") == "none") {
                    $(this).blur();
                    $(this).attr('tabindex', -1);
                    $(this).css("z-index", "0");
                    $(this).addClass("disabled");
                }


                $(this).attr("dropTarget", dropId);
            }
        }

    }
}

DNDClassification.dragStart = function (dropped, ui) {
    if ($(this).hasClass("disabled"))
        return false;
    $(this).css("z-index", "20");
    $(this).removeAttr("revert");

}

DNDClassification.dragStop = function (dropped, ui) {
    $(this).css("z-index", "0");
}

DNDClassification.dragRevert = function (dropped, ui) {
    if (dropped) {
        $(".InstrutationText2").hide()
        if (dropped.attr("totalPlaced") > dropped.attr("maxDrop")) {
            var num = dropped.attr("totalPlaced");
            dropped.attr("totalPlaced", num - 1);
            $(this).data("uiDraggable").originalPosition = {
                top: 0,
                left: 0
            };

            if (placed === 0) {
                DNDClassification.enableButton("buttonReset", false);
            }
            return true;
        }

        //if dropped at proper draggable object
        var dropId = dropped.attr("id").substr(String(dropped.attr("id")).length - 1, 1);

        //if object already placed at same target - snapback
        if ($(this).attr("dropTarget") == dropId) {
            $(this).data("uiDraggable").originalPosition = {
                top: 0,
                left: 0
            };

            if (placed === 0) {
                DNDClassification.enableButton("buttonReset", false);
            }
            return true;
        } else {
            //if draggable placed first time, add disable class to its main reference
            //if ($(this).attr("dropTarget") == "none")
            //$(this).addClass("disabled");

            //$(this).attr("dropTarget", dropId);
        }
    } else {
        //if dropped outiside
        if ($(this).attr("dropTarget") != "none") {

            //var dragNo = $(this).attr("id").split("_")[1];
            //alert(dragNo)
            var pos = $('#dragHolder #' + $(this).attr("id")).offset()
            //alert($('#dragHolder #'+ $(this).attr("id")).css('left'))
            $('#dragHolder #' + $(this).attr("id")).addClass("ui-draggable").draggable('option', 'disabled', false).removeClass('opacity');
            $(this).offset({
                top: pos.top,
                left: pos.left
            });

            $(this).remove();
            var myDropTarget = DNDClassification.mainContainer.find("#dropHolder" + $(this).attr("dropTarget"));
            var placed = myDropTarget.attr("totalPlaced");
            myDropTarget.attr("totalPlaced", --placed);
            //dragHolder
        } else {
            $(this).data("uiDraggable").originalPosition = {
                top: 0,
                left: 0
            };
        }

        DNDClassification.checkAllPlaced();

        if (placed === 0) {
            DNDClassification.enableButton("buttonReset", false);
        }

        return true;
    }
}

DNDClassification.onDrop = function (event, ui) {
    //trace("onDrop");

    var dropId = $(this).attr("id").substr(String($(this).attr("id")).length - 1, 1);

    if ($(ui.draggable).attr("dropTarget") == dropId)
        return;

    var pl = $(this).attr("totalPlaced");
    if (pl < $(this).attr("maxDrop")) {
        if ($(ui.draggable).attr("dropTarget") != "none") {
            var myDropTarget = DNDClassification.mainContainer.find("#dropHolder" + $(ui.draggable).attr("dropTarget"));
            var placed = myDropTarget.attr("totalPlaced") - 1;
            myDropTarget.attr("totalPlaced", placed);
        }

        $(ui.draggable).css("top", "0px");
        $(ui.draggable).css("left", "0px");
        $(ui.draggable).css("z-index", 2);
        //alert($(".dragWrap").children("#"+$(ui.draggable).attr("id")).attr("id"));	

        setTimeout(function () {
            if ($(ui.draggable).attr("revert") != "true") {
                $(".dragWrap").find("#" + $(ui.draggable).attr("id")).addClass("opacity");
                $(".dropWrap").find("#" + $(ui.draggable).attr("id")).removeClass("opacity");
            }
        }, 100);

        /* 		alert($(ui.draggable).attr("id"))
                $(ui.draggable).css("opacity",.3);	
                $(ui.draggable).css(" -ms-filter","progid:DXImageTransform.Microsoft.Alpha(Opacity=50)");			 */
        var _dropId = dropId;
        if ($(ui.draggable).attr("dropTarget") != "none") {
            $(this).append($(ui.draggable));
            $(ui.draggable).attr("dropTarget", _dropId)
            // var temp1 = $(ui.draggable).clone();
            // temp1.attr("dropTarget", dropId);
            // alert(dropId)
        } else {
            /*if (dropId != $(ui.draggable).attr("correcttarget")) {
                $(ui.draggable).attr("revert", true);
            }
            else {*/
            var temp = $(ui.draggable).clone();
            temp.attr("dropTarget", dropId);


            $(temp).draggable({
                containment: $("#dndContainer"),
                start: DNDClassification.dragStart,
                stop: DNDClassification.dragStop,
                revert: DNDClassification.dragRevert
            });

            $(this).append(temp);
            $(ui.draggable).removeClass("ui-draggable").draggable('option', 'disabled', true);
            pl++;
            $(this).attr("totalPlaced", pl);
            DNDClassification.checkAllPlaced();
            //}
            DNDClassification.enableButton("buttonReset", true);
        }
    } else {
        pl++;
        $(this).attr("totalPlaced", pl);
    }

    $(this).addClass("disabled")
}

DNDClassification.checkAllPlaced = function () {
    // if (DNDClassification.mainContainer.find(".dropWrap").find(".dragItem").length == parseInt(DNDClassification.questionData.droppableItems.items[0].maxDrop)) {
    //     SubmitButton.chkSubmitEnable(true);
    //     //DNDClassification.showFeedback(true);
    // } else {
    //     SubmitButton.chkSubmitEnable(false);
    // }


    if (DNDClassification.mainContainer.find(".dropWrap").find(".dragItem").length >= DNDClassification.questionData.draggableItems.items.length) {
        SubmitButton.chkSubmitEnable(true);
        $("#submitBtn").off().on('click', DNDClassification.submitClicked);
        //DNDClassification.showFeedback(true);
    } else {

        $("#submitBtn").off();
        SubmitButton.chkSubmitEnable(false);
    }
}

DNDClassification.enableButton = function (buttonId, enableFlag) {
    if (enableFlag) {
        if (buttonId === "solutionBtn") {
            $("#solutionBtn").show().removeClass('disabled').off().on('click', DNDClassification.showSolution);
        } else {
            $("#buttonReset").show().removeClass('disabled').off().on('click', DNDClassification.resetOptions);
        }
    } else {
        if (buttonId === "solutionBtn") {
            $("#" + buttonId).addClass('disabled').off('click');
        } else {
            $("#" + buttonId).addClass('disabled').off('click');
        }
    }
}

DNDClassification.submitClicked = function () {


    DNDClassification.disableOptions();
    DNDClassification.enableButton("buttonReset", false);
    var correctCounter = 0;

    DNDClassification.mainContainer.find(".dropWrap").find(".dragItem").each(function () {
        console.log($(this).attr("id") + " " + $(this).attr("correctTarget") + " " + $(this).attr("dropTarget"))
        if ($(this).attr("correctTarget") == $(this).attr("dropTarget")) {
            correctCounter++;
        } else {
            correctCounter--;
        }

    });
    //var corrCount = parseInt(DNDClassification.questionData.droppableItems.items[0].maxDrop);
    var corrCount = 0;

    for (var i = 0; i < DNDClassification.questionData.draggableItems.items.length; i++) {
        if (DNDClassification.questionData.draggableItems.items[i].target == "1") {
            corrCount++;
        }
    }
    console.log("correctCounter " + correctCounter + " corrCount" + corrCount + "  items.length" + DNDClassification.questionData.draggableItems.items.length)
    if (correctCounter == DNDClassification.questionData.draggableItems.items.length) {
        DNDClassification.showFeedback(true);
        $(".lftColumn").hide();
        //DataManager.isSliderLocked = false;
        Utils.pageCompleted()
    } else {
        DNDClassification.showFeedback(false);
    }

}


var _DND_Audio = [{
    id: "1",
    autoplay: true,
    url: './shell/audio/blank.mp3',
    timeline: [],
    title: "",
    description: "",
    transcript: ''
}]

DNDClassification.showFeedback = function (flag) {
    SubmitButton.chkSubmitEnable(false);
    DNDClassification.currentAttempt++;

    if (DNDClassification.questionData.responseType == "generic") {
        DNDClassification.mainContainer.find("#dndFeedbackBox1").removeClass('Correct Incorrect Debrief')
        var feedObj = DNDClassification.mainContainer.find("#dndFeedbackBox1").find(".tempFeedback").clone();
        feedObj.removeClass("tempFeedback Correct Incorrect");

        if (flag) {
            DNDClassification.mainContainer.find("#dndFeedbackBox1").addClass('Correct');
            feedObj.find("#imgHolder img").attr("src", DNDClassification.questionData.genericResponse.correct.image);
            feedObj.find("#contentHolder #content").html(DNDClassification.questionData.genericResponse.correct.content);
            if (DNDClassification.questionData.genericResponse.correct.header)
                $("#dndFeedbackBox1 #feedbackHeader span").html(DNDClassification.questionData.genericResponse.correct.header);
            DNDClassification.showTickOnly();
        } else if (DNDClassification.currentAttempt < DNDClassification.questionData.maxAttempts) {
            DNDClassification.mainContainer.find("#dndFeedbackBox1").addClass('Incorrect')
            feedObj.find("#imgHolder img").attr("src", DNDClassification.questionData.genericResponse.incorrect.image);
            feedObj.find("#contentHolder #content").html(DNDClassification.questionData.genericResponse.incorrect.content);
            if (DNDClassification.questionData.genericResponse.incorrect.header)
                $("#dndFeedbackBox1 #feedbackHeader span").html(DNDClassification.questionData.genericResponse.incorrect.header);
        } else {
            DNDClassification.mainContainer.find("#dndFeedbackBox1").addClass('Incorrect')
            feedObj.find("#imgHolder img").attr("src", DNDClassification.questionData.genericResponse.incorrect.image);
            feedObj.find("#contentHolder #content").html(DNDClassification.questionData.genericResponse.incorrect.content);

            if (DNDClassification.questionData.genericResponse.incorrect.header)
                $("#dndFeedbackBox1 #feedbackHeader span").html(DNDClassification.questionData.genericResponse.incorrect.header);

            //$("#submitBtn").hide();
            DNDClassification.enableButton("solutionBtn", true);

            DNDClassification.mainContainer.find(".dropWrap").find(".dragItem").each(function () {
                if ($(this).attr("correctTarget") == $(this).attr("dropTarget"))
                    $(this).addClass("correct");
                else
                    $(this).addClass("incorrect");
            });

            DNDClassification.mainContainer.find(".dragWrap").find(".dragItem").each(function () {
                if (!$(this).hasClass("opacity")) {
                    if ($(this).attr("correctTarget") == 1)
                        $(this).addClass("correct");
                    else
                        $(this).addClass("incorrect");
                }
            });

            DNDClassification.markPageComplete();
        }

        DNDClassification.mainContainer.find("#dndFeedbackContent").append(feedObj);
    } else {
        DNDClassification.mainContainer.find("#dndFeedbackBox1").removeClass('Correct Incorrect Debrief')
        for (var f = 0; f < DNDClassification.questionData.draggableItems.items.length; f++) {
            var feedObj = DNDClassification.mainContainer.find("#dndFeedbackBox1").find(".tempFeedback").clone();
            feedObj.removeClass("tempFeedback");
            feedObj.find("#imgHolder img").attr("src", DNDClassification.questionData.specificResponse.response[f].image);
            feedObj.find("#contentHolder #content").html(DNDClassification.questionData.specificResponse.response[f].content);
            $("#dndFeedbackBox1 #feedbackHeader span").html(DNDClassification.questionData.specificResponse.response[f].header);
            DNDClassification.mainContainer.find("#dndFeedbackContent").append(feedObj);
        }

        DNDClassification.mainContainer.find("#dndFeedbackBox1").find(".tempFeedback").remove();

        if (flag) {
            DNDClassification.mainContainer.find("#dndFeedbackContent").addClass('Correct')
            DNDClassification.showTickOnly();
        } else {
            DNDClassification.mainContainer.find("#dndFeedbackContent").addClass('Incorrect')

            // if (DNDClassification.currentAttempt >= DNDClassification.questionData.maxAttempts)
            //     $("#submitBtn").hide()
            DNDClassification.enableButton("solutionBtn", true);

        }
    }

    if ($("#dragDropContainer").length == 1) {
        // if (DNDClassification.questionData.feedbackdrag) {
        $("#dndFeedbackBox1").show();

    } else if ($("#dndContainer").length == 1) {
        // if (DNDClassification.questionData.feedbackdrag) {
        $("#dndFeedbackBox1").show()
    }

    $("#dndFeedbackBox1").focus();
    //closing feedback and resetting options
    $("#dndFeedbackBox1").find("#feedbackClose").on("click", DNDClassification.closeFeedback);
    //DNDClassification.resetOptions();
    Utils.updateAudio(_DND_Audio[0], function () {

    })
}



DNDClassification.closeFeedback = function () {
    if (DNDClassification.mainContainer.find("#dndFeedbackBox1").hasClass('Incorrect')) {
        DNDClassification.showSolution();
        Utils.pageCompleted()
    }
    $("#dndFeedbackBox1").hide()
}

DNDClassification.resetOptions = function () {
    $(".InstrutationText2").show()
    $("#submitBtn").off();
    DNDClassification.mainContainer.find("#dragHolder").find(".dragItem").each(function () {
        if ($(this).hasClass("ui-draggable-disabled")) {
            //$(this).removeClass("disabled")
            $(this).attr("dropTarget", "none");

            //var temp = $(this).clone();
            $(this).removeClass("incorrect ui-draggable-disabled ui-state-disabled opacity").addClass("ui-draggable").draggable('option', 'disabled', false);
        }
    });

    for (var c = 1; c <= DNDClassification.questionData.droppableItems.items.length; c++) {
        var dropTarget = DNDClassification.mainContainer.find("#dropHolder" + c);
        dropTarget.attr("totalPlaced", 0);
    }

    DNDClassification.mainContainer.find(".dropWrap").find(".dragItem").each(function () {
        $(this).remove();
    });

    DNDClassification.enableButton("solutionBtn", false);
    DNDClassification.enableButton("buttonReset", false);
    SubmitButton.chkSubmitEnable(false);
    //DataManager.isSliderLocked = true;
}

DNDClassification.showTickOnly = function () {
    DNDClassification.mainContainer.find(".dropWrap").find(".dragItem").each(function () {
        $(this).addClass("correct");
    });
    DNDClassification.markPageComplete();
}

DNDClassification.showSolution = function () {
    //DataManager.isSliderLocked = false;
    DNDClassification.mainContainer.find("#dndFeedbackBox1").removeClass('Correct Incorrect Debrief').addClass("Debrief");
    var feedObj = DNDClassification.mainContainer.find("#dndFeedbackBox1").find(".tempFeedback").clone();
    feedObj.removeClass("tempFeedback Correct Incorrect");
    feedObj.find("#imgHolder img").attr("src", DNDClassification.questionData.genericResponse.solution.image);
    feedObj.find("#contentHolder #content").html(DNDClassification.questionData.genericResponse.solution.content);

    if (DNDClassification.questionData.genericResponse.solution.header)
        $("#dndFeedbackBox1 #feedbackHeader span").html(DNDClassification.questionData.genericResponse.solution.header);

    DNDClassification.mainContainer.find("#dndFeedbackBox1").find(".row").css('display', 'none');
    DNDClassification.mainContainer.find("#dndFeedbackContent").append(feedObj);

    // DNDClassification.mainContainer.find(".dragWrap").find(".dragItem").each(function() {

    //             $(this).removeClass("correct");

    //             $(this).removeClass("incorrect");

    // });

    if ($("#dragDropContainer").length == 1) {
        $("#dndFeedbackBox1").show()
            /*.draggable({
                        containment: "#dragDropContainer",
                        handle: "#feedbackHeader"
                    })*/
            ;
    } else if ($("#dndContainer").length == 1) {
        $("#dndFeedbackBox1").show()
            /*.draggable({
                        containment: "#dndContainer",
                        handle: "#feedbackHeader"
                    })*/
            ;
    }

    // $("#dndFeedbackBox1").focus();
    // DNDClassification.mainContainer.find("#dndFeedbackBox1").find(".row").eq(2).css('display', 'block');

    DNDClassification.mainContainer.find(".dropWrap").find(".dragItem").each(function () {
        var dragId = $(this).attr("id");
        $(this).remove();
        // var dragItemEle = DNDClassification.mainContainer.find("#dragHolder").find("#" + dragId);
        //DNDClassification.mainContainer.find("#dragHolder").append($(this));

        // $(this).css('position', 'absolute');
        // $(this).position().left = $(dragItemEle).parent().position().left;
        // $(this).position().top = $(dragItemEle).parent().position().top;

        //$(this).removeClass("incorrect ui-draggable-disabled ui-state-disabled opacity");
        //$("#" + dragId).removeClass("incorrect ui-draggable-disabled ui-state-disabled opacity");

    });

    DNDClassification.mainContainer.find(".dragItem").each(function () {
        $(this).removeClass("incorrect ui-draggable-disabled ui-state-disabled opacity");
        if ($(this).attr("correcttarget") == "1") {
            var temp = $(this).clone();
            temp.addClass("correct");
            $(this).addClass('opacity')
            $(this).parent().hide()
            DNDClassification.mainContainer.find("#dropHolder1").append(temp);
            // $(this).removeClass("incorrect ui-draggable-disabled ui-state-disabled opacity").addClass("correct");
        }
        if ($(this).attr("correcttarget") == "2") {
            var temp = $(this).clone();
            temp.addClass("correct");
            $(this).addClass('opacity')
            $(this).parent().hide()
            DNDClassification.mainContainer.find("#dropHolder2").append(temp);
            // $(this).removeClass("incorrect ui-draggable-disabled ui-state-disabled opacity").addClass("correct");
        }
    });

    DNDClassification.enableButton("solutionBtn", false);
    DNDClassification.markPageComplete();

    try {
        //    // $(".debriefBox").fadeIn();
        //     $("#debriefClose").off().on("click", function () {
        //         $(".debriefBox").hide();
        //         DNDClassification.enableButton("solutionBtn", true);
        //     });

    } catch (error) {

    }
}

DNDClassification.markPageComplete = function () {

}

DNDClassification.disableOptions = function () {
    DNDClassification.mainContainer.find("#dragHolder").find(".dragItem").each(function () {
        if (!$(this).hasClass("disabled")) {
            $(this).addClass("disabled")
        }
    });
    DNDClassification.mainContainer.find(".dropWrap").find(".dragItem").each(function () {
        $(this).addClass("disabled")
    });
}


loadDnDClassificationDataFn = function (data) {
    return parseDNDClassificationData(data);
}



parseDNDClassificationData = function (data) {
    var dndObj = {};
    var dndData = data;
    dndObj.audio = $(dndData).attr("audio");
    dndObj.scenario = $(dndData).attr("scenarioText");
    dndObj.question = $(dndData).attr("question");
    dndObj.instruction = $(dndData).attr("instructionText");
    dndObj.responseType = $(dndData.DND).attr("responseType");
    dndObj.maxAttempts = $(dndData.DND).attr("maxAttempts");
    dndObj.feedbackdrag = $(dndData.DND).attr("feedbackdrag");
    dndObj.draggableItems = {};
    //console.log(data.data);
    dndObj.draggableItems.label = $(dndData.DND.draggableItems).attr("label");
    dndObj.draggableItems.items = [];
    for (var d = 0; d < dndData.DND.draggableItems.items.length; d++) {
        dndObj.draggableItems.items[d] = {};
        dndObj.draggableItems.items[d].target = $(dndData.DND.draggableItems.items[d]).attr("target");
        dndObj.draggableItems.items[d].content = $(dndData.DND.draggableItems.items[d]).attr("content");
        dndObj.draggableItems.items[d].image = $(dndData.DND.draggableItems.items[d]).attr("image");
    }
    dndObj.droppableItems = {};
    dndObj.droppableItems.label = $(dndData.DND.droppables).attr("label");
    dndObj.droppableItems.items = [];
    for (var r = 0; r < dndData.DND.droppables.items.length; r++) {
        dndObj.droppableItems.items[r] = {};
        dndObj.droppableItems.items[r].maxDrop = parseInt($(dndData.DND.droppables.items[r]).attr("maxDrop"));
    }

    dndObj.genericResponse = {};
    dndObj.genericResponse.correct = {};
    dndObj.genericResponse.correct.header = $(dndData.DND.feedback.genericResponse.correct).attr("header");
    dndObj.genericResponse.correct.content = $(dndData.DND.feedback.genericResponse.correct).attr("content");
    dndObj.genericResponse.correct.audio = $(dndData.DND.feedback.genericResponse.correct).attr("audio");
    dndObj.genericResponse.correct.image = $(dndData.DND.feedback.genericResponse.correct).attr("image");
    dndObj.genericResponse.incorrect = {};
    dndObj.genericResponse.incorrect.header = $(dndData.DND.feedback.genericResponse.incorrect).attr("header");
    dndObj.genericResponse.incorrect.content = $(dndData.DND.feedback.genericResponse.incorrect).attr("content");
    dndObj.genericResponse.incorrect.audio = $(dndData.DND.feedback.genericResponse.incorrect).attr("audio");
    dndObj.genericResponse.incorrect.image = $(dndData.DND.feedback.genericResponse.incorrect).attr("image");
    dndObj.genericResponse.solution = {};
    dndObj.genericResponse.solution.header = $(dndData.DND.feedback.genericResponse.solution).attr("header");
    dndObj.genericResponse.solution.content = $(dndData.DND.feedback.genericResponse.solution).attr("content");
    dndObj.genericResponse.solution.audio = $(dndData.DND.feedback.genericResponse.solution).attr("audio");
    dndObj.genericResponse.solution.image = $(dndData.DND.feedback.genericResponse.solution).attr("image");

    dndObj.specificResponse = {};
    dndObj.specificResponse.response = [];
    for (var r = 0; r < dndData.DND.feedback.specificResponse.response.length; r++) {
        var responseObj = {};
        responseObj.content = $(dndData.DND.feedback.specificResponse.response[r]).attr("content");
        responseObj.image = $(dndData.DND.feedback.specificResponse.response[r]).attr("image");
        responseObj.header = $(dndData.DND.feedback.specificResponse.response[r]).attr("header");
        dndObj.specificResponse.response[r] = responseObj;
    }
    return dndObj;
}

var init_activity = (function () {
    this.init = function (data, callback) {
        tabData = loadDnDClassificationDataFn(data.DND_data);
        DNDClassification.initialize(tabData);
        setTimeout(function () {
            DNDClassification.addListeners();
        }, 50);
    };
    return this;

})