﻿//-----------------------------------------------------------------------------------------
    function LeesMobileWindow(winname,marginx,marginy,nspeed,nstyle,tx,ty)
    {
        var z=this;
        var t=document.getElementById(winname);
        var t2=document.getElementById(winname+"iframe");
        this.windowName=winname?winname:"";
        this.window=t?t:null;
        this.iframe=t2?t2:null;       
        if(this.window==null)
            return null;       
        var vdsp=this.window.style.display;
        this.window.style.display="";
        this.width=this.window.clientWidth;
        this.height=this.window.clientHeight;        
        this.window.style.display=vdsp;
        
        this.marginX=marginx?marginx:0;
        this.marginY=marginy?marginy:0;
        this.speed=nspeed?nspeed:100;
        this.style=nstyle?nstyle:0;
        //0-左上；1-左下，2：右上；3-右下；4-中间垂直1/3；5-中间垂直1/2；6-中间垂直1/4;
        //101-左侧，顶部位置自定义；102-右侧，顶部位置自定义
        //201顶部，左侧位置自定义；202-底部，左侧位置自定义
        this.isClose=true;
        this.top=ty?ty:0;
        this.left=tx?tx:0;
        
        
        var h1=0;
        var h2=0; 
        try
        {
            h1 = document.body.clientHeight;
        }
        catch(ex){}
        try
        {
            h2 = document.documentElement.clientHeight;
        }
        catch(ex){}
        
        var isXhtml =(h2<=h1&&h2!=0)?true:false; //判断当前页面的Doctype是否为Xhtml
         
        this.body = isXhtml?document.documentElement:document.body;
        
        this.moveWindow=function()
        {
            if(this.isClose)
            {
                return;
            }
            else
            {
                //浏览器显示区域宽度
                var dw=this.body.clientWidth;
                //浏览器显示区域高度
                var dh=this.body.clientHeight;
                //页面显示区域顶部坐标
                var pt=this.body.scrollTop;
                //页面显示区域左边坐标
                var pl=this.body.scrollLeft;
                
                var t=0;
                var newTop=0;
                var newLeft=0;
                switch(this.style)
                {
                    case 0:
                        newLeft=pl+this.marginX;
                        newTop=pt+this.marginY;
                        break;
                    case 1:
                        newLeft=pl+this.marginX;
                        newTop=pt+dh-this.height-this.marginY;
                        break;
                    case 2:
                        newLeft=pl+dw-this.width-this.marginX;
                        newTop=pt+this.marginY;
                        break;
                    case 3:
                        newLeft=pl+dw-this.width-this.marginX;
                        newTop=pt+dh-this.height-this.marginY;
                        break;
                    case 4:
                        t=(dw-this.width)/2;
                        t=t>0?t:0;
                        newLeft=pl+t;
                        t=(dh-this.height)/3;
                        t=t>0?t:0;
                        newTop=pt+t;
                        break;
                    case 5:
                        t=(dw-this.width)/2;
                        t=t>0?t:0;
                        newLeft=pl+t;
                        t=(dh-this.height)/2;
                        t=t>0?t:0;
                        newTop=pt+t;
                        break;
                    case 6:
                        t=(dw-this.width)/2;
                        t=t>0?t:0;
                        newLeft=pl+t;
                        t=(dh-this.height)/4;
                        t=t>0?t:0;
                        newTop=pt+t;
                        break;
                    case 101:
                        newLeft=pl+this.marginX;
                        newTop=pt+this.marginY+this.top;
                        break;
                    case 102:
                        newLeft=pl+dw-this.width-this.marginX;
                        newTop=pt+this.marginY+this.top;
                        break;
                    case 201:
                        newLeft=pl+this.marginX+this.left;
                        newTop=pt+this.marginY;
                        break;
                    case 202:
                        newLeft=pl+this.marginX+this.left;
                        newTop=pt+dh-this.height-this.marginY;
                        break;
                     
                        
                }//end case
                this.window.style.top=newTop+"px";
                this.window.style.left=newLeft+"px";
                
                if(this.iframe)
                {
                    this.iframe.style.top=newTop+"px";
                    this.iframe.style.left=newLeft+"px";
                    this.iframe.style.width=this.width+2+"px";
                    this.iframe.style.height=this.height+2+"px";
                }
                
                var self=this;
                
                setTimeout(function(){self.moveWindow();},this.speed);
            }            
        }//end function
        this.closeWindow=function()
        {
            if(this.window)
            {
                this.window.style.display="none";
            }
            if(this.iframe)
            {
                this.iframe.style.display="none";
            }
            this.isClose=true;
        }
        this.showWindow=function()
        {
            if(this.window)
            {
                this.window.style.display="";
            }
            if(this.iframe)
            {
                this.iframe.style.display="";
            }
            this.isClose=false;
            this.moveWindow(); 
        }
        
        return this;
    }//end class
//-----------------------------------------------------------------------------------------
