﻿
var _p;
function LoadD8Game(gamePath, w, h, d8cname, gamecname) {
    var game = '<object id="ExternalInterfaceExample" width="' + w + '" height="' + h + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
        + '<param name="movie" value="glct.swf" />'
        + '<param name="quality" value="high" />'
        + '<param name="bgcolor" value="#869ca7" />'
        + '<param name="allowScriptAccess" value="always" />'
        + '<param name="FlashVars" value="gamePath=' + gamePath + '&w=' + w + '&h=' + h + '&d8cname=' + d8cname + '&gamecname=' + gamecname + '">'
        + '<embed src="glct.swf" quality="high" bgcolor="#869ca7" width="500" height="375" name="ExternalInterfaceExample" align="middle" play="true" loop="false" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">'
        + '</embed>'
     + '</object>';
    showGameWindow(game, w, h);
}
function showGameWindow(msg, w, h) {
    _p = new wanMessageBox(msg, h, w);
}
function HideGame() {
    _p.HideGame();
}
/* 
wanMessageBox弹出框 
msg: 将要显示的信息
vheight: 显示的高度, 
vwidth:消息框的宽度 
*/
function wanMessageBox(msg, vheight, vwidth) {
    var pop = window.createPopup();

    var _msg = msg;
    var w = vwidth;
    var h = vheight + 30;
    
    //居中显示 
    var l = (document.body.clientWidth - w) / 2; 
    var t = (document.body.clientHeight - h) / 2; 
    
    /* 
    //显示在右下方 
    */
    /*
    var l = document.body.scrollWidth - w - 1;
    var t = document.body.clientHeight - h - 1;
*/
    var container = document.createElement("div");

    var items = document.createElement("div");
    items.style.cssText = "z-index:50001; background:#fff; top:" + t + "px; left:" + l + "px; width:" + w + "px; height:" + h + "px; border:2px double #99CCFF;font-size:14px; font-family:宋体;position:absolute;";
    items.onmousedown = mousedown;

    var title = document.createElement("div");
    title.style.cssText = "width:" + w + "px; height:26px; cursor:move; line-height:26px; padding-left:5px; background:#fff; border-bottom:1px solid #99CCFF;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#99CCFF, EndColorStr=#EEF7FF);";

    var title_left = document.createElement("div");
    title_left.style.cssText = "float:left;font-weight:bold; color: #113DAE;";
    title_left.innerText = "小游戏窗口";

    var title_right = document.createElement("div");
    title_right.style.cssText = "float:right; font-family:Webdings; font-size:16px; color: white; text-align:center; width:40px; cursor: pointer;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#F0172D, EndColorStr=#ECF5FF);";
    title_right.onclick = _close;
    title_right.innerText = "r";

    var message = document.createElement("div");
    message.style.cssText = "padding:0px;margin:0; line-height:130%; color:black;";
    message.innerHTML = "  " + _msg;

    title.appendChild(title_left);
    title.appendChild(title_right);
    items.appendChild(title);
    items.appendChild(message);
    container.appendChild(items);

    var bgDiv = document.createElement("div");
    bgDiv.style.cssText = " Z-INDEX: 50000; FILTER: alpha(opacity=50); LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 100%; BACKGROUND-COLOR: #BCBCBC; moz-opacity: 0.5; opacity: 0.5";
    bgDiv.onmouseup = function() { return false; }
    bgDiv.onmousemove = function() { return false; }
    bgDiv.onmousedown = function() { return false; }
    bgDiv.onmousedown = function() { return false; }
    bgDiv.ondblclick = function() { return false; }
    bgDiv.onclick = function() { return false; }
    bgDiv.oncontextmenu = function() { return false; }
    bgDiv.onselectstart = function() { return false; }

    document.body.appendChild(container);
    document.body.appendChild(bgDiv);

    _setSelectDisplay("none");

    var x, y, dragObj;
    function mousedown() {
        var obj = event.srcElement.parentNode;
        dragObj = obj;
        dragObj.onmousemove = mousemove;
        dragObj.onmouseup = mouseup;
        dragObj.setCapture();

        oEvent = window.event ? window.event : event;
        x = oEvent.clientX;
        y = oEvent.clientY;
    };
    function mousemove() {
        oEvent = window.event ? window.event : event;
        var _top = oEvent.clientY - y + parseInt(dragObj.style.top);
        var _left = oEvent.clientX - x + parseInt(dragObj.style.left);
        if (_left < 1) _left = 1;
        if (_top < 1) _top = 1;
        var sw = document.body.scrollWidth - dragObj.offsetWidth - 1;
        var sh = document.body.clientHeight - dragObj.offsetHeight - 1;
        if (_left > sw) _left = sw;
        if (_top > sh) _top = sh;

        try {
            dragObj.style.top = _top + "px";
            dragObj.style.left = _left + "px";
        }
        catch (e) { }
        x = oEvent.clientX;
        y = oEvent.clientY
    };
    function mouseup() {
        dragObj.onmousemove = null;
        dragObj.onmouseup = null;
        dragObj.releaseCapture();
        dragObj = null;
    };
    function _close() {
        thisMovie("D8City").CloseGame();
    }
    function thisMovie(movieName) {
        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[movieName];
        } else {
            return document[movieName];
        }
    }
    this.HideGame = function _hide() {
        container.style.display = "none";
        bgDiv.style.display = "none";
        _setSelectDisplay("");
    };

    function _setSelectDisplay(dis) {
        var selects = document.getElementsByTagName("select");
        for (var i = 0; i < selects.length; i++) {
            selects[i].style.display = dis;
        }
    };
}
