
function Create_cPanel(mediaCall, video, share, videoContainer) {
    var Self        = this;
    var isFit       = false;
    var isMax       = false;
    var panelShowed = false;
    var hideTimer   = null;
    var _cPanel     = document.createElement("div");
    var _fade       = new mcService.FadeControl(_cPanel);
    var controls    = {
        cameraSwitch     : document.createElement("span"),
        microphoneSwitch : document.createElement("span"),
        cancelCall       : document.createElement("span"),
        fillFitScreen    : document.createElement("span"),
        minMaxScreen     : document.createElement("span"),
        recordCall       : document.createElement("span"),
    };

    _cPanel.id                   = "cPanel";
    controls.cameraSwitch    .id = "cameraSwitch";
    controls.microphoneSwitch.id = "microphoneSwitch";
    controls.cancelCall      .id = "cancelCall";
    controls.fillFitScreen   .id = "fillFitScreen";
    controls.minMaxScreen    .id = "minMaxScreen";
    controls.recordCall      .id = "recordCall";

    controls.cameraSwitch .style.display = video ? "inline-block" : "none";
    controls.fillFitScreen.style.display = share ? "inline-block" : "none";
    controls.minMaxScreen .style.display = video || share ? "inline-block" : "none";

    // _cPanel.appendChild(controls.recordCall);
    _cPanel.appendChild(controls.cameraSwitch);
    _cPanel.appendChild(controls.microphoneSwitch);
    _cPanel.appendChild(controls.fillFitScreen);
    _cPanel.appendChild(controls.minMaxScreen);
    _cPanel.appendChild(controls.cancelCall);

    // ------------------------

    function showPanel() {
        if (panelShowed){
            clearTimeout(hideTimer);

            hideTimer = setTimeout(function () {
                panelShowed = false;
                hideTimer   = null;

                _fade.out();
            }, 4000);
        } else {
            _fade.in();

            panelShowed = true;
        }
    }

    // ------------------------

    controls.cameraSwitch.addEventListener('click', function(){
        if (mcService.checkRights(mcConst._CMD_.RS.QPrivAllowDisableCameraDuringCalls)){
            if (mediaCall.switchCamera()){
                controls.cameraSwitch.className = "";
            } else {
                controls.cameraSwitch.className = "cameraSwitchOFF";
            }
        }
    });

    controls.microphoneSwitch.addEventListener('click', function(){
        if (mcService.checkRights(mcConst._CMD_.RS.QPrivAllowMuteSoundDuringCalls)){
            if (mediaCall.switchMicrophone()) {
                controls.microphoneSwitch.className = "";
            } else {
                controls.microphoneSwitch.className = "microphoneSwitchOFF";
            }
        }
    });

    controls.fillFitScreen.addEventListener('click', function(){
        if (Self.fitFill) Self.fitFill(isFit, videoContainer);

        controls.fillFitScreen.className = isFit ? "" : "fillFitScreenOFF";

        isFit = !isFit;
    });

    controls.minMaxScreen.addEventListener('click', function () {
        if (Self.minMax) Self.minMax(isMax);

        isMax = !isMax;
    });

    controls.cancelCall.addEventListener('click', function () {
        if (mcService.checkRights(mcConst._CMD_.RS.QPrivAllowHangUpCalls) && Self.closeCall) Self.closeCall();
    });

    controls.recordCall.addEventListener('click', function () {
        if (mcService.checkRights(mcConst._CMD_.RS.QPrivAllowRecordMediaCalls) && Self.record) Self.record();
    });

    // --------------------------------

    if (!mcService.checkRights(mcConst._CMD_.RS.QPrivAllowMuteSoundDuringCalls)) {
        controls.microphoneSwitch.style.opacity = .3;
    }

    if (!mcService.checkRights(mcConst._CMD_.RS.QPrivAllowDisableCameraDuringCalls)) {
        controls.cameraSwitch.style.opacity = .3;
    }

    if (!mcService.checkRights(mcConst._CMD_.RS.QPrivAllowHangUpCalls)) {
        controls.cancelCall.style.opacity = .3;
    }

    if (!mcService.checkRights(mcConst._CMD_.RS.QPrivAllowRecordMediaCalls)) {
        controls.recordCall.style.opacity = .3;
    }

    // --------------------------------

    this.body      = _cPanel;
    this.closeCall = null;
    this.minMax    = null;
    this.fitFill   = null;
    this.record    = null;

    this.init = function (parent) {
        if (parent){
            parent.appendChild(_cPanel);
        }
    };

    this.show = function () {
        _cPanel.className    += "whitePanelBG";
        _cPanel.style.opacity = 1;

        panelShowed = true;

        showPanel();
    };

    this.onmousemove = showPanel;

    this.destructor = function () {
        if (_cPanel){
            _cPanel.innerHTML = "";

            if (_cPanel.parentNode) {
                _cPanel.parentNode.removeChild(_cPanel);
            }

            _cPanel = null;
        }
    };
}