/*
 * JQuery functionality specific for the Movia site
 */

/* Code from 1508. For the simple tree node expansion. Customized a bit for movia */
var simpleTreeCollection;
$(document).ready(function() {
    simpleTreeCollection = $('.simpleTree').simpleTree({
        autoclose: true,
        drag: false,
        afterClick: function(node) {
            //alert("text-"+$('span:first',node).text());
        },
        afterDblClick: function(node) {
            //alert("text-"+$('span:first',node).text());
        },
        afterMove: function(destination, source, pos) {
            //alert("destination-"+destination.attr('id')+" source-"+source.attr('id')+" pos-"+pos);
        },
        afterAjax: function() {
            //alert('Loaded');
        },
        animate: true
        //,docToFolderConvert:true
    });
});

$(document).ready(function() {
    // newuser lightbox
    if ($("input[id $= 'ProfileCreated']").val() == "true") {
        $("input[id $= 'ProfileCreated']").val("false");
        $("div[id $= 'basic-modal-content']").modal({ onClose: NewUserModal_close });
    }

    //.LineScheduleV3 <span> click behavior
    $(".LineScheduleV3 ul>li>span").click(function() {
        var url = $(this).attr("href");
        $(location).attr('href', url); ;
    });
    $(".LineScheduleV3 .active").parents("ul").parents("li.folder-close").addClass("folder-open");
    $(".LineScheduleV3 .active").parents("ul").parents("li.folder-close").removeClass("folder-close");
    $(".LineScheduleV3 .active").parents("ul").css("display", "block");
});

// close newuser lightbox
function NewUserModal_close() {
    var url = $("div[id $= 'basic-modal-content']").attr("href");
    $(location).attr("href", url);
    $.modal.close(); // must call this!
}