//подгрузка окна инструкций
function get_instruction_wnd(page_name) {
    $.ajax({
        url: '/instructions/GetInstrWnd',
        type: 'post',
        dataType: 'html',
        async: true,
        data: {
            page_name: page_name
        },
        success: function (data) {                        
            $('body').append(data);
        },
        complete: function () {
            stop_wait();
        },
        beforeSend: function () {
            start_wait();
        }
    });
};

function start_wait() {
    $('.wait').show();
};
function stop_wait() {
    $('.wait').hide();
};

function build_instr_editor(data) {    
    destroy_videos();
    var outStr = '';
    $.each(data, function (i, o) {
        outStr += '<h3 class="vTitle">' + o.title + '</h3>';      
        outStr += '<div id="V' + o.video_id + i + '" class="iVideo" vid="' + o.video_id + '"></div>';        
    });
    $('.instr_vd_content').html(outStr);
    $('.iVideo').each(function () {
        var id = $(this).attr('id');
        var vid = $(this).attr('vid');

        var player = new YT.Player(id, {
            height: '390',
            width: '600',
            videoId: vid /*,
                    events: {
                        'onReady': onPlayerReady,
                        'onStateChange': onPlayerStateChange
                    }*/
        });
        push_video(player);
    });
};
function push_video(p) {
    videos.push(p);
};
function destroy_videos() {    
    $.each(videos, function (i, o) {
        try {            
            o.destroy();            
        } catch (e) {
            console.log(e);
        };
    });
    videos = [];
}
var videos = [];    

function close_instr_wnd() {
    destroy_videos();
    $('.instrWnd').remove();

};

(function ($) {
    
    $(function () {
        $(document).on('click', '.closeDiv', function () {
            close_instr_wnd();
        });
        $(document).on('click', '.close_instr', function () {
            close_instr_wnd();
        });        
    });

})(jQuery);