﻿//以下为滚动代码
var Class = {
    create: function() {
        return function() {
            this.initialize.apply(this, arguments);
        }
    }
}

Object.extend = function(destination, source) {
    for (var property in source) {
        destination[property] = source[property];
    }
    return destination;
}

function addEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = fnHandler;
    }
};
var Scroller = Class.create();
Scroller.prototype = {
    initialize: function(lobbyZBTitleDivR, lobbyZBRollDiv1, options) {
        var oScroll = this, oScroller = $(lobbyZBTitleDivR), oScrollMid = $(lobbyZBRollDiv1);

        this.heightScroller = oScroller.offsetHeight;
        this.heightList = oScrollMid.offsetHeight;

        if (this.heightList <= this.heightScroller) return;

        oScroller.style.overflow = "hidden";
        oScrollMid.appendChild(oScrollMid.cloneNode(true));

        this.oScroller = oScroller;
        this.timer = null;

        this.SetOptions(options);

        this.side = 1; //1是上 -1是下
        switch (this.options.Side) {
            case "down":
                this.side = -1;
                break;
            case "up":
            default:
                this.side = 1;
        }

        addEventHandler(oScrollMid, "mouseover", function() { oScroll.Stop(); });
        addEventHandler(oScrollMid, "mouseout", function() { oScroll.Start(); });

        if (this.options.PauseStep <= 0 || this.options.PauseHeight <= 0) this.options.PauseStep = this.options.PauseHeight = 0;
        this.Pause = 0;

        this.Start();
    },
    //设置默认属性
    SetOptions: function(options) {
        this.options = {//默认值
            Step:1, //每次变化的px量
            Time:60, //速度(越大越慢)
            Side:"up", //滚动方向:"up"是上，"down"是下
            PauseHeight:20, //隔多高停一次
            PauseStep:1000//停顿时间(PauseHeight大于0该参数才有效)
        };
        Object.extend(this.options, options || {});
    },
    //滚动
    Scroll: function() {
        var iScroll = this.oScroller.scrollTop, iHeight = this.heightList, time = this.options.Time, oScroll = this, iStep = this.options.Step * this.side;

        if (this.side > 0) {
            if (iScroll >= (iHeight * 2 - this.heightScroller)) { iScroll -= iHeight; }
        } else {
            if (iScroll <= 0) { iScroll += iHeight; }
        }

        if (this.options.PauseHeight > 0) {
            if (this.Pause >= this.options.PauseHeight) {
                time = this.options.PauseStep;
                this.Pause = 0;
            } else {
                this.Pause += Math.abs(iStep);
                this.oScroller.scrollTop = iScroll + iStep;
            }
        } else { this.oScroller.scrollTop = iScroll + iStep; }

        this.timer = window.setTimeout(function() { oScroll.Scroll(); }, time);
    },
    //开始
    Start: function() {
        this.Scroll();
    },
    //停止
    Stop: function() {
        clearTimeout(this.timer);
    }
};

function delPK(id)
{
    caller("?flag=delpk",{id:id} );
}

    function browserinfo(){
        var Browser_Name=navigator.appName;
        var Browser_Version=parseFloat(navigator.appVersion);
        var Browser_Agent=navigator.userAgent;
        
        var Actual_Version,Actual_Name;
        
        var is_IE=(Browser_Name=="Microsoft Internet Explorer");
        var is_NN=(Browser_Name=="Netscape");
        
        if(is_NN){
            if(Browser_Version>=5.0){
                var Split_Sign=Browser_Agent.lastIndexOf("/");
                var Version=Browser_Agent.indexOf(" ",Split_Sign);
                var Bname=Browser_Agent.lastIndexOf(" ",Split_Sign);

                Actual_Version=Browser_Agent.substring(Split_Sign+1,Version);
                Actual_Name=Browser_Agent.substring(Bname+1,Split_Sign);
            }
            else{
                Actual_Version=Browser_Version;
                Actual_Name=Browser_Name;
            }
        }
        else if(is_IE){
            var Version_Start=Browser_Agent.indexOf("MSIE");
            var Version_End=Browser_Agent.indexOf(";",Version_Start);
            Actual_Version=Browser_Agent.substring(Version_Start+5,Version_End)
            Actual_Name=Browser_Name;
            
            if(Browser_Agent.indexOf("Maxthon")!=-1){
                Actual_Name+="(Maxthon)";
            }
            else if(Browser_Agent.indexOf("Opera")!=-1){
                Actual_Name="Opera";
                var tempstart=Browser_Agent.indexOf("Opera");
                var tempend=Browser_Agent.length;
                Actual_Version=Browser_Agent.substring(tempstart+6,tempend)
            }
        }
        else{
            Actual_Name="Unknown Navigator"
            Actual_Version="Unknown Version"
        }

        navigator.Actual_Name=Actual_Name;
        navigator.Actual_Version=Actual_Version;
        
        this.Name=Actual_Name;
        this.Version=Actual_Version;
    }
    
  function startGame(id)
  {
    caller("?flag=entergame",{id:id} );
  }
        
    function dowith(NavigatorName,Version,game)
    {
    
        switch(NavigatorName)
        {
            case "Firefox":
                try{
                    location.href=game;
                }
                catch(e)
                {
                    //alert("未注册的处理");
                }
                break;
            case "Microsoft Internet Explorer":
                document.getElementById("gameDiv").innerHTML="<iframe name=\"thisiframe\" id=\"thisiframe\"></iframe>";
                document.getElementById("thisiframe").src=game;
                
                break;
            default:
                try{
                    document.getElementById("gameDiv").innerHTML="<iframe id=\"thisiframe\" src=\""+game+"\"></iframe>";
                }
                catch(e){}
                break;
        }
    }
    
function changeOrderStyle(id,type,name)
{

    for(var i=0; i<10; i++)
    {
        if( $(name+i) && i!=id)
            $(name+i).className="lobbyItem";
    }
    
    if(type==0)
    {
        $(name+id).className="lobbyItemfocus";
    }
    else
    {
        $(name+id).className="lobbyItem";
    }

}

function changeBigMenu(type)
{
    switch(type)
    {
        case 0:
            $("lobbyMenu0Div").className="lobbyBigMenu0focusDiv";
            $("lobbyMenu1Div").className="lobbyBigMenu1unfocusDiv";
            $("lobbyMenu0A").className="lobbyBigMenu00";
            $("lobbyMenu1A").className="lobbyBigMenu11";
            break;
        case 1:
            $("lobbyMenu0Div").className="lobbyBigMenu0unfocusDiv";
            $("lobbyMenu1Div").className="lobbyBigMenu1focusDiv";
            $("lobbyMenu0A").className="lobbyBigMenu01";
            $("lobbyMenu1A").className="lobbyBigMenu10";
            break;
    }
}

function startGamecheck(gid,pkid)
{
    caller("?flag=checkpkgame",{gid:gid,pkid:pkid} );
}

function checkPKInfo(flag,gid,pkid)
{
    var temp="";
    switch(flag)
    {
        case -40:
            temp="同IP警告！为了维护游戏的公平性，每位居民每天只能接受相同IP 5 次挑战，超过次数不再有PK奖励！选择“确认”进行无奖惩PK，选择“取消”保留本战书";
            break;
        case -41:
            temp="同IP警告！您的挑战者今天已通过相同IP完成 5 次PK，所以今天您与对方的任何应战不再有金币奖惩！选择“确认”进行无奖惩PK，选择“取消”保留本战书";
            break;
        case -42:
            temp="您今日PK胜利次数已达上限！为了维护游戏的公平性，每位居民每天PK的胜利次数最高为25次，超过次数不再有PK奖励！选择“确认”进行无奖惩PK，选择“取消”保留本战书";
            break;
        case -43:
            temp="您的挑战者今日胜利次数已达上限！所以今天您与对方的任何应战不再有金币奖惩！选择“确认”进行无奖惩PK，选择“取消”保留本战书";
            break;
    }
    
    if(temp=="")
    {
        location.href="playgame?gid="+gid+"&pkid="+pkid;
    }
    else
    {
        if(confirm(temp))
            location.href="playgame?gid="+gid+"&pkid="+pkid;
    }
}

function showBigFlash(code)
{
    $("lobbyBigFlashDiv").style.display="block";
    $("lobbyBigFlashDiv1").style.display="block";
    
    var thisHeight=document.documentElement.clientHeight;
    var thisWidth=document.documentElement.clientWidth-33;
    $("lobbyBigFlashContentDiv").style.width=thisHeight+"px";
    $("lobbyBigFlashContentDiv").style.height=thisWidth+"px";
    $("lobbyBigFlashContentDiv").style.paddingLeft=parseInt((thisWidth-thisHeight-200)/2)+"px";
    
    $("lobbyBigShow").style.width=(thisHeight+225)+"px";
    $("lobbyBigShow").style.height=thisHeight+"px";
    
    var tempStr='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="flashId" id="flashId" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="900" height="700">';
    tempStr+='<param name="movie" value="'+flashURL+'" />';
    tempStr+='<param name="quality" value="high" />';
    tempStr+='<param name="allowScriptAccess" value="always" />';
    tempStr+='<param name="allowFullScreen" value="true">';
    tempStr+='<param name="wmode" value="window" />';
    tempStr+='<param name="FlashVars" value="code='+code+'" />';
    tempStr+='<embed  name="flashId" flashvars="code='+code+'" wmode="window" id="flashId" src="'+flashURL+'" allowFullScreen="true" allowScriptAccess="always" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="900" height="700"></embed>';
    tempStr+='</object>';
    $("lobbyBigShow").innerHTML=tempStr;
}

function closeBigFlash()
{
    isbig=false;

    $("lobbyBigShow").innerHTML="";

    $("lobbyBigFlashDiv").style.display="none";
    $("lobbyBigFlashDiv1").style.display="none";
    
}