﻿var actifModal;
var downloadComplete = false;
var actifModal_tst;
var actifModal_tstObjId;

function VideoOynat(ObjId) {
    /* var videoobj = document.getElementById(ObjId);*/
    //var dvVideModal = videoobj.parentNode;
   var dvVideModal = document.getElementById('dvVideModal');
    dvVideModal.style.width = 825 + 'px';
    dvVideModal.style.height = 550 + 'px';
   
    TalkToJavaScript(ObjId);
}

//Main Page xaml den çağrılan fonksiyon
function TalkToJavaScript(data) {

    var silverlightControl = document.getElementById(data);
    var videoBox = silverlightControl.parentNode;
    var modalbox = videoBox.parentNode;

    if (actifModal && actifModal != silverlightControl) {
        AktifPencereKapat("");
    }
    actifModal = silverlightControl;

    var modalboxMask = document.getElementById('modalboxMask');

    modalboxMask.className = 'modalboxMask';
    videoBox.className = 'video-ContainerPlay';
    modalbox.className = 'modalboxPlay';

    var kapat = videoBox.getElementsByTagName("div");
    kapat[0].style.display = 'block';

    //play video
    if ((screen.width <= 1280) || (screen.height <= 768)) {
        silverlightControl.Content.Page.RunJS(500, 350, true);
        videoBox.style.height = 365 + "px";
        videoBox.style.width = 625 + "px";
    }
    else {
        silverlightControl.Content.Page.RunJS(800, 535, true);
       /* videoBox.style.height = 550 + "px";
        videoBox.style.width = 825 + "px";*/
    }
}

function SetactifModal_tst(ObjId) {
    actifModal_tstObjId = ObjId;
    actifModal_tst = document.getElementById(ObjId);
}

function Videokapat(valu) {
    var videoBox = valu.parentNode.parentNode;
    var modalbox = videoBox.parentNode;
    var modalboxMask = document.getElementById('modalboxMask');

    modalboxMask.className = '';
    videoBox.className = 'video-Container';
    videoBox.style.width = 0 + 'px';
    videoBox.style.height = 0 + 'px';

    modalbox.className = 'modalbox';
    
    valu.parentNode.style.display = 'none';
    actifModal = null;
}

function kapat(valu) {
    var videoBox = valu.parentNode.parentNode;
    var modalbox = videoBox.parentNode;
    var modalboxMask = document.getElementById('modalboxMask');

    modalboxMask.className = '';
    videoBox.className = 'video-Container';
    modalbox.className = 'modalbox';

    var silverlightControl = videoBox.getElementsByTagName("object");
    silverlightControl[0].Content.Page.RunJS(150, 125, false);
    valu.parentNode.style.display = 'none';
    actifModal = null;
}

//Main Page xaml den çağrılan fonksiyon
function AktifPencereKapat(pm) {
    if (actifModal) {
        var videoBox = actifModal.parentNode;
        var modalbox = videoBox.parentNode;
        var modalboxMask = document.getElementById('modalboxMask');

        modalboxMask.className = '';
        videoBox.className = 'video-Container';
        modalbox.className = 'modalbox';

        var kapat = videoBox.getElementsByTagName("div");
        kapat[0].style.display = 'none';
        
        var dvVideModal = document.getElementById('dvVideModal');
        if (dvVideModal) {
            dvVideModal.style.width = 0 + 'px';
            dvVideModal.style.height = 0 + 'px';
        }

        actifModal.Content.Page.RunJS(150, 125, false);
        actifModal = null;
    }
}

function MesajBx(Msg) {
    alert('Silverlight Hatası:' + Msg);
}

function ResizeDiv(W, H) {
    if (actifModal) {
        var videoBox = actifModal.parentNode;
        videoBox.className = 'video-ContainerPlay';
        videoBox.style.height = (H + 25) + "px";
        videoBox.style.width = (W + 25) + "px";
    }
}

function OnSourceDownloadProgressChanged(sender, args) {
    downloadComplete = false;
    ///do silverlight action during loading from server.
}

function OnSourceDownloadComplete(sender, args) {
    downloadComplete = true;
    ///do silverlight action after loading from server.
}

function onSilverlightError(sender, args) {
    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }

    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    if (errorType == "ImageError" || errorType == "MediaError") {
        return;
    }

    var errMsg = "Unhandled Error in   Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    alert(errMsg);
}

function setWindowles(ObjId, value) {

    // get a reference to the <object>
    var obj = document.getElementById(ObjId);
    // duplicate the <object>
    var newObj = obj.cloneNode(true);
    // get a reference to the current <param>
    var param = document.getElementById('windowless');
    // duplicate the <param>
    var newParam = param.cloneNode(true);
    // change the value of the <param>
    newParam.setAttribute('value', 'newblah.midi');
    // replace the <param> tag on the <object>
    newObj.replaceChild(newParam, param);
    // replace the <object> on the page
    obj.parentNode.replaceChild(newObj, obj);



    var myObj = document.getElementById(ObjId);
    myObj.setAttribute("windowless", value ? "true" : "false");
    // Above, we access the value attribute of our referenced <param> element
}
