﻿function displayLoader(message) {
    return "<div id='ajaxLoader'><img src='/Images/Ajax/ajax-loaderGrey2.gif' />&nbsp;&nbsp;" + message + "</div>";
}
function getVideoMenu(IDApp, IDSection, IDChapter) {
    $("#helpIndex").removeClass("helpIndex").addClass("helpIndexExpanded").html(displayLoader("Loading Tutorials...")).show("slow");
    $.ajax({
        type: "POST",
        url: "/services/help.asmx/getMenu",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: '{"IDApp":"' + IDApp + '","IDSection":"' + IDSection + '","IDChapter":"' + IDChapter + '"}',
        success: function (msg) {
            $("#helpIndex").html("<h1>Help Index</h1>" + msg.d);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            $("#helpIndex").removeClass("helpIndex").addClass("helpIndexExpanded").show("slow").html("<h1>An Error Occurred</h1><p>There was an error while getting a list of videos from the server.</p>");
        }
    });
}

function markAsRead(IDTutorial, IDTutorialType) {
    $.ajax({
        type: "POST",
        url: "/services/help.asmx/markAsRead",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: '{"IDTutorial":"' + IDTutorial + '","IDTutorialType":"' + IDTutorialType + '"}',
        success: function (msg) {
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert("An error occurred while saving to log");
        }
    });
}
$(function () {
    var player;
    var api = $("#overlay").overlay({
        expose: '#234559',
        api: true,
        onBeforeLoad: function () {
            //var el = this.getBackgroundImage().expose({ color: '#234559', api: true });
            //api.load();
        },

        // when overlay is opened, load our player
        onLoad: function () {
            player.load();

        },
        // when overlay is closed, unload our player
        onClose: function () {
            //this.getBackgroundImage().expose().close();
            if (player != null && player.isPlaying())
                player.stop();
            player.unload();

        }
    }); //close overlay


    // define function that opens the overlay
    window.openOverlay = function (path) {

        player = $f("player", { wmode: 'opaque', src: "/Help/swf/flowplayer-3.1.3.swf" }, { playlist: [{ url: '/Images/newsclip_hires.jpg', scaling: 'fit' }, { url: path, scaling: 'orig'}] });

        if (player != null && player.isPlaying()) {
            player.stop()
        }

        if ($("#helpIndex").hasClass("helpIndexExpanded")) {
            $("#helpIndex").removeClass("helpIndexExpanded");
            $("#helpIndex").removeClass("helpIndex").css({ "display": "none" });
        }
        api.load();
    }
});
